(wallClock: string, timeZone: string)
| 158 | * calendar apps treat that once-a-year hour. |
| 159 | */ |
| 160 | export function zonedWallClockToUtc(wallClock: string, timeZone: string): Date { |
| 161 | const [datePart, timePart] = wallClock.split('T') |
| 162 | const [year, month, day] = datePart.split('-').map(Number) |
| 163 | const [hour, minute, second = 0] = timePart.split(':').map(Number) |
| 164 | const utcGuess = Date.UTC(year, month - 1, day, hour, minute, second) |
| 165 | const guessOffset = timezoneOffsetMs(new Date(utcGuess), timeZone) |
| 166 | const candidate = utcGuess - guessOffset |
| 167 | const candidateOffset = timezoneOffsetMs(new Date(candidate), timeZone) |
| 168 | if (candidateOffset === guessOffset) return new Date(candidate) |
| 169 | const adjusted = utcGuess - candidateOffset |
| 170 | return timezoneOffsetMs(new Date(adjusted), timeZone) === candidateOffset |
| 171 | ? new Date(adjusted) |
| 172 | : new Date(candidate) |
| 173 | } |
no test coverage detected