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

Function startOfDecade

pkgs/core/src/startOfDecade/index.ts:32–48  ·  view source on GitHub ↗
(
  date: DateArg<DateType>,
  options?: StartOfDecadeOptions<ResultDate> | undefined,
)

Source from the content-addressed store, hash-verified

30 * //=> Jan 01 2010 00:00:00
31 */
32export function startOfDecade<
33 DateType extends Date,
34 ResultDate extends Date = DateType,
35>(
36 date: DateArg<DateType>,
37 options?: StartOfDecadeOptions<ResultDate> | undefined,
38): ResultDate {
39 // TODO: Switch to more technical definition in of decades that start with 1
40 // end with 0. I.e. 2001-2010 instead of current 2000-2009. It's a breaking
41 // change, so it can only be done in 4.0.
42 const _date = toDate(date, options?.in);
43 const year = _date.getFullYear();
44 const decade = Math.floor(year / 10) * 10;
45 _date.setFullYear(decade, 0, 1);
46 _date.setHours(0, 0, 0, 0);
47 return _date;
48}

Callers 1

test.tsFile · 0.90

Calls 1

toDateFunction · 0.90

Tested by

no test coverage detected