MCPcopy
hub / github.com/date-fns/date-fns / toTpInstant

Function toTpInstant

pkgs/core/src/_lib/tp/index.ts:5–23  ·  view source on GitHub ↗
(
  date: DateArg<DateType>,
  options?: ContextOptions<ResultDate> | undefined,
)

Source from the content-addressed store, hash-verified

3import type { ContextOptions, DateArg } from "../../types.ts";
4
5export 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
25function getDateTimeZone<DateType extends Date>(
26 date: DateArg<DateType>,

Callers 3

tpyAddDaysFunction · 0.90
tpyAddBusinessDaysFunction · 0.90
tpyAddFunction · 0.90

Calls 3

toDateFunction · 0.90
getDateTimeZoneFunction · 0.85
invalidDateFunction · 0.70

Tested by

no test coverage detected