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

Function constructFrom

pkgs/core/src/constructFrom/index.ts:44–60  ·  view source on GitHub ↗
(
  date: DateArg<DateType> | ContextFn<ResultDate> | undefined,
  value: DateArg<Date> & {},
)

Source from the content-addressed store, hash-verified

42 * }
43 */
44export function constructFrom<
45 DateType extends Date | ConstructableDate,
46 ResultDate extends Date = DateType,
47>(
48 date: DateArg<DateType> | ContextFn<ResultDate> | undefined,
49 value: DateArg<Date> & {},
50): ResultDate {
51 if (typeof date === "function") return date(value);
52
53 if (date && typeof date === "object" && constructFromSymbol in date)
54 return date[constructFromSymbol](value);
55
56 if (date instanceof Date)
57 return new (date.constructor as GenericDateConstructor<ResultDate>)(value);
58
59 return new Date(value) as ResultDate;
60}

Callers 15

addDaysFunction · 0.90
toDateFunction · 0.90
startOfWeekYearFunction · 0.90
startOfISOWeekYearFunction · 0.90
fromTpFunction · 0.90
invalidDateFunction · 0.90
startOfTomorrowFunction · 0.90
eachDayOfIntervalFunction · 0.90
endOfISOWeekYearFunction · 0.90
addMillisecondsFunction · 0.90
minFunction · 0.90
setWeekYearFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected