@@ -20,7 +20,7 @@ import { v4 as uuidv4 } from 'uuid';
2020
2121import TimePickerSpinner from '../TimePickerSpinner/TimePickerSpinner' ;
2222import { settings } from '../../constants/Settings' ;
23- import dayjs , { DAYJS_INPUT_FORMATS } from '../../utils/dayjs' ;
23+ import dayjs , { DAYJS_INPUT_FORMATS , detectDateTimeFormat } from '../../utils/dayjs' ;
2424import { handleSpecificKeyDown , useOnClickOutside } from '../../utils/componentUtilityFunctions' ;
2525import { Tooltip } from '../Tooltip' ;
2626
@@ -200,6 +200,8 @@ const propTypes = {
200200 light : PropTypes . bool ,
201201 /** The language locale used to format the days of the week, months, and numbers. */
202202 locale : PropTypes . string ,
203+ /** IANA timezone string to interpret datetime values in (e.g., 'America/New_York') */
204+ timeZone : PropTypes . string ,
203205 /** Unique id of the component */
204206 id : PropTypes . string ,
205207 style : PropTypes . objectOf ( PropTypes . string ) ,
@@ -292,6 +294,7 @@ const defaultProps = {
292294 } ,
293295 light : false ,
294296 locale : 'en' ,
297+ timeZone : undefined ,
295298 id : undefined ,
296299 style : { } ,
297300} ;
@@ -315,6 +318,7 @@ const DateTimePicker = ({
315318 i18n,
316319 light,
317320 locale,
321+ timeZone,
318322 style,
319323 ...others
320324} ) => {
@@ -323,7 +327,8 @@ const DateTimePicker = ({
323327 ...defaultProps . i18n ,
324328 ...i18n ,
325329 } ;
326-
330+ const effectiveTimezone = timeZone || dayjs . tz . guess ( ) ;
331+ dayjs . tz . setDefault ( effectiveTimezone ) ;
327332 dayjs . locale ( locale ) ;
328333
329334 // State
@@ -428,7 +433,13 @@ const DateTimePicker = ({
428433 }
429434
430435 setCurrentValue ( value ) ;
431- const parsedValue = parseValue ( value , dateTimeMask , mergedI18n . toLabel ) ;
436+ const parsedValue = parseValue (
437+ value ,
438+ dateTimeMask ,
439+ mergedI18n . toLabel ,
440+ hasTimeInput ,
441+ effectiveTimezone
442+ ) ;
432443 setHumanValue ( parsedValue . readableValue ) ;
433444
434445 return {
@@ -498,15 +509,21 @@ const DateTimePicker = ({
498509 setIsCustomRange ( true ) ;
499510 setCustomRangeKind ( PICKER_KINDS . ABSOLUTE ) ;
500511 if ( ! absolute . hasOwnProperty ( 'start' ) ) {
501- absolute . start = dayjs ( `${ absolute . startDate } ${ absolute . startTime } ` ) . valueOf ( ) ;
512+ const startDateTime = `${ absolute . startDate } ${ absolute . startTime } ` ;
513+ absolute . start = dayjs
514+ . tz ( startDateTime , detectDateTimeFormat ( startDateTime ) , effectiveTimezone )
515+ . valueOf ( ) ;
502516 }
503517 if ( ! absolute . hasOwnProperty ( 'end' ) ) {
504- absolute . end = dayjs ( `${ absolute . endDate } ${ absolute . endTime } ` ) . valueOf ( ) ;
518+ const endDateTime = `${ absolute . endDate } ${ absolute . endTime } ` ;
519+ absolute . end = dayjs
520+ . tz ( endDateTime , detectDateTimeFormat ( endDateTime ) , effectiveTimezone )
521+ . valueOf ( ) ;
505522 }
506- absolute . startDate = dayjs ( absolute . start ) . format ( 'MM/DD/YYYY' ) ;
507- absolute . startTime = dayjs ( absolute . start ) . format ( 'HH:mm' ) ;
508- absolute . endDate = dayjs ( absolute . end ) . format ( 'MM/DD/YYYY' ) ;
509- absolute . endTime = dayjs ( absolute . end ) . format ( 'HH:mm' ) ;
523+ absolute . startDate = dayjs . tz ( absolute . start ) . format ( 'MM/DD/YYYY' ) ;
524+ absolute . startTime = dayjs . tz ( absolute . start ) . format ( 'HH:mm' ) ;
525+ absolute . endDate = dayjs . tz ( absolute . end ) . format ( 'MM/DD/YYYY' ) ;
526+ absolute . endTime = dayjs . tz ( absolute . end ) . format ( 'HH:mm' ) ;
510527 setAbsoluteValue ( absolute ) ;
511528 }
512529 } else {
@@ -610,7 +627,8 @@ const DateTimePicker = ({
610627 customRangeKind === PICKER_KINDS . ABSOLUTE &&
611628 ( absoluteStartTimeInvalid ||
612629 absoluteEndTimeInvalid ||
613- ( absoluteValue . startDate === '' && absoluteValue . endDate === '' ) ||
630+ ! absoluteValue . startDate ||
631+ ! absoluteValue . endDate ||
614632 ( hasTimeInput ? ! absoluteValue . startTime || ! absoluteValue . endTime : false ) ) ;
615633
616634 const disableApply = disableRelativeApply || disableAbsoluteApply ;
0 commit comments