@zag-js/date-utils 2.0.0-next.3 → 2.0.0-next.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. package/dist/align.d.mts +4 -8
  2. package/dist/align.d.ts +4 -8
  3. package/dist/align.js +15 -47
  4. package/dist/align.mjs +10 -21
  5. package/dist/assertion.d.mts +6 -10
  6. package/dist/assertion.d.ts +6 -10
  7. package/dist/assertion.js +21 -48
  8. package/dist/assertion.mjs +13 -19
  9. package/dist/constrain.d.mts +7 -10
  10. package/dist/constrain.d.ts +7 -10
  11. package/dist/constrain.js +72 -133
  12. package/dist/constrain.mjs +63 -110
  13. package/dist/date-month.d.mts +17 -21
  14. package/dist/date-month.d.ts +17 -21
  15. package/dist/date-month.js +103 -112
  16. package/dist/date-month.mjs +92 -86
  17. package/dist/date-year.d.mts +8 -11
  18. package/dist/date-year.d.ts +8 -11
  19. package/dist/date-year.js +35 -62
  20. package/dist/date-year.mjs +28 -34
  21. package/dist/duration.d.mts +8 -12
  22. package/dist/duration.d.ts +8 -12
  23. package/dist/duration.js +13 -37
  24. package/dist/duration.mjs +8 -11
  25. package/dist/format.d.mts +5 -8
  26. package/dist/format.d.ts +5 -8
  27. package/dist/format.js +35 -76
  28. package/dist/format.mjs +29 -49
  29. package/dist/formatter.d.mts +3 -6
  30. package/dist/formatter.d.ts +3 -6
  31. package/dist/formatter.js +26 -50
  32. package/dist/formatter.mjs +21 -24
  33. package/dist/get-era-format.d.mts +2 -6
  34. package/dist/get-era-format.d.ts +2 -6
  35. package/dist/get-era-format.js +9 -34
  36. package/dist/get-era-format.mjs +5 -9
  37. package/dist/index.d.mts +15 -15
  38. package/dist/index.d.ts +15 -15
  39. package/dist/index.js +66 -47
  40. package/dist/index.mjs +14 -14
  41. package/dist/locale.d.mts +3 -5
  42. package/dist/locale.d.ts +3 -5
  43. package/dist/locale.js +28 -55
  44. package/dist/locale.mjs +22 -28
  45. package/dist/mutation.d.mts +6 -10
  46. package/dist/mutation.d.ts +6 -10
  47. package/dist/mutation.js +21 -53
  48. package/dist/mutation.mjs +14 -30
  49. package/dist/pagination.d.mts +16 -19
  50. package/dist/pagination.d.ts +16 -19
  51. package/dist/pagination.js +120 -201
  52. package/dist/pagination.mjs +106 -166
  53. package/dist/parse-date.d.mts +2 -6
  54. package/dist/parse-date.d.ts +2 -6
  55. package/dist/parse-date.js +41 -72
  56. package/dist/parse-date.mjs +37 -47
  57. package/dist/preset.d.mts +3 -6
  58. package/dist/preset.d.ts +3 -6
  59. package/dist/preset.js +23 -63
  60. package/dist/preset.mjs +19 -47
  61. package/dist/types.d.mts +17 -20
  62. package/dist/types.d.ts +17 -20
  63. package/dist/types.js +4 -18
  64. package/dist/types.mjs +1 -0
  65. package/package.json +3 -3
@@ -1,123 +1,76 @@
1
+ import { maxDate, minDate, startOfMonth, startOfWeek, startOfYear, toCalendarDate } from "@internationalized/date";
1
2
  // src/constrain.ts
