(date: Date, timezone?: string)
| 194 | } |
| 195 | |
| 196 | function getTimezoneGMT(date: Date, timezone?: string) { |
| 197 | const fmt = getOffsetFormatter(timezone); |
| 198 | const parts = fmt.formatToParts(date); |
| 199 | const tzPart = parts.find(p => p.type === 'timeZoneName'); |
| 200 | if (!tzPart) return 'Z'; |
| 201 | |
| 202 | const tzValue = tzPart.value; // e.g. "GMT-5", "GMT+5:30", "GMT" |
| 203 | if (tzValue === 'GMT') return 'Z'; |
| 204 | |
| 205 | // Parse the offset from the Intl-provided string |
| 206 | const match = tzValue.match(/^GMT([+-])(\d{1,2})(?::(\d{2}))?$/); |
| 207 | if (!match) return 'Z'; |
| 208 | |
| 209 | const sign = match[1]; |
| 210 | const hoursNum = parseInt(match[2]); |
| 211 | const minutesNum = parseInt(match[3] || '0'); |
| 212 | if (hoursNum === 0 && minutesNum === 0) return 'Z'; |
| 213 | |
| 214 | const hours = match[2].padStart(2, '0'); |
| 215 | const minutes = (match[3] || '00').padStart(2, '0'); |
| 216 | |
| 217 | return `GMT${sign}${hours}:${minutes}`; |
| 218 | } |
no test coverage detected