@@ -4,11 +4,11 @@ import { addMinutes } from 'date-fns';
44
55import { warnOnce } from '@cloudscape-design/component-toolkit/internal' ;
66
7- import { formatTimeOffsetISO , parseTimezoneOffset , shiftTimezoneOffset } from '../internal/utils/date-time' ;
7+ import { formatTimeOffsetISOInternal , parseTimezoneOffset , shiftTimezoneOffset } from '../internal/utils/date-time' ;
88import { DateRangePickerProps } from './interfaces' ;
99
1010/**
11- * Appends a time zone offset to an offset-less date string.
11+ * Appends a time zone offset to a date string, replacing any existing timezone information .
1212 */
1313export function setTimeOffset (
1414 value : DateRangePickerProps . Value | null ,
@@ -17,10 +17,16 @@ export function setTimeOffset(
1717 if ( ! ( value ?. type === 'absolute' ) ) {
1818 return value ;
1919 }
20+
21+ const stripTimezone = ( dateString : string ) : string => {
22+ // Remove existing timezone info: Z, +HH:MM, -HH:MM, +HHMM, -HHMM
23+ return dateString . replace ( / [ Z ] $ | [ + - ] \d { 2 } : ? \d { 2 } $ / , '' ) ;
24+ } ;
25+
2026 return {
2127 type : 'absolute' ,
22- startDate : value . startDate + formatTimeOffsetISO ( value . startDate , timeOffset . startDate ) ,
23- endDate : value . endDate + formatTimeOffsetISO ( value . endDate , timeOffset . endDate ) ,
28+ startDate : stripTimezone ( value . startDate ) + formatTimeOffsetISOInternal ( value . startDate , timeOffset . startDate ) ,
29+ endDate : stripTimezone ( value . endDate ) + formatTimeOffsetISOInternal ( value . endDate , timeOffset . endDate ) ,
2430 } ;
2531}
2632
0 commit comments