2
- import {
3
- maxDate,
4
- minDate,
5
- startOfMonth,
6
- startOfWeek,
7
- startOfYear,
8
- toCalendarDate
9
- } from "@internationalized/date";
3
+ function withCalendarDate(date, next) {
4
+ return date.set({
5
+ year: next.year,
6
+ month: next.month,
7
+ day: next.day
8
+ });
9
+ }
10
10
  function alignCenter(date, duration, locale, min, max) {
11
- const halfDuration = {};
12
- for (let prop in duration) {
13
- const key = prop;
14
- const value = duration[key];
15
- if (value == null) continue;
16
- halfDuration[key] = Math.floor(value / 2);
17
- if (halfDuration[key] > 0 && value % 2 === 0) {
18
- halfDuration[key]--;
19
- }
20
- }
21
- const aligned = alignStart(date, duration, locale).subtract(halfDuration);
22
- return constrainStart(date, aligned, duration, locale, min, max);
11
+ const halfDuration = {};
12
+ for (let prop in duration) {
13
+ const key = prop;
14
+ const value = duration[key];
15
+ if (value == null) continue;
16
+ halfDuration[key] = Math.floor(value / 2);
17
+ if (halfDuration[key] > 0 && value % 2 === 0) halfDuration[key]--;
18
+ }
19
+ return constrainStart(date, alignStart(date, duration, locale).subtract(halfDuration), duration, locale, min, max);
23
20
  }
24
21
  function alignStart(date, duration, locale, min, max) {
25
- let aligned = date;
26
- if (duration.years) {
27
- aligned = startOfYear(date);
28
- } else if (duration.months) {
29
- aligned = startOfMonth(date);
30
- } else if (duration.weeks) {
31
- aligned = startOfWeek(date, locale);
32
- }
33
- return constrainStart(date, aligned, duration, locale, min, max);
22
+ let aligned = date;
23
+ if (duration.years) aligned = startOfYear(date);
24
+ else if (duration.months) aligned = startOfMonth(date);
25
+ else if (duration.weeks) aligned = startOfWeek(date, locale);
26
+ return constrainStart(date, aligned, duration, locale, min, max);
34
27
  }
35
28
  function alignEnd(date, duration, locale, min, max) {
36
- let d = { ...duration };
37
- if (d.days) {
38
- d.days--;
39
- } else if (d.weeks) {
40
- d.weeks--;
41
- } else if (d.months) {
42
- d.months--;
43
- } else if (d.years) {
44
- d.years--;
45
- }
46
- let aligned = alignStart(date, duration, locale).subtract(d);
47
- return constrainStart(date, aligned, duration, locale, min, max);
29
+ let d = { ...duration };
30
+ if (d.days) d.days--;
31
+ else if (d.weeks) d.weeks--;
32
+ else if (d.months) d.months--;
33
+ else if (d.years) d.years--;
34
+ return constrainStart(date, alignStart(date, duration, locale).subtract(d), duration, locale, min, max);
48
35
  }
49
36
  function constrainStart(date, aligned, duration, locale, min, max) {
50
- if (min && date.compare(min) >= 0) {
51
- aligned = maxDate(aligned, alignStart(toCalendarDate(min), duration, locale));
52
- }
53
- if (max && date.compare(max) <= 0) {
54
- aligned = minDate(aligned, alignEnd(toCalendarDate(max), duration, locale));
55
- }
56
- return aligned;
37
+ let result = aligned;
38
+ if (min && date.compare(min) >= 0) {
39
+ const lower = alignStart(toCalendarDate(min), duration, locale);
40
+ if (toCalendarDate(result).compare(lower) < 0) result = withCalendarDate(result, lower);
41
+ }
42
+ if (max && date.compare(max) <= 0) {
43
+ const upper = alignEnd(toCalendarDate(max), duration, locale);
44
+ if (toCalendarDate(result).compare(upper) > 0) result = withCalendarDate(result, upper);
45
+ }
46
+ return result;
57
47
  }
58
48
  function constrainValue(date, minValue, maxValue) {
59
- const dateOnly = toCalendarDate(date);
60
- const minOnly = minValue ? toCalendarDate(minValue) : void 0;
61
- const maxOnly = maxValue ? toCalendarDate(maxValue) : void 0;
62
- let constrainedDateOnly = dateOnly;
63
- if (minOnly) {
64
- constrainedDateOnly = maxDate(constrainedDateOnly, minOnly);
65
- }
66
- if (maxOnly) {
67
- constrainedDateOnly = minDate(constrainedDateOnly, maxOnly);
68
- }
69
- if (constrainedDateOnly.compare(dateOnly) === 0) {
70
- return date;
71
- }
72
- if ("hour" in date) {
73
- return date.set({
74
- year: constrainedDateOnly.year,
75
- month: constrainedDateOnly.month,
76
- day: constrainedDateOnly.day
77
- });
78
- }
79
- return constrainedDateOnly;
49
+ const dateOnly = toCalendarDate(date);
50
+ const minOnly = minValue ? toCalendarDate(minValue) : void 0;
51
+ const maxOnly = maxValue ? toCalendarDate(maxValue) : void 0;
52
+ let constrainedDateOnly = dateOnly;
53
+ if (minOnly) constrainedDateOnly = maxDate(constrainedDateOnly, minOnly);
54
+ if (maxOnly) constrainedDateOnly = minDate(constrainedDateOnly, maxOnly);
55
+ if (constrainedDateOnly.compare(dateOnly) === 0) return date;
56
+ return withCalendarDate(date, constrainedDateOnly);
80
57
  }
