( date: DateArg<DateType>, options?: ContextOptions<ResultDate> | undefined, )
| 3 | import type { ContextOptions, DateArg } from "../../types.ts"; |
| 4 | |
| 5 | export function toTpInstant< |
| 6 | DateType extends Date, |
| 7 | ResultDate extends Date = DateType, |
| 8 | >( |
| 9 | date: DateArg<DateType>, |
| 10 | options?: ContextOptions<ResultDate> | undefined, |
| 11 | ): [temporal: Temporal.ZonedDateTime | null, invalidDate: ResultDate] { |
| 12 | const inputDate = toDate(date, options?.in); |
| 13 | let temporal: Temporal.ZonedDateTime | null; |
| 14 | try { |
| 15 | temporal = Temporal.Instant.fromEpochMilliseconds( |
| 16 | inputDate.getTime(), |
| 17 | ).toZonedDateTimeISO(getDateTimeZone(inputDate)); |
| 18 | } catch (err) { |
| 19 | if (err instanceof RangeError) temporal = null; |
| 20 | else throw err; |
| 21 | } |
| 22 | return [temporal, invalidDate(date, options)]; |
| 23 | } |
| 24 | |
| 25 | function getDateTimeZone<DateType extends Date>( |
| 26 | date: DateArg<DateType>, |
no test coverage detected