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

Function timezoneOffsetMs

apps/sim/lib/core/utils/timezone.ts:125–146  ·  view source on GitHub ↗

The UTC offset (ms, east-positive) of `timeZone` at a given instant.

(instant: Date, timeZone: string)

Source from the content-addressed store, hash-verified

123
124/** The UTC offset (ms, east-positive) of `timeZone` at a given instant. */
125function timezoneOffsetMs(instant: Date, timeZone: string): number {
126 const parts = new Intl.DateTimeFormat('en-US', {
127 timeZone,
128 hourCycle: 'h23',
129 year: 'numeric',
130 month: '2-digit',
131 day: '2-digit',
132 hour: '2-digit',
133 minute: '2-digit',
134 second: '2-digit',
135 }).formatToParts(instant)
136 const get = (type: string) => Number(parts.find((p) => p.type === type)?.value)
137 const asUtc = Date.UTC(
138 get('year'),
139 get('month') - 1,
140 get('day'),
141 get('hour'),
142 get('minute'),
143 get('second')
144 )
145 return asUtc - instant.getTime()
146}
147
148/**
149 * Resolves a naive `yyyy-MM-ddTHH:mm[:ss]` wall-clock — interpreted as local

Callers 2

getTimezoneOptionsFunction · 0.85
zonedWallClockToUtcFunction · 0.85

Calls 1

getFunction · 0.70

Tested by

no test coverage detected