MCPcopy
hub / github.com/simstudioai/sim / zonedWallClockToUtc

Function zonedWallClockToUtc

apps/sim/lib/core/utils/timezone.ts:160–173  ·  view source on GitHub ↗
(wallClock: string, timeZone: string)

Source from the content-addressed store, hash-verified

158 * calendar apps treat that once-a-year hour.
159 */
160export 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}

Callers 3

timezone.test.tsFile · 0.90
isLaunchInPastFunction · 0.90

Calls 1

timezoneOffsetMsFunction · 0.85

Tested by

no test coverage detected