(
date: DateArg<DateType> | ContextFn<ResultDate> | undefined,
value: DateArg<Date> & {},
)
| 42 | * } |
| 43 | */ |
| 44 | export 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 | } |
no outgoing calls
no test coverage detected