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

Function max

pkgs/core/src/max/index.ts:37–54  ·  view source on GitHub ↗
(
  dates: DateArg<DateType>[],
  options?: MaxOptions<ResultDate> | undefined,
)

Source from the content-addressed store, hash-verified

35 * //=> Sun Jul 02 1995 00:00:00
36 */
37export function max<DateType extends Date, ResultDate extends Date = DateType>(
38 dates: DateArg<DateType>[],
39 options?: MaxOptions<ResultDate> | undefined,
40): ResultDate {
41 let result: ResultDate | undefined;
42 let context = options?.in;
43
44 dates.forEach((date) => {
45 // Use the first date object as the context function
46 if (!context && typeof date === "object")
47 context = constructFrom.bind(null, date) as ContextFn<ResultDate>;
48
49 const date_ = toDate(date, context);
50 if (!result || result < date_ || isNaN(+date_)) result = date_;
51 });
52
53 return constructFrom(context, result || NaN);
54}

Callers 2

clampFunction · 0.90
test.tsFile · 0.90

Calls 2

toDateFunction · 0.90
constructFromFunction · 0.90

Tested by

no test coverage detected