81
58
  function constrainSegments(date, minValue, maxValue) {
82
- const dateOnly = toCalendarDate(date);
83
- const minOnly = minValue ? toCalendarDate(minValue) : void 0;
84
- const maxOnly = maxValue ? toCalendarDate(maxValue) : void 0;
85
- let result = dateOnly;
86
- if (minOnly && result.compare(minOnly) < 0) {
87
- if (result.year < minOnly.year) {
88
- result = result.set({ year: minOnly.year });
89
- }
90
- if (result.compare(minOnly) < 0 && result.month < minOnly.month) {
91
- result = result.set({ month: minOnly.month });
92
- }
93
- if (result.compare(minOnly) < 0 && result.day < minOnly.day) {
94
- result = result.set({ day: minOnly.day });
95
- }
96
- }
97
- if (maxOnly && result.compare(maxOnly) > 0) {
98
- if (result.year > maxOnly.year) {
99
- result = result.set({ year: maxOnly.year });
100
- }
101
- if (result.compare(maxOnly) > 0 && result.month > maxOnly.month) {
102
- result = result.set({ month: maxOnly.month });
103
- }
104
- if (result.compare(maxOnly) > 0 && result.day > maxOnly.day) {
105
- result = result.set({ day: maxOnly.day });
106
- }
107
- }
108
- if (result.compare(dateOnly) === 0) {
109
- return date;
110
- }
111
- if ("hour" in date) {
112
- return date.set({ year: result.year, month: result.month, day: result.day });
113
- }
114
- return result;
59
+ const dateOnly = toCalendarDate(date);
60
+ const minOnly = minValue ? toCalendarDate(minValue) : void 0;
61
+ const maxOnly = maxValue ? toCalendarDate(maxValue) : void 0;
62
+ let result = dateOnly;
63
+ if (minOnly && result.compare(minOnly) < 0) {
64
+ if (result.year < minOnly.year) result = result.set({ year: minOnly.year });
65
+ if (result.compare(minOnly) < 0 && result.month < minOnly.month) result = result.set({ month: minOnly.month });
66
+ if (result.compare(minOnly) < 0 && result.day < minOnly.day) result = result.set({ day: minOnly.day });
67
+ }
68
+ if (maxOnly && result.compare(maxOnly) > 0) {
69
+ if (result.year > maxOnly.year) result = result.set({ year: maxOnly.year });
70
+ if (result.compare(maxOnly) > 0 && result.month > maxOnly.month) result = result.set({ month: maxOnly.month });
71
+ if (result.compare(maxOnly) > 0 && result.day > maxOnly.day) result = result.set({ day: maxOnly.day });
72
+ }
73
+ if (result.compare(dateOnly) === 0) return date;
74
+ return withCalendarDate(date, result);
115
75
  }
