11import { useEffect , useState } from 'react' ;
22import { DateTimePicker } from '@mui/x-date-pickers/DateTimePicker' ;
33import dayjs , { Dayjs } from 'dayjs' ;
4-
4+ import DateFormatter from '../../helpers/formatters/Date' ;
55import handleEvent from '../../helpers/event-utils' ;
66import { format } from '../../helpers/formatters' ;
77import { dateFormatInfoDefault , getDateFormatInfo } from '../../helpers/date-format-utils' ;
@@ -19,7 +19,10 @@ export default function DateTime(props: DateTimeProps) {
1919
2020 const { getPConnect, label, required, disabled, value = '' , validatemessage, status, readOnly, testId, helperText, displayMode, hideLabel } = props ;
2121
22- const [ dateValue , setDateValue ] = useState < Dayjs | null > ( value ? dayjs ( value ) : null ) ;
22+ const environmentInfo = PCore . getEnvironmentInfo ( ) ;
23+ const timezone = environmentInfo && environmentInfo . getTimeZone ( ) ;
24+
25+ const [ dateValue , setDateValue ] = useState < Dayjs | null > ( value ? dayjs ( DateFormatter . convertToTimezone ( value , { timezone } ) ) : null ) ;
2326
2427 const pConn = getPConnect ( ) ;
2528 const actions = pConn . getActionsApi ( ) ;
@@ -35,7 +38,7 @@ export default function DateTime(props: DateTimeProps) {
3538 dateFormatInfo . dateFormatMask = theDateFormat . dateFormatMask ;
3639
3740 useEffect ( ( ) => {
38- setDateValue ( dayjs ( value ) ) ;
41+ setDateValue ( dayjs ( DateFormatter . convertToTimezone ( value , { timezone } ) ) ) ;
3942 } , [ value ] ) ;
4043
4144 if ( displayMode === 'DISPLAY_ONLY' ) {
@@ -64,8 +67,9 @@ export default function DateTime(props: DateTimeProps) {
6467 } ;
6568
6669 const handleChange = date => {
67- setDateValue ( date ) ;
68- const changeValue = date && date . isValid ( ) ? date . toISOString ( ) : null ;
70+ const timeZoneDateTime = dayjs . tz ( date . format ( 'YYYY-MM-DDTHH:mm:ss' ) , timezone ) ;
71+ const changeValue = timeZoneDateTime && timeZoneDateTime . isValid ( ) ? timeZoneDateTime . toISOString ( ) : '' ;
72+ setDateValue ( timeZoneDateTime ) ;
6973 handleEvent ( actions , 'changeNblur' , propName , changeValue ) ;
7074 } ;
7175
0 commit comments