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

Function startOfWeek

pkgs/core/src/startOfWeek/index.ts:43–65  ·  view source on GitHub ↗
(
  date: DateArg<DateType>,
  options?: StartOfWeekOptions<ResultDate>,
)

Source from the content-addressed store, hash-verified

41 * //=> Mon Sep 01 2014 00:00:00
42 */
43export function startOfWeek<
44 DateType extends Date,
45 ResultDate extends Date = DateType,
46>(
47 date: DateArg<DateType>,
48 options?: StartOfWeekOptions<ResultDate>,
49): ResultDate {
50 const defaultOptions = getDefaultOptions();
51 const weekStartsOn =
52 options?.weekStartsOn ??
53 options?.locale?.options?.weekStartsOn ??
54 defaultOptions.weekStartsOn ??
55 defaultOptions.locale?.options?.weekStartsOn ??
56 0;
57
58 const _date = toDate(date, options?.in);
59 const day = _date.getDay();
60 const diff = (day < weekStartsOn ? 7 : 0) + day - weekStartsOn;
61
62 _date.setDate(_date.getDate() - diff);
63 _date.setHours(0, 0, 0, 0);
64 return _date;
65}

Callers 12

startOfWeekYearFunction · 0.90
getWeekFunction · 0.90
getWeekYearFunction · 0.90
setMethod · 0.90
setMethod · 0.90
eachWeekOfIntervalFunction · 0.90
startOfISOWeekFunction · 0.90
test.tsFile · 0.90
test.tsFile · 0.90
isSameWeekFunction · 0.90
test.tsFile · 0.90

Calls 2

getDefaultOptionsFunction · 0.90
toDateFunction · 0.90

Tested by

no test coverage detected