116
- export {
117
- alignCenter,
118
- alignEnd,
119
- alignStart,
120
- constrainSegments,
121
- constrainStart,
122
- constrainValue
123
- };
76
+ export { alignCenter, alignEnd, alignStart, constrainSegments, constrainStart, constrainValue };
@@ -1,23 +1,19 @@
1
- import * as _internationalized_date from '@internationalized/date';
2
- import { DateValue } from '@internationalized/date';
3
-
4
- declare function getStartOfWeek(date: DateValue, locale: string, firstDayOfWeek?: number): DateValue;
5
- declare function getEndOfWeek(date: DateValue, locale: string, firstDayOfWeek?: number): DateValue;
6
- declare function getDaysInWeek(weekIndex: number, from: DateValue, locale: string, firstDayOfWeek?: number): DateValue[];
7
- declare function getMonthDays(from: DateValue, locale: string, numOfWeeks?: number, firstDayOfWeek?: number): DateValue[][];
8
- declare function getWeekdayFormats(locale: string, timeZone: string): <T extends DateValue | Date>(value: T) => {
9
- value: T;
10
- short: string;
11
- long: string;
12
- narrow: string;
1
+ import { DateValue } from "@internationalized/date";
2
+ export declare function getStartOfWeek<T extends DateValue>(date: T, locale: string, firstDayOfWeek?: number): T;
3
+ export declare function getEndOfWeek<T extends DateValue>(date: T, locale: string, firstDayOfWeek?: number): T;
4
+ export declare function getDaysInWeek<T extends DateValue>(weekIndex: number, from: T, locale: string, firstDayOfWeek?: number): T[];
5
+ export declare function getMonthDays<T extends DateValue>(from: T, locale: string, numOfWeeks?: number, firstDayOfWeek?: number): T[][];
6
+ export declare function getWeekdayFormats(locale: string, timeZone: string): <T extends DateValue | Date>(value: T) => {
7
+ value: T;
8
+ short: string;
9
+ long: string;
10
+ narrow: string;
13
11
  };
14
- declare function getWeekDays(date: DateValue, startOfWeekProp: number | undefined, timeZone: string, locale: string): {
15
- value: _internationalized_date.CalendarDate | _internationalized_date.CalendarDateTime | _internationalized_date.ZonedDateTime;
16
- short: string;
17
- long: string;
18
- narrow: string;
12
+ export declare function getWeekDays(date: DateValue, startOfWeekProp: number | undefined, timeZone: string, locale: string): {
13
+ value: import("@internationalized/date").CalendarDate | import("@internationalized/date").CalendarDateTime | import("@internationalized/date").ZonedDateTime;
14
+ short: string;
15
+ long: string;
16
+ narrow: string;
19
17
  }[];
20
- declare function getMonthNames(locale: string, format?: Intl.DateTimeFormatOptions["month"], referenceDate?: DateValue): string[];
21
- declare function getWeekOfYear(date: DateValue, locale: string): number;
22
-
23
- export { getDaysInWeek, getEndOfWeek, getMonthDays, getMonthNames, getStartOfWeek, getWeekDays, getWeekOfYear, getWeekdayFormats };
18
+ export declare function getMonthNames(locale: string, format?: Intl.DateTimeFormatOptions["month"], referenceDate?: DateValue): string[];
19
+ export declare function getWeekOfYear(date: DateValue, locale: string): number;
@@ -1,23 +1,19 @@
1
- import * as _internationalized_date from '@internationalized/date';
2
- import { DateValue } from '@internationalized/date';
3
-
4
- declare function getStartOfWeek(date: DateValue, locale: string, firstDayOfWeek?: number): DateValue;
5
- declare function getEndOfWeek(date: DateValue, locale: string, firstDayOfWeek?: number): DateValue;
6
- declare function getDaysInWeek(weekIndex: number, from: DateValue, locale: string, firstDayOfWeek?: number): DateValue[];
7
- declare function getMonthDays(from: DateValue, locale: string, numOfWeeks?: number, firstDayOfWeek?: number): DateValue[][];
8
- declare function getWeekdayFormats(locale: string, timeZone: string): <T extends DateValue | Date>(value: T) => {
9
- value: T;
10
- short: string;
11
- long: string;
12
- narrow: string;
1
+ import { DateValue } from "@internationalized/date";
2
+ export declare function getStartOfWeek<T extends DateValue>(date: T, locale: string, firstDayOfWeek?: number): T;
3
+ export declare function getEndOfWeek<T extends DateValue>(date: T, locale: string, firstDayOfWeek?: number): T;
4
+ export declare function getDaysInWeek<T extends DateValue>(weekIndex: number, from: T, locale: string, firstDayOfWeek?: number): T[];
5
+ export declare function getMonthDays<T extends DateValue>(from: T, locale: string, numOfWeeks?: number, firstDayOfWeek?: number): T[][];
6
+ export declare function getWeekdayFormats(locale: string, timeZone: string): <T extends DateValue | Date>(value: T) => {
7
+ value: T;
8
+ short: string;
9
+ long: string;
10
+ narrow: string;
13
11
  };
14
- declare function getWeekDays(date: DateValue, startOfWeekProp: number | undefined, timeZone: string, locale: string): {
15
- value: _internationalized_date.CalendarDate | _internationalized_date.CalendarDateTime | _internationalized_date.ZonedDateTime;
16
- short: string;
17
- long: string;
18
- narrow: string;
12
+ export declare function getWeekDays(date: DateValue, startOfWeekProp: number | undefined, timeZone: string, locale: string): {
13
+ value: import("@internationalized/date").CalendarDate | import("@internationalized/date").CalendarDateTime | import("@internationalized/date").ZonedDateTime;
14
+ short: string;
15
+ long: string;
16
+ narrow: string;
19
17
  }[];
20
- declare function getMonthNames(locale: string, format?: Intl.DateTimeFormatOptions["month"], referenceDate?: DateValue): string[];
21
- declare function getWeekOfYear(date: DateValue, locale: string): number;
22
-
23
- export { getDaysInWeek, getEndOfWeek, getMonthDays, getMonthNames, getStartOfWeek, getWeekDays, getWeekOfYear, getWeekdayFormats };
18
+ export declare function getMonthNames(locale: string, format?: Intl.DateTimeFormatOptions["month"], referenceDate?: DateValue): string[];
19
+ export declare function getWeekOfYear(date: DateValue, locale: string): number;
@@ -1,131 +1,122 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/date-month.ts
21
- var date_month_exports = {};
22
- __export(date_month_exports, {
23
- getDaysInWeek: () => getDaysInWeek,
24
- getEndOfWeek: () => getEndOfWeek,
25
- getMonthDays: () => getMonthDays,
26
- getMonthNames: () => getMonthNames,
27
- getStartOfWeek: () => getStartOfWeek,
28
- getWeekDays: () => getWeekDays,
29
- getWeekOfYear: () => getWeekOfYear,
30
- getWeekdayFormats: () => getWeekdayFormats
1
+ Object.defineProperties(exports, {
2
+ __esModule: { value: true },
3
+ [Symbol.toStringTag]: { value: "Module" }
31
4
  });
32
- module.exports = __toCommonJS(date_month_exports);
33
- var import_date = require("@internationalized/date");
34
- var daysOfTheWeek = ["sun", "mon", "tue", "wed", "thu", "fri", "sat"];
5
+ let _internationalized_date = require("@internationalized/date");
6
+ // src/date-month.ts
7
+ const daysOfTheWeek = [
8
+ "sun",
9
+ "mon",
10
+ "tue",
11
+ "wed",
12
+ "thu",
13
+ "fri",
14
+ "sat"
15
+ ];
35
16
  function normalizeFirstDayOfWeek(firstDayOfWeek) {
36
- return firstDayOfWeek != null ? daysOfTheWeek[firstDayOfWeek] : void 0;
17
+ return firstDayOfWeek != null ? daysOfTheWeek[firstDayOfWeek] : void 0;
37
18
  }
38
19
  function getStartOfWeek(date, locale, firstDayOfWeek) {
39
- const firstDay = normalizeFirstDayOfWeek(firstDayOfWeek);
40
- return (0, import_date.startOfWeek)(date, locale, firstDay);
20
+ const firstDay = normalizeFirstDayOfWeek(firstDayOfWeek);
21
+ return (0, _internationalized_date.startOfWeek)(date, locale, firstDay);
41
22
  }
42
23
  function getEndOfWeek(date, locale, firstDayOfWeek = 0) {
43
- const firstDay = normalizeFirstDayOfWeek(firstDayOfWeek);
44
- return (0, import_date.endOfWeek)(date, locale, firstDay);
24
+ const firstDay = normalizeFirstDayOfWeek(firstDayOfWeek);
25
+ return (0, _internationalized_date.endOfWeek)(date, locale, firstDay);
45
26
  }
46
27
  function getDaysInWeek(weekIndex, from, locale, firstDayOfWeek) {
47
- const weekDate = from.add({ weeks: weekIndex });
48
- const dates = [];
49
- let date = getStartOfWeek(weekDate, locale, firstDayOfWeek);
50
- while (dates.length < 7) {
51
- dates.push(date);
52
- let nextDate = date.add({ days: 1 });
53
- if ((0, import_date.isSameDay)(date, nextDate)) break;
54
- date = nextDate;
55
- }
56
- return dates;
28
+ const weekDate = from.add({ weeks: weekIndex });
29
+ const dates = [];
30
+ let date = getStartOfWeek(weekDate, locale, firstDayOfWeek);
31
+ while (dates.length < 7) {
32
+ dates.push(date);
33
+ let nextDate = date.add({ days: 1 });
34
+ if ((0, _internationalized_date.isSameDay)(date, nextDate)) break;
35
+ date = nextDate;
36
+ }
37
+ return dates;
57
38
  }
58
39
  function getMonthDays(from, locale, numOfWeeks, firstDayOfWeek) {
59
- const firstDay = normalizeFirstDayOfWeek(firstDayOfWeek);
60
- const monthWeeks = numOfWeeks ?? (0, import_date.getWeeksInMonth)(from, locale, firstDay);
61
- const weeks = [...new Array(monthWeeks).keys()];
62
- return weeks.map((week) => getDaysInWeek(week, from, locale, firstDayOfWeek));
40
+ const firstDay = normalizeFirstDayOfWeek(firstDayOfWeek);
41
+ const monthWeeks = numOfWeeks ?? (0, _internationalized_date.getWeeksInMonth)(from, locale, firstDay);
42
+ return [...new Array(monthWeeks).keys()].map((week) => getDaysInWeek(week, from, locale, firstDayOfWeek));
63
43
  }
64
44
  function getWeekdayFormats(locale, timeZone) {
65
- const longFormat = new import_date.DateFormatter(locale, { weekday: "long", timeZone });
66
- const shortFormat = new import_date.DateFormatter(locale, { weekday: "short", timeZone });
67
- const narrowFormat = new import_date.DateFormatter(locale, { weekday: "narrow", timeZone });
68
- return (value) => {
69
- const date = value instanceof Date ? value : value.toDate(timeZone);
70
- return {
71
- value,
72
- short: shortFormat.format(date),
73
- long: longFormat.format(date),
74
- narrow: narrowFormat.format(date)
75
- };
76
- };
45
+ const longFormat = new _internationalized_date.DateFormatter(locale, {
46
+ weekday: "long",
47
+ timeZone
48
+ });
49
+ const shortFormat = new _internationalized_date.DateFormatter(locale, {
50
+ weekday: "short",
51
+ timeZone
52
+ });
53
+ const narrowFormat = new _internationalized_date.DateFormatter(locale, {
54
+ weekday: "narrow",
55
+ timeZone
56
+ });
57
+ return (value) => {
58
+ const date = value instanceof Date ? value : value.toDate(timeZone);
59
+ return {
60
+ value,
61
+ short: shortFormat.format(date),
62
+ long: longFormat.format(date),
63
+ narrow: narrowFormat.format(date)
64
+ };
65
+ };
77
66
  }
78
67
  function getWeekDays(date, startOfWeekProp, timeZone, locale) {
79
- const firstDayOfWeek = getStartOfWeek(date, locale, startOfWeekProp);
80
- const weeks = [...new Array(7).keys()];
81
- const format = getWeekdayFormats(locale, timeZone);
82
- return weeks.map((index) => format(firstDayOfWeek.add({ days: index })));
68
+ const firstDayOfWeek = getStartOfWeek(date, locale, startOfWeekProp);
69
+ const weeks = [...new Array(7).keys()];
70
+ const format = getWeekdayFormats(locale, timeZone);
71
+ return weeks.map((index) => format(firstDayOfWeek.add({ days: index })));
83
72
  }
84
73
  function getMonthNames(locale, format = "long", referenceDate) {
85
- if (!referenceDate || referenceDate.calendar.identifier === "gregory" || referenceDate.calendar.identifier === "iso8601") {
86
- const date = new Date(2021, 0, 1);
87
- const monthNames2 = [];
88
- for (let i = 0; i < 12; i++) {
89
- monthNames2.push(date.toLocaleString(locale, { month: format }));
90
- date.setMonth(date.getMonth() + 1);
91
- }
92
- return monthNames2;
93
- }
94
- const monthCount = referenceDate.calendar.getMonthsInYear(referenceDate);
95
- const formatter = new import_date.DateFormatter(locale, {
96
- month: format,
97
- calendar: referenceDate.calendar.identifier
98
- });
99
- const monthNames = [];
100
- for (let month = 1; month <= monthCount; month++) {
101
- const d = referenceDate.set({ month });
102
- monthNames.push(formatter.format(d.toDate("UTC")));
103
- }
104
- return monthNames;
74
+ if (!referenceDate || referenceDate.calendar.identifier === "gregory" || referenceDate.calendar.identifier === "iso8601") {
75
+ const date = new Date(2021, 0, 1);
76
+ const monthNames = [];
77
+ for (let i = 0; i < 12; i++) {
78
+ monthNames.push(date.toLocaleString(locale, { month: format }));
79
+ date.setMonth(date.getMonth() + 1);
80
+ }
81
+ return monthNames;
82
+ }
83
+ const monthCount = referenceDate.calendar.getMonthsInYear(referenceDate);
84
+ const formatter = new _internationalized_date.DateFormatter(locale, {
85
+ month: format,
86
+ calendar: referenceDate.calendar.identifier
87
+ });
88
+ const monthNames = [];
89
+ for (let month = 1; month <= monthCount; month++) {
90
+ const d = referenceDate.set({ month });
91
+ monthNames.push(formatter.format(d.toDate("UTC")));
92
+ }
93
+ return monthNames;
105
94
  }
106
95
  function getWeekOfYear(date, locale) {
107
- const mondayOfWeek = (0, import_date.startOfWeek)(date, locale, "mon");
108
- const year = mondayOfWeek.year;
109
- const jan4 = mondayOfWeek.set({ month: 1, day: 4 });
110
- const week1Monday = (0, import_date.startOfWeek)(jan4, locale, "mon");
111
- const julianMonday = mondayOfWeek.calendar.toJulianDay(mondayOfWeek);
112
- const julianWeek1 = week1Monday.calendar.toJulianDay(week1Monday);
113
- if (julianMonday >= julianWeek1) {
114
- return 1 + Math.floor((julianMonday - julianWeek1) / 7);
115
- }
116
- const prevJan4 = mondayOfWeek.set({ year: year - 1, month: 1, day: 4 });
117
- const prevWeek1Monday = (0, import_date.startOfWeek)(prevJan4, locale, "mon");
118
- const julianPrevWeek1 = prevWeek1Monday.calendar.toJulianDay(prevWeek1Monday);
119
- return 1 + Math.floor((julianMonday - julianPrevWeek1) / 7);
96
+ const mondayOfWeek = (0, _internationalized_date.startOfWeek)(date, locale, "mon");
97
+ const year = mondayOfWeek.year;
98
+ const jan4 = mondayOfWeek.set({
99
+ month: 1,
100
+ day: 4
101
+ });
102
+ const week1Monday = (0, _internationalized_date.startOfWeek)(jan4, locale, "mon");
103
+ const julianMonday = mondayOfWeek.calendar.toJulianDay(mondayOfWeek);
104
+ const julianWeek1 = week1Monday.calendar.toJulianDay(week1Monday);
105
+ if (julianMonday >= julianWeek1) return 1 + Math.floor((julianMonday - julianWeek1) / 7);
106
+ const prevJan4 = mondayOfWeek.set({
107
+ year: year - 1,
108
+ month: 1,
109
+ day: 4
110
+ });
111
+ const prevWeek1Monday = (0, _internationalized_date.startOfWeek)(prevJan4, locale, "mon");
112
+ const julianPrevWeek1 = prevWeek1Monday.calendar.toJulianDay(prevWeek1Monday);
113
+ return 1 + Math.floor((julianMonday - julianPrevWeek1) / 7);
120
114
  }
121
- // Annotate the CommonJS export names for ESM import in node:
122
- 0 && (module.exports = {
123
- getDaysInWeek,
124
- getEndOfWeek,
125
- getMonthDays,
126
- getMonthNames,
127
- getStartOfWeek,
128
- getWeekDays,
129
- getWeekOfYear,
130
- getWeekdayFormats
131
- });
115
+ exports.getDaysInWeek = getDaysInWeek;
116
+ exports.getEndOfWeek = getEndOfWeek;
117
+ exports.getMonthDays = getMonthDays;
118
+ exports.getMonthNames = getMonthNames;
119
+ exports.getStartOfWeek = getStartOfWeek;
120
+ exports.getWeekDays = getWeekDays;
121
+ exports.getWeekOfYear = getWeekOfYear;
122
+ exports.getWeekdayFormats = getWeekdayFormats;