@@ -246,6 +246,7 @@ const DateTimePicker = (
246246 useEffect ( ( ) => {
247247 if ( prevTimezone !== timeZone ) {
248248 const newDate = dayjs ( ) . tz ( timeZone ) ;
249+ console . log ( 'current' , newDate . toDate ( ) ) ;
249250 dispatch ( {
250251 type : CalendarActionKind . CHANGE_CURRENT_DATE ,
251252 payload : newDate ,
@@ -277,7 +278,7 @@ const DateTimePicker = (
277278
278279 if ( prevTimezone !== timeZone ) {
279280 ( onChange as SingleChange ) ( {
280- date : _date ,
281+ date : _date ? dayjs ( _date ) . toDate ( ) : _date ,
281282 } ) ;
282283 }
283284 } else if ( mode === 'range' ) {
@@ -313,8 +314,8 @@ const DateTimePicker = (
313314
314315 if ( prevTimezone !== timeZone ) {
315316 ( onChange as RangeChange ) ( {
316- startDate : start ,
317- endDate : end ,
317+ startDate : start ? dayjs ( start ) . toDate ( ) : start ,
318+ endDate : end ? dayjs ( end ) . toDate ( ) : end ,
318319 } ) ;
319320 }
320321 } else if ( mode === 'multiple' ) {
@@ -329,7 +330,7 @@ const DateTimePicker = (
329330
330331 if ( prevTimezone !== timeZone ) {
331332 ( onChange as MultiChange ) ( {
332- dates : _dates ,
333+ dates : _dates . map ( ( item ) => dayjs ( item ) . toDate ( ) ) ,
333334 change : 'updated' ,
334335 } ) ;
335336 }
@@ -355,22 +356,22 @@ const DateTimePicker = (
355356 if ( onChange ) {
356357 if ( mode === 'single' ) {
357358 const newDate = timePicker
358- ? selectedDate
359- : getStartOfDay ( selectedDate ) ;
359+ ? dayjs . tz ( selectedDate , timeZone )
360+ : dayjs . tz ( getStartOfDay ( selectedDate ) , timeZone ) ;
360361
361362 dispatch ( {
362363 type : CalendarActionKind . CHANGE_CURRENT_DATE ,
363364 payload : newDate ,
364365 } ) ;
365366
366367 ( onChange as SingleChange ) ( {
367- date : newDate ,
368+ date : newDate ? dayjs ( newDate ) . toDate ( ) : newDate ,
368369 } ) ;
369370 } else if ( mode === 'range' ) {
370371 // set time to 00:00:00
371- let start = removeTime ( stateRef . current . startDate ) ;
372- let end = removeTime ( stateRef . current . endDate ) ;
373- const selected = removeTime ( selectedDate ) ;
372+ let start = removeTime ( stateRef . current . startDate , timeZone ) ;
373+ let end = removeTime ( stateRef . current . endDate , timeZone ) ;
374+ const selected = removeTime ( selectedDate , timeZone ) ;
374375 let isStart : boolean = true ;
375376 let isReset : boolean = false ;
376377
@@ -434,17 +435,21 @@ const DateTimePicker = (
434435 } ) ;
435436 } else {
436437 ( onChange as RangeChange ) ( {
437- startDate : isStart ? getStartOfDay ( selectedDate ) : start ,
438+ startDate : isStart
439+ ? dayjs ( selected ) . toDate ( )
440+ : start
441+ ? dayjs . tz ( start ) . toDate ( )
442+ : start ,
438443 endDate : ! isStart
439- ? getEndOfDay ( selectedDate )
444+ ? dayjs . tz ( getEndOfDay ( selected ) , timeZone ) . toDate ( )
440445 : end
441- ? getEndOfDay ( end )
446+ ? dayjs . tz ( getEndOfDay ( end ) , timeZone ) . toDate ( )
442447 : end ,
443448 } ) ;
444449 }
445450 } else if ( mode === 'multiple' ) {
446451 const safeDates = ( stateRef . current . dates as DateType [ ] ) || [ ] ;
447- const newDate = getStartOfDay ( selectedDate ) ;
452+ const newDate = dayjs ( selectedDate , timeZone ) . startOf ( 'day' ) ;
448453
449454 const exists = safeDates . some ( ( ed ) => areDatesOnSameDay ( ed , newDate ) ) ;
450455
@@ -463,14 +468,14 @@ const DateTimePicker = (
463468 ) as DateType [ ] ;
464469
465470 ( onChange as MultiChange ) ( {
466- dates : _dates ,
467- datePressed : newDate ,
471+ dates : _dates . map ( ( item ) => dayjs ( item ) . toDate ( ) ) ,
472+ datePressed : newDate ? dayjs ( newDate ) . toDate ( ) : newDate ,
468473 change : exists ? 'removed' : 'added' ,
469474 } ) ;
470475 }
471476 }
472477 } ,
473- [ mode , timePicker , min , max , stateRef ]
478+ [ mode , timePicker , min , max , timeZone ]
474479 ) ;
475480
476481 // set the active displayed month
0 commit comments