(date: Date, timeZone: string)
| 7 | } |
| 8 | |
| 9 | export 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 | |
| 35 | export function addDaysToYmd( |
| 36 | year: number, |
no test coverage detected