@@ -104,15 +104,31 @@ export const parseDate = (time) => {
104104 } else {
105105 date = new Date ( )
106106 }
107-
108- return {
109- year : date . getFullYear ( ) ,
110- month : date . getMonth ( ) + 1 ,
111- day : date . getDate ( ) ,
112- hours : date . getHours ( ) ,
113- minutes : date . getMinutes ( ) ,
114- seconds : date . getSeconds ( )
107+ // 识别无时分秒的日期时间
108+ const timeParts = hasNoTime ( time )
109+ let timesPartsOne = { }
110+ let timesPartsTwo = { }
111+ if ( ! timeParts . hours ) {
112+ timesPartsOne = {
113+ year : timeParts . year ,
114+ month : timeParts . month ,
115+ day : timeParts . day ,
116+ hours : 0 ,
117+ minutes : 0 ,
118+ seconds : 0
119+ }
120+ } else {
121+ timesPartsTwo = {
122+ year : date . getFullYear ( ) ,
123+ month : date . getMonth ( ) + 1 ,
124+ day : date . getDate ( ) ,
125+ hours : date . getHours ( ) ,
126+ minutes : date . getMinutes ( ) ,
127+ seconds : date . getSeconds ( )
128+ }
115129 }
130+ const timePartsList = Object . assign ( timesPartsOne , timesPartsTwo )
131+ return timePartsList
116132}
117133
118134export const computedCalendar =
@@ -160,6 +176,36 @@ const getCalendarItem = function (item, props, isFunction, type, isNext, isLast)
160176 return res
161177}
162178
179+ const hasNoTime = ( date ) => {
180+ const datetimeStr = date
181+ let hoursTime = 0
182+ let minutesTime = 0
183+ let secondsTime = 0
184+ const [ datePart , timePart ] = datetimeStr . split ( ' ' )
185+ const [ year , month , day ] = datePart && datePart . split ( '-' )
186+ if ( timePart ) {
187+ const [ hours , minutes , seconds ] = timePart && timePart . split ( ':' )
188+ hoursTime = hours
189+ minutesTime = minutes
190+ secondsTime = seconds
191+ }
192+ // 提取时间
193+ return {
194+ year : Number ( year ) ,
195+ month : Number ( month ) ,
196+ day : Number ( day ) ,
197+ hours : hoursTime ,
198+ minutes : minutesTime ,
199+ seconds : secondsTime
200+ }
201+ }
202+ // 时间转GMT8
203+ const timesToGMT8 = ( date ) => {
204+ const originalDate = new Date ( date )
205+ const gmt8 = new Date ( originalDate . getTime ( ) + 15 * 60 * 60 * 1000 )
206+ return gmt8
207+ }
208+
163209export const handleEvents =
164210 ( { props, state } ) =>
165211 ( ) => {
@@ -197,14 +243,23 @@ export const handleEvents =
197243 ( [ lastYear , + state . activeYear , nextYear ] . includes ( endYear ) &&
198244 [ lastMon , + state . activeMonth , nextMon ] . includes ( endMonth ) )
199245 ) {
200- item . start = getTime ( item . start )
201- item . end = getTime ( item . end )
202- item . startTime = makeUpZero ( startHours ) + ':' + makeUpZero ( startMinutes ) + ':' + makeUpZero ( startSeconds )
203- item . endTime = makeUpZero ( endHours ) + ':' + makeUpZero ( endMinutes ) + ':' + makeUpZero ( endSeconds )
246+ const timeStartPart = hasNoTime ( item . start )
247+ const timeEndPart = hasNoTime ( item . end )
248+
249+ item . start = timeStartPart . hours ? getTime ( item . start ) : timesToGMT8 ( item . start )
250+ item . end = timeEndPart . hours ? getTime ( item . end ) : timesToGMT8 ( item . end )
251+
252+ item . startTime = timeStartPart . hours
253+ ? makeUpZero ( startHours ) + ':' + makeUpZero ( startMinutes ) + ':' + makeUpZero ( startSeconds )
254+ : ''
255+ item . endTime = timeEndPart . hours
256+ ? makeUpZero ( endHours ) + ':' + makeUpZero ( endMinutes ) + ':' + makeUpZero ( endSeconds )
257+ : ''
258+
204259 item . startDay = startYear + '-' + startMonth + '-' + startDay
205260 item . endDay = endYear + '-' + endMonth + '-' + endDay
206- const startTimestamp = getTime ( startYear + '-' + startMonth + '-' + startDay )
207- const endTimestamp = getTime ( endYear + '-' + endMonth + '-' + endDay )
261+ const startTimestamp = getTime ( item . startDay )
262+ const endTimestamp = getTime ( item . endDay )
208263 const days = Math . abs ( endTimestamp - startTimestamp ) / dayMillisecond
209264 item . dayNumber = days >= 1 ? days + 1 : 1
210265
0 commit comments