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

Function getZonedParts

common/src/util/zoned-time.ts:9–33  ·  view source on GitHub ↗
(date: Date, timeZone: string)

Source from the content-addressed store, hash-verified

7}
8
9export function getZonedParts(date: Date, timeZone: string): ZonedDateParts {
10 const parts = new Intl.DateTimeFormat('en-US', {
11 timeZone,
12 year: 'numeric',
13 month: '2-digit',
14 day: '2-digit',
15 hour: '2-digit',
16 minute: '2-digit',
17 hourCycle: 'h23',
18 }).formatToParts(date)
19
20 const get = (type: string) => {
21 const value = parts.find((part) => part.type === type)?.value
22 if (!value) throw new Error(`Missing ${type} in ${timeZone} date parts`)
23 return Number(value)
24 }
25
26 return {
27 year: get('year'),
28 month: get('month'),
29 day: get('day'),
30 hour: get('hour'),
31 minute: get('minute'),
32 }
33}
34
35export function addDaysToYmd(
36 year: number,

Callers 5

getUtcForZonedTimeFunction · 0.85
getZonedDayBoundsFunction · 0.85

Calls 1

getFunction · 0.70

Tested by

no test coverage detected