UNPKG

891 BPlain TextView Raw
1import type { Locale } from "../lib/dateLib.js";
2import { dateLib as defaultDateLib } from "../lib/index.js";
3import type { DateLib } from "../types/index.js";
4
5/**
6 * Generate a series of 7 days, starting from the week, to use for formatting
7 * the weekday names (Monday, Tuesday, etc.).
8 */
9export function getWeekdays(
10 locale?: Locale | undefined,
11 /** The index of the first day of the week (0 - Sunday). */
12 weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | undefined,
13 /** Use ISOWeek instead of locale/ */
14 ISOWeek?: boolean | undefined,
15 /** @ignore */
16 dateLib: DateLib = defaultDateLib
17): Date[] {
18 const start = ISOWeek
19 ? dateLib.startOfISOWeek(new dateLib.Date())
20 : dateLib.startOfWeek(new dateLib.Date(), { locale, weekStartsOn });
21
22 const days = [];
23 for (let i = 0; i < 7; i++) {
24 const day = dateLib.addDays(start, i);
25 days.push(day);
26 }
27 return days;
28}