@@ -98,7 +98,52 @@ export function formatDateTime(
98
98
}
99
99
100
100
export function formatDateTimeISO ( date : Date , timeZone : string ) : string {
101
- return new Date ( date . toLocaleString ( "en-US" , { timeZone } ) ) . toISOString ( ) ;
101
+ // Special handling for UTC
102
+ if ( timeZone === "UTC" ) {
103
+ return date . toISOString ( ) ;
104
+ }
105
+
106
+ // Get the offset in minutes for the specified timezone
107
+ const formatter = new Intl . DateTimeFormat ( "en-US" , {
108
+ timeZone,
109
+ timeZoneName : "shortOffset" ,
110
+ } ) ;
111
+ const tzOffset =
112
+ formatter
113
+ . formatToParts ( date )
114
+ . find ( ( p ) => p . type === "timeZoneName" )
115
+ ?. value . replace ( "GMT" , "" ) ?? "" ;
116
+
117
+ // Format the offset properly as ±HH:mm
118
+ const offsetNum = parseInt ( tzOffset ) ;
119
+ const offsetHours = Math . abs ( Math . floor ( offsetNum ) ) . toString ( ) . padStart ( 2 , "0" ) ;
120
+ const sign = offsetNum >= 0 ? "+" : "-" ;
121
+ const formattedOffset = `${ sign } ${ offsetHours } :00` ;
122
+
123
+ // Format the date parts
124
+ const dateFormatter = new Intl . DateTimeFormat ( "en-US" , {
125
+ timeZone,
126
+ year : "numeric" ,
127
+ month : "2-digit" ,
128
+ day : "2-digit" ,
129
+ hour : "2-digit" ,
130
+ minute : "2-digit" ,
131
+ second : "2-digit" ,
132
+ hour12 : false ,
133
+ } ) ;
134
+
135
+ const parts = dateFormatter . formatToParts ( date ) ;
136
+ const dateParts : Record < string , string > = { } ;
137
+ parts . forEach ( ( part ) => {
138
+ dateParts [ part . type ] = part . value ;
139
+ } ) ;
140
+
141
+ // Format: YYYY-MM-DDThh:mm:ss.sss±hh:mm
142
+ const isoString =
143
+ `${ dateParts . year } -${ dateParts . month } -${ dateParts . day } T` +
144
+ `${ dateParts . hour } :${ dateParts . minute } :${ dateParts . second } .000${ formattedOffset } ` ;
145
+
146
+ return isoString ;
102
147
}
103
148
104
149
// New component that only shows date when it changes
0 commit comments