MCPcopy
hub / github.com/CodebuffAI/codebuff / getUtcForZonedTime

Function getUtcForZonedTime

common/src/util/zoned-time.ts:50–80  ·  view source on GitHub ↗
(
  parts: Pick<ZonedDateParts, 'year' | 'month' | 'day'>,
  timeZone: string,
  hour: number,
  minute: number,
)

Source from the content-addressed store, hash-verified

48}
49
50export function getUtcForZonedTime(
51 parts: Pick<ZonedDateParts, 'year' | 'month' | 'day'>,
52 timeZone: string,
53 hour: number,
54 minute: number,
55): Date {
56 let guess = new Date(
57 Date.UTC(parts.year, parts.month - 1, parts.day, hour, minute),
58 )
59
60 for (let i = 0; i < 3; i++) {
61 const actual = getZonedParts(guess, timeZone)
62 const desiredUtc = Date.UTC(
63 parts.year,
64 parts.month - 1,
65 parts.day,
66 hour,
67 minute,
68 )
69 const actualUtc = Date.UTC(
70 actual.year,
71 actual.month - 1,
72 actual.day,
73 actual.hour,
74 actual.minute,
75 )
76 guess = new Date(guess.getTime() + (desiredUtc - actualUtc))
77 }
78
79 return guess
80}
81
82export function getZonedDayBounds(
83 now: Date,

Callers 3

getZonedDayBoundsFunction · 0.85

Calls 1

getZonedPartsFunction · 0.85

Tested by

no test coverage detected