react-day-picker 9.1.3 → 9.2.0
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.
- package/dist/cjs/DayPicker.js +34 -29
- package/dist/cjs/DayPicker.js.map +1 -1
- package/dist/cjs/classes/CalendarDay.d.ts +2 -4
- package/dist/cjs/classes/CalendarDay.js +2 -4
- package/dist/cjs/classes/CalendarDay.js.map +1 -1
- package/dist/cjs/classes/DateLib.d.ts +268 -0
- package/dist/cjs/classes/DateLib.js +360 -0
- package/dist/cjs/classes/DateLib.js.map +1 -0
- package/dist/cjs/classes/index.d.ts +1 -0
- package/dist/cjs/classes/index.js +1 -0
- package/dist/cjs/classes/index.js.map +1 -1
- package/dist/cjs/formatters/formatCaption.d.ts +2 -4
- package/dist/cjs/formatters/formatCaption.js +3 -5
- package/dist/cjs/formatters/formatCaption.js.map +1 -1
- package/dist/cjs/formatters/formatDay.d.ts +2 -4
- package/dist/cjs/formatters/formatDay.js +3 -5
- package/dist/cjs/formatters/formatDay.js.map +1 -1
- package/dist/cjs/formatters/formatMonthDropdown.d.ts +1 -1
- package/dist/cjs/formatters/formatMonthDropdown.js +2 -2
- package/dist/cjs/formatters/formatMonthDropdown.js.map +1 -1
- package/dist/cjs/formatters/formatWeekdayName.d.ts +2 -4
- package/dist/cjs/formatters/formatWeekdayName.js +3 -5
- package/dist/cjs/formatters/formatWeekdayName.js.map +1 -1
- package/dist/cjs/helpers/getDates.d.ts +3 -2
- package/dist/cjs/helpers/getDates.js +3 -9
- package/dist/cjs/helpers/getDates.js.map +1 -1
- package/dist/cjs/helpers/getDisplayMonths.d.ts +1 -1
- package/dist/cjs/helpers/getFocusableDate.d.ts +2 -2
- package/dist/cjs/helpers/getFocusableDate.js +3 -5
- package/dist/cjs/helpers/getFocusableDate.js.map +1 -1
- package/dist/cjs/helpers/getInitialMonth.d.ts +2 -1
- package/dist/cjs/helpers/getInitialMonth.js.map +1 -1
- package/dist/cjs/helpers/getMonthOptions.d.ts +2 -2
- package/dist/cjs/helpers/getMonthOptions.js +2 -2
- package/dist/cjs/helpers/getMonthOptions.js.map +1 -1
- package/dist/cjs/helpers/getMonths.d.ts +2 -2
- package/dist/cjs/helpers/getMonths.js +3 -15
- package/dist/cjs/helpers/getMonths.js.map +1 -1
- package/dist/cjs/helpers/getNavMonth.d.ts +2 -2
- package/dist/cjs/helpers/getNavMonth.js.map +1 -1
- package/dist/cjs/helpers/getNextFocus.d.ts +2 -2
- package/dist/cjs/helpers/getNextFocus.js.map +1 -1
- package/dist/cjs/helpers/getNextMonth.d.ts +1 -1
- package/dist/cjs/helpers/getPreviousMonth.d.ts +1 -1
- package/dist/cjs/helpers/getWeekdays.d.ts +5 -7
- package/dist/cjs/helpers/getWeekdays.js +5 -8
- package/dist/cjs/helpers/getWeekdays.js.map +1 -1
- package/dist/cjs/helpers/getYearOptions.d.ts +1 -1
- package/dist/cjs/index.d.ts +1 -2
- package/dist/cjs/index.js +3 -4
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/labels/labelDayButton.d.ts +2 -4
- package/dist/cjs/labels/labelDayButton.js +3 -5
- package/dist/cjs/labels/labelDayButton.js.map +1 -1
- package/dist/cjs/labels/labelGrid.d.ts +2 -4
- package/dist/cjs/labels/labelGrid.js +3 -5
- package/dist/cjs/labels/labelGrid.js.map +1 -1
- package/dist/cjs/labels/labelGridcell.d.ts +2 -5
- package/dist/cjs/labels/labelGridcell.js +3 -5
- package/dist/cjs/labels/labelGridcell.js.map +1 -1
- package/dist/cjs/labels/labelMonthDropdown.d.ts +2 -2
- package/dist/cjs/labels/labelMonthDropdown.js.map +1 -1
- package/dist/cjs/labels/labelWeekNumber.d.ts +2 -2
- package/dist/cjs/labels/labelWeekNumber.js.map +1 -1
- package/dist/cjs/labels/labelWeekNumberHeader.d.ts +2 -2
- package/dist/cjs/labels/labelWeekNumberHeader.js.map +1 -1
- package/dist/cjs/labels/labelWeekday.d.ts +2 -4
- package/dist/cjs/labels/labelWeekday.js +3 -5
- package/dist/cjs/labels/labelWeekday.js.map +1 -1
- package/dist/cjs/labels/labelYearDropdown.d.ts +2 -2
- package/dist/cjs/labels/labelYearDropdown.js.map +1 -1
- package/dist/cjs/selection/useMulti.d.ts +1 -1
- package/dist/cjs/selection/useMulti.js.map +1 -1
- package/dist/cjs/selection/useRange.d.ts +1 -1
- package/dist/cjs/selection/useRange.js.map +1 -1
- package/dist/cjs/selection/useSingle.d.ts +1 -1
- package/dist/cjs/selection/useSingle.js.map +1 -1
- package/dist/cjs/types/props.d.ts +4 -8
- package/dist/cjs/useCalendar.d.ts +2 -3
- package/dist/cjs/useCalendar.js.map +1 -1
- package/dist/cjs/useFocus.d.ts +1 -2
- package/dist/cjs/useFocus.js.map +1 -1
- package/dist/cjs/useGetModifiers.d.ts +1 -2
- package/dist/cjs/useGetModifiers.js.map +1 -1
- package/dist/cjs/useSelection.d.ts +1 -1
- package/dist/cjs/utils/addToRange.d.ts +1 -1
- package/dist/cjs/utils/addToRange.js +2 -2
- package/dist/cjs/utils/addToRange.js.map +1 -1
- package/dist/cjs/utils/dateMatchModifiers.d.ts +1 -1
- package/dist/cjs/utils/dateMatchModifiers.js +2 -2
- package/dist/cjs/utils/dateMatchModifiers.js.map +1 -1
- package/dist/cjs/utils/rangeIncludesDate.d.ts +1 -4
- package/dist/cjs/utils/rangeIncludesDate.js +3 -5
- package/dist/cjs/utils/rangeIncludesDate.js.map +1 -1
- package/dist/cjs/utils/typeguards.d.ts +1 -1
- package/dist/esm/DayPicker.js +34 -29
- package/dist/esm/DayPicker.js.map +1 -1
- package/dist/esm/classes/CalendarDay.d.ts +2 -4
- package/dist/esm/classes/CalendarDay.js +2 -4
- package/dist/esm/classes/CalendarDay.js.map +1 -1
- package/dist/esm/classes/DateLib.d.ts +268 -0
- package/dist/esm/classes/DateLib.js +355 -0
- package/dist/esm/classes/DateLib.js.map +1 -0
- package/dist/esm/classes/index.d.ts +1 -0
- package/dist/esm/classes/index.js +1 -0
- package/dist/esm/classes/index.js.map +1 -1
- package/dist/esm/formatters/formatCaption.d.ts +2 -4
- package/dist/esm/formatters/formatCaption.js +3 -5
- package/dist/esm/formatters/formatCaption.js.map +1 -1
- package/dist/esm/formatters/formatDay.d.ts +2 -4
- package/dist/esm/formatters/formatDay.js +3 -5
- package/dist/esm/formatters/formatDay.js.map +1 -1
- package/dist/esm/formatters/formatMonthDropdown.d.ts +1 -1
- package/dist/esm/formatters/formatMonthDropdown.js +2 -2
- package/dist/esm/formatters/formatMonthDropdown.js.map +1 -1
- package/dist/esm/formatters/formatWeekdayName.d.ts +2 -4
- package/dist/esm/formatters/formatWeekdayName.js +3 -5
- package/dist/esm/formatters/formatWeekdayName.js.map +1 -1
- package/dist/esm/helpers/getDates.d.ts +3 -2
- package/dist/esm/helpers/getDates.js +3 -9
- package/dist/esm/helpers/getDates.js.map +1 -1
- package/dist/esm/helpers/getDisplayMonths.d.ts +1 -1
- package/dist/esm/helpers/getFocusableDate.d.ts +2 -2
- package/dist/esm/helpers/getFocusableDate.js +3 -5
- package/dist/esm/helpers/getFocusableDate.js.map +1 -1
- package/dist/esm/helpers/getInitialMonth.d.ts +2 -1
- package/dist/esm/helpers/getInitialMonth.js.map +1 -1
- package/dist/esm/helpers/getMonthOptions.d.ts +2 -2
- package/dist/esm/helpers/getMonthOptions.js +2 -2
- package/dist/esm/helpers/getMonthOptions.js.map +1 -1
- package/dist/esm/helpers/getMonths.d.ts +2 -2
- package/dist/esm/helpers/getMonths.js +3 -15
- package/dist/esm/helpers/getMonths.js.map +1 -1
- package/dist/esm/helpers/getNavMonth.d.ts +2 -2
- package/dist/esm/helpers/getNavMonth.js.map +1 -1
- package/dist/esm/helpers/getNextFocus.d.ts +2 -2
- package/dist/esm/helpers/getNextFocus.js.map +1 -1
- package/dist/esm/helpers/getNextMonth.d.ts +1 -1
- package/dist/esm/helpers/getPreviousMonth.d.ts +1 -1
- package/dist/esm/helpers/getWeekdays.d.ts +5 -7
- package/dist/esm/helpers/getWeekdays.js +5 -8
- package/dist/esm/helpers/getWeekdays.js.map +1 -1
- package/dist/esm/helpers/getYearOptions.d.ts +1 -1
- package/dist/esm/index.d.ts +1 -2
- package/dist/esm/index.js +1 -2
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/labels/labelDayButton.d.ts +2 -4
- package/dist/esm/labels/labelDayButton.js +3 -5
- package/dist/esm/labels/labelDayButton.js.map +1 -1
- package/dist/esm/labels/labelGrid.d.ts +2 -4
- package/dist/esm/labels/labelGrid.js +3 -5
- package/dist/esm/labels/labelGrid.js.map +1 -1
- package/dist/esm/labels/labelGridcell.d.ts +2 -5
- package/dist/esm/labels/labelGridcell.js +3 -5
- package/dist/esm/labels/labelGridcell.js.map +1 -1
- package/dist/esm/labels/labelMonthDropdown.d.ts +2 -2
- package/dist/esm/labels/labelMonthDropdown.js.map +1 -1
- package/dist/esm/labels/labelWeekNumber.d.ts +2 -2
- package/dist/esm/labels/labelWeekNumber.js.map +1 -1
- package/dist/esm/labels/labelWeekNumberHeader.d.ts +2 -2
- package/dist/esm/labels/labelWeekNumberHeader.js.map +1 -1
- package/dist/esm/labels/labelWeekday.d.ts +2 -4
- package/dist/esm/labels/labelWeekday.js +3 -5
- package/dist/esm/labels/labelWeekday.js.map +1 -1
- package/dist/esm/labels/labelYearDropdown.d.ts +2 -2
- package/dist/esm/labels/labelYearDropdown.js.map +1 -1
- package/dist/esm/selection/useMulti.d.ts +1 -1
- package/dist/esm/selection/useMulti.js.map +1 -1
- package/dist/esm/selection/useRange.d.ts +1 -1
- package/dist/esm/selection/useRange.js.map +1 -1
- package/dist/esm/selection/useSingle.d.ts +1 -1
- package/dist/esm/selection/useSingle.js.map +1 -1
- package/dist/esm/types/props.d.ts +4 -8
- package/dist/esm/useCalendar.d.ts +2 -3
- package/dist/esm/useCalendar.js.map +1 -1
- package/dist/esm/useFocus.d.ts +1 -2
- package/dist/esm/useFocus.js.map +1 -1
- package/dist/esm/useGetModifiers.d.ts +1 -2
- package/dist/esm/useGetModifiers.js.map +1 -1
- package/dist/esm/useSelection.d.ts +1 -1
- package/dist/esm/utils/addToRange.d.ts +1 -1
- package/dist/esm/utils/addToRange.js +1 -1
- package/dist/esm/utils/addToRange.js.map +1 -1
- package/dist/esm/utils/dateMatchModifiers.d.ts +1 -1
- package/dist/esm/utils/dateMatchModifiers.js +1 -1
- package/dist/esm/utils/dateMatchModifiers.js.map +1 -1
- package/dist/esm/utils/rangeIncludesDate.d.ts +1 -4
- package/dist/esm/utils/rangeIncludesDate.js +2 -4
- package/dist/esm/utils/rangeIncludesDate.js.map +1 -1
- package/dist/esm/utils/typeguards.d.ts +1 -1
- package/examples/Formatters.tsx +2 -2
- package/examples/NumberingSystem.tsx +5 -2
- package/examples/RangeLong.tsx +22 -0
- package/examples/TestCase2511.test.tsx +14 -0
- package/examples/TestCase2511.tsx +19 -0
- package/examples/Utc.tsx +2 -3
- package/examples/index.ts +2 -0
- package/jalali.d.ts +1 -0
- package/jalali.js +4 -0
- package/locale.d.ts +1 -0
- package/locale.js +4 -0
- package/package.json +104 -84
- package/src/DayPicker.tsx +48 -53
- package/src/classes/CalendarDay.ts +1 -3
- package/src/classes/DateLib.ts +478 -0
- package/src/classes/index.ts +1 -0
- package/src/formatters/formatCaption.test.ts +12 -4
- package/src/formatters/formatCaption.ts +4 -9
- package/src/formatters/formatDay.ts +4 -6
- package/src/formatters/formatMonthDropdown.ts +3 -3
- package/src/formatters/formatWeekdayName.ts +4 -6
- package/src/helpers/getDates.test.ts +29 -20
- package/src/helpers/getDates.ts +6 -14
- package/src/helpers/getDisplayMonths.test.ts +4 -4
- package/src/helpers/getDisplayMonths.ts +1 -1
- package/src/helpers/getFocusableDate.ts +5 -8
- package/src/helpers/getFormatters.test.ts +9 -5
- package/src/helpers/getInitialMonth.test.ts +7 -6
- package/src/helpers/getInitialMonth.ts +2 -1
- package/src/helpers/getMonthOptions.test.ts +3 -4
- package/src/helpers/getMonthOptions.ts +2 -3
- package/src/helpers/getMonths.test.ts +7 -10
- package/src/helpers/getMonths.ts +5 -26
- package/src/helpers/getNavMonth.test.ts +9 -9
- package/src/helpers/getNavMonth.ts +1 -2
- package/src/helpers/getNextFocus.test.tsx +11 -12
- package/src/helpers/getNextFocus.tsx +2 -8
- package/src/helpers/getNextMonth.test.ts +9 -8
- package/src/helpers/getNextMonth.ts +1 -1
- package/src/helpers/getPossibleFocusDate.test.ts +6 -5
- package/src/helpers/getPreviousMonth.test.ts +7 -7
- package/src/helpers/getPreviousMonth.ts +1 -1
- package/src/helpers/getWeekdays.test.ts +8 -4
- package/src/helpers/getWeekdays.ts +6 -10
- package/src/helpers/getYearOptions.test.ts +4 -4
- package/src/helpers/getYearOptions.ts +1 -1
- package/src/index.ts +1 -3
- package/src/labels/labelDayButton.ts +4 -6
- package/src/labels/labelGrid.ts +4 -6
- package/src/labels/labelGridcell.ts +4 -7
- package/src/labels/labelMonthDropdown.ts +2 -2
- package/src/labels/labelWeekNumber.ts +2 -2
- package/src/labels/labelWeekNumberHeader.ts +2 -2
- package/src/labels/labelWeekday.ts +4 -6
- package/src/labels/labelYearDropdown.ts +2 -2
- package/src/selection/useMulti.test.tsx +3 -4
- package/src/selection/useMulti.tsx +1 -1
- package/src/selection/useRange.test.tsx +8 -8
- package/src/selection/useRange.tsx +1 -1
- package/src/selection/useSingle.test.tsx +3 -4
- package/src/selection/useSingle.tsx +1 -1
- package/src/style.css +2 -2
- package/src/style.module.css.d.ts +29 -0
- package/src/types/props.ts +4 -8
- package/src/useCalendar.ts +2 -3
- package/src/useFocus.ts +1 -2
- package/src/useGetModifiers.tsx +1 -2
- package/src/useSelection.ts +1 -1
- package/src/utils/addToRange.ts +1 -1
- package/src/utils/dateMatchModifiers.test.ts +21 -13
- package/src/utils/dateMatchModifiers.ts +1 -1
- package/src/utils/rangeIncludesDate.ts +2 -3
- package/src/utils/typeguards.test.ts +5 -5
- package/src/utils/typeguards.ts +1 -1
- package/website/docs/docs/styling.mdx +2 -2
- package/dist/cjs/helpers/getDateLib.d.ts +0 -3
- package/dist/cjs/helpers/getDateLib.js +0 -11
- package/dist/cjs/helpers/getDateLib.js.map +0 -1
- package/dist/cjs/lib/dateLib.d.ts +0 -138
- package/dist/cjs/lib/dateLib.js +0 -68
- package/dist/cjs/lib/dateLib.js.map +0 -1
- package/dist/cjs/lib/index.d.ts +0 -2
- package/dist/cjs/lib/index.js +0 -21
- package/dist/cjs/lib/index.js.map +0 -1
- package/dist/cjs/lib/locales.d.ts +0 -1
- package/dist/cjs/lib/locales.js +0 -6
- package/dist/cjs/lib/locales.js.map +0 -1
- package/dist/esm/helpers/getDateLib.d.ts +0 -3
- package/dist/esm/helpers/getDateLib.js +0 -8
- package/dist/esm/helpers/getDateLib.js.map +0 -1
- package/dist/esm/lib/dateLib.d.ts +0 -138
- package/dist/esm/lib/dateLib.js +0 -65
- package/dist/esm/lib/dateLib.js.map +0 -1
- package/dist/esm/lib/index.d.ts +0 -2
- package/dist/esm/lib/index.js +0 -3
- package/dist/esm/lib/index.js.map +0 -1
- package/dist/esm/lib/locales.d.ts +0 -1
- package/dist/esm/lib/locales.js +0 -2
- package/dist/esm/lib/locales.js.map +0 -1
- package/src/helpers/getDateLib.ts +0 -9
- package/src/lib/dateLib.ts +0 -175
- package/src/lib/index.ts +0 -2
- package/src/lib/locales.ts +0 -1
- package/src/style.css.d.ts +0 -38
|
@@ -0,0 +1,478 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DateArg,
|
|
3
|
+
EndOfWeekOptions,
|
|
4
|
+
FormatOptions as DateFnsFormatOptions,
|
|
5
|
+
StartOfWeekOptions,
|
|
6
|
+
addDays,
|
|
7
|
+
addMonths,
|
|
8
|
+
addWeeks,
|
|
9
|
+
addYears,
|
|
10
|
+
differenceInCalendarDays,
|
|
11
|
+
differenceInCalendarMonths,
|
|
12
|
+
endOfISOWeek,
|
|
13
|
+
endOfMonth,
|
|
14
|
+
endOfWeek,
|
|
15
|
+
endOfYear,
|
|
16
|
+
format,
|
|
17
|
+
getISOWeek,
|
|
18
|
+
getWeek,
|
|
19
|
+
isAfter,
|
|
20
|
+
isBefore,
|
|
21
|
+
isDate,
|
|
22
|
+
isSameDay,
|
|
23
|
+
isSameMonth,
|
|
24
|
+
isSameYear,
|
|
25
|
+
max,
|
|
26
|
+
min,
|
|
27
|
+
setMonth,
|
|
28
|
+
setYear,
|
|
29
|
+
startOfDay,
|
|
30
|
+
startOfISOWeek,
|
|
31
|
+
startOfMonth,
|
|
32
|
+
startOfWeek,
|
|
33
|
+
startOfYear
|
|
34
|
+
} from "date-fns";
|
|
35
|
+
import type { Locale } from "date-fns/locale";
|
|
36
|
+
import { enUS } from "date-fns/locale";
|
|
37
|
+
|
|
38
|
+
export type { Locale } from "date-fns/locale";
|
|
39
|
+
export type { Month as DateFnsMonth } from "date-fns";
|
|
40
|
+
|
|
41
|
+
/** @deprecated Use {@link DateLibOptions} instead. */
|
|
42
|
+
export type FormatOptions = DateLibOptions;
|
|
43
|
+
/** @deprecated Use {@link DateLibOptions} instead. */
|
|
44
|
+
export type LabelOptions = DateLibOptions;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* The options for the `DateLib` class.
|
|
48
|
+
*
|
|
49
|
+
* Extends `date-fns` [format](https://date-fns.org/docs/format),
|
|
50
|
+
* [startOfWeek](https://date-fns.org/docs/startOfWeek) and
|
|
51
|
+
* [endOfWeek](https://date-fns.org/docs/endOfWeek) options.
|
|
52
|
+
*
|
|
53
|
+
* @since 9.2.0
|
|
54
|
+
*/
|
|
55
|
+
export interface DateLibOptions
|
|
56
|
+
extends DateFnsFormatOptions,
|
|
57
|
+
StartOfWeekOptions,
|
|
58
|
+
EndOfWeekOptions {
|
|
59
|
+
/** A constructor for the `Date` object. */
|
|
60
|
+
Date?: typeof Date;
|
|
61
|
+
/** A locale to use for formatting dates. */
|
|
62
|
+
locale?: Locale;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* A wrapper class around [date-fns](http://date-fns.org) sharing the same
|
|
67
|
+
* options. Methods of this class can be overridden using the
|
|
68
|
+
* {@link PropsBase.dateLib} prop.
|
|
69
|
+
*
|
|
70
|
+
* @since 9.2.0
|
|
71
|
+
* @example
|
|
72
|
+
* const dateLib = new DateLib({ locale: es });
|
|
73
|
+
* const newDate = dateLib.addDays(new Date(), 5);
|
|
74
|
+
*/
|
|
75
|
+
export class DateLib {
|
|
76
|
+
/** The options for the date library. */
|
|
77
|
+
readonly options: DateLibOptions;
|
|
78
|
+
|
|
79
|
+
/** Overrides for the date library functions. */
|
|
80
|
+
readonly overrides?: Partial<typeof DateLib.prototype>;
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Creates an instance of DateLib.
|
|
84
|
+
*
|
|
85
|
+
* @param options The options for the date library.
|
|
86
|
+
* @param overrides Overrides for the date library functions.
|
|
87
|
+
*/
|
|
88
|
+
constructor(
|
|
89
|
+
options?: DateLibOptions,
|
|
90
|
+
overrides?: Partial<typeof DateLib.prototype>
|
|
91
|
+
) {
|
|
92
|
+
this.options = { locale: enUS, ...options };
|
|
93
|
+
this.overrides = overrides;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** Reference to the built-in Date constructor. */
|
|
97
|
+
Date: typeof Date = Date;
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Adds the specified number of days to the given date.
|
|
101
|
+
*
|
|
102
|
+
* @param date The date to add days to.
|
|
103
|
+
* @param amount The number of days to add.
|
|
104
|
+
* @returns The new date with the days added.
|
|
105
|
+
*/
|
|
106
|
+
addDays: typeof addDays = (date, amount) => {
|
|
107
|
+
return this.overrides?.addDays
|
|
108
|
+
? this.overrides.addDays(date, amount)
|
|
109
|
+
: addDays(date, amount);
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Adds the specified number of months to the given date.
|
|
114
|
+
*
|
|
115
|
+
* @param date The date to add months to.
|
|
116
|
+
* @param amount The number of months to add.
|
|
117
|
+
* @returns The new date with the months added.
|
|
118
|
+
*/
|
|
119
|
+
addMonths: typeof addMonths = (date, amount) => {
|
|
120
|
+
return this.overrides?.addMonths
|
|
121
|
+
? this.overrides.addMonths(date, amount)
|
|
122
|
+
: addMonths(date, amount);
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Adds the specified number of weeks to the given date.
|
|
127
|
+
*
|
|
128
|
+
* @param date The date to add weeks to.
|
|
129
|
+
* @param amount The number of weeks to add.
|
|
130
|
+
* @returns The new date with the weeks added.
|
|
131
|
+
*/
|
|
132
|
+
addWeeks: typeof addWeeks = (date, amount) => {
|
|
133
|
+
return this.overrides?.addWeeks
|
|
134
|
+
? this.overrides.addWeeks(date, amount)
|
|
135
|
+
: addWeeks(date, amount);
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Adds the specified number of years to the given date.
|
|
140
|
+
*
|
|
141
|
+
* @param date The date to add years to.
|
|
142
|
+
* @param amount The number of years to add.
|
|
143
|
+
* @returns The new date with the years added.
|
|
144
|
+
*/
|
|
145
|
+
addYears: typeof addYears = (date, amount) => {
|
|
146
|
+
return this.overrides?.addYears
|
|
147
|
+
? this.overrides.addYears(date, amount)
|
|
148
|
+
: addYears(date, amount);
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Returns the number of calendar days between the given dates.
|
|
153
|
+
*
|
|
154
|
+
* @param dateLeft The later date.
|
|
155
|
+
* @param dateRight The earlier date.
|
|
156
|
+
* @returns The number of calendar days between the dates.
|
|
157
|
+
*/
|
|
158
|
+
differenceInCalendarDays: typeof differenceInCalendarDays = (
|
|
159
|
+
dateLeft,
|
|
160
|
+
dateRight
|
|
161
|
+
) => {
|
|
162
|
+
return this.overrides?.differenceInCalendarDays
|
|
163
|
+
? this.overrides.differenceInCalendarDays(dateLeft, dateRight)
|
|
164
|
+
: differenceInCalendarDays(dateLeft, dateRight);
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Returns the number of calendar months between the given dates.
|
|
169
|
+
*
|
|
170
|
+
* @param dateLeft The later date.
|
|
171
|
+
* @param dateRight The earlier date.
|
|
172
|
+
* @returns The number of calendar months between the dates.
|
|
173
|
+
*/
|
|
174
|
+
differenceInCalendarMonths: typeof differenceInCalendarMonths = (
|
|
175
|
+
dateLeft,
|
|
176
|
+
dateRight
|
|
177
|
+
) => {
|
|
178
|
+
return this.overrides?.differenceInCalendarMonths
|
|
179
|
+
? this.overrides.differenceInCalendarMonths(dateLeft, dateRight)
|
|
180
|
+
: differenceInCalendarMonths(dateLeft, dateRight);
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Returns the end of the ISO week for the given date.
|
|
185
|
+
*
|
|
186
|
+
* @param date The original date.
|
|
187
|
+
* @returns The end of the ISO week.
|
|
188
|
+
*/
|
|
189
|
+
endOfISOWeek: typeof endOfISOWeek = (date) => {
|
|
190
|
+
return this.overrides?.endOfISOWeek
|
|
191
|
+
? this.overrides.endOfISOWeek(date)
|
|
192
|
+
: endOfISOWeek(date);
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Returns the end of the month for the given date.
|
|
197
|
+
*
|
|
198
|
+
* @param date The original date.
|
|
199
|
+
* @returns The end of the month.
|
|
200
|
+
*/
|
|
201
|
+
endOfMonth: typeof endOfMonth = (date) => {
|
|
202
|
+
return this.overrides?.endOfMonth
|
|
203
|
+
? this.overrides.endOfMonth(date)
|
|
204
|
+
: endOfMonth(date);
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Returns the end of the week for the given date.
|
|
209
|
+
*
|
|
210
|
+
* @param date The original date.
|
|
211
|
+
* @returns The end of the week.
|
|
212
|
+
*/
|
|
213
|
+
endOfWeek: typeof endOfWeek = <
|
|
214
|
+
DateType extends Date,
|
|
215
|
+
ResultDate extends Date = DateType
|
|
216
|
+
>(
|
|
217
|
+
date: DateArg<DateType>
|
|
218
|
+
): ResultDate => {
|
|
219
|
+
return this.overrides?.endOfWeek
|
|
220
|
+
? this.overrides.endOfWeek(
|
|
221
|
+
date,
|
|
222
|
+
this.options as EndOfWeekOptions<ResultDate>
|
|
223
|
+
)
|
|
224
|
+
: endOfWeek(date, this.options as EndOfWeekOptions<ResultDate>);
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* Returns the end of the year for the given date.
|
|
229
|
+
*
|
|
230
|
+
* @param date The original date.
|
|
231
|
+
* @returns The end of the year.
|
|
232
|
+
*/
|
|
233
|
+
endOfYear: typeof endOfYear = (date) => {
|
|
234
|
+
return this.overrides?.endOfYear
|
|
235
|
+
? this.overrides.endOfYear(date)
|
|
236
|
+
: endOfYear(date);
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* Formats the given date using the specified format string.
|
|
241
|
+
*
|
|
242
|
+
* @param date The date to format.
|
|
243
|
+
* @param formatStr The format string.
|
|
244
|
+
* @returns The formatted date string.
|
|
245
|
+
*/
|
|
246
|
+
format: typeof format = (date, formatStr) => {
|
|
247
|
+
return this.overrides?.format
|
|
248
|
+
? this.overrides.format(date, formatStr, this.options)
|
|
249
|
+
: format(date, formatStr, this.options);
|
|
250
|
+
};
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* Returns the ISO week number for the given date.
|
|
254
|
+
*
|
|
255
|
+
* @param date The date to get the ISO week number for.
|
|
256
|
+
* @returns The ISO week number.
|
|
257
|
+
*/
|
|
258
|
+
getISOWeek: typeof getISOWeek = (date) => {
|
|
259
|
+
return this.overrides?.getISOWeek
|
|
260
|
+
? this.overrides.getISOWeek(date)
|
|
261
|
+
: getISOWeek(date);
|
|
262
|
+
};
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* Returns the local week number for the given date.
|
|
266
|
+
*
|
|
267
|
+
* @param date The date to get the week number for.
|
|
268
|
+
* @returns The week number.
|
|
269
|
+
*/
|
|
270
|
+
getWeek: typeof getWeek = (date) => {
|
|
271
|
+
return this.overrides?.getWeek
|
|
272
|
+
? this.overrides.getWeek(date, this.options)
|
|
273
|
+
: getWeek(date, this.options);
|
|
274
|
+
};
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* Checks if the first date is after the second date.
|
|
278
|
+
*
|
|
279
|
+
* @param date The date to compare.
|
|
280
|
+
* @param dateToCompare The date to compare with.
|
|
281
|
+
* @returns True if the first date is after the second date.
|
|
282
|
+
*/
|
|
283
|
+
isAfter: typeof isAfter = (date, dateToCompare) => {
|
|
284
|
+
return this.overrides?.isAfter
|
|
285
|
+
? this.overrides.isAfter(date, dateToCompare)
|
|
286
|
+
: isAfter(date, dateToCompare);
|
|
287
|
+
};
|
|
288
|
+
|
|
289
|
+
/**
|
|
290
|
+
* Checks if the first date is before the second date.
|
|
291
|
+
*
|
|
292
|
+
* @param date The date to compare.
|
|
293
|
+
* @param dateToCompare The date to compare with.
|
|
294
|
+
* @returns True if the first date is before the second date.
|
|
295
|
+
*/
|
|
296
|
+
isBefore: typeof isBefore = (date, dateToCompare) => {
|
|
297
|
+
return this.overrides?.isBefore
|
|
298
|
+
? this.overrides.isBefore(date, dateToCompare)
|
|
299
|
+
: isBefore(date, dateToCompare);
|
|
300
|
+
};
|
|
301
|
+
|
|
302
|
+
/**
|
|
303
|
+
* Checks if the given value is a Date object.
|
|
304
|
+
*
|
|
305
|
+
* @param value The value to check.
|
|
306
|
+
* @returns True if the value is a Date object.
|
|
307
|
+
*/
|
|
308
|
+
isDate: (value: unknown) => value is Date = (value): value is Date => {
|
|
309
|
+
return this.overrides?.isDate
|
|
310
|
+
? this.overrides.isDate(value)
|
|
311
|
+
: isDate(value);
|
|
312
|
+
};
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
* Checks if the given dates are on the same day.
|
|
316
|
+
*
|
|
317
|
+
* @param dateLeft The first date to compare.
|
|
318
|
+
* @param dateRight The second date to compare.
|
|
319
|
+
* @returns True if the dates are on the same day.
|
|
320
|
+
*/
|
|
321
|
+
isSameDay: typeof isSameDay = (dateLeft, dateRight) => {
|
|
322
|
+
return this.overrides?.isSameDay
|
|
323
|
+
? this.overrides.isSameDay(dateLeft, dateRight)
|
|
324
|
+
: isSameDay(dateLeft, dateRight);
|
|
325
|
+
};
|
|
326
|
+
|
|
327
|
+
/**
|
|
328
|
+
* Checks if the given dates are in the same month.
|
|
329
|
+
*
|
|
330
|
+
* @param dateLeft The first date to compare.
|
|
331
|
+
* @param dateRight The second date to compare.
|
|
332
|
+
* @returns True if the dates are in the same month.
|
|
333
|
+
*/
|
|
334
|
+
isSameMonth: typeof isSameMonth = (dateLeft, dateRight) => {
|
|
335
|
+
return this.overrides?.isSameMonth
|
|
336
|
+
? this.overrides.isSameMonth(dateLeft, dateRight)
|
|
337
|
+
: isSameMonth(dateLeft, dateRight);
|
|
338
|
+
};
|
|
339
|
+
|
|
340
|
+
/**
|
|
341
|
+
* Checks if the given dates are in the same year.
|
|
342
|
+
*
|
|
343
|
+
* @param dateLeft The first date to compare.
|
|
344
|
+
* @param dateRight The second date to compare.
|
|
345
|
+
* @returns True if the dates are in the same year.
|
|
346
|
+
*/
|
|
347
|
+
isSameYear: typeof isSameYear = (dateLeft, dateRight) => {
|
|
348
|
+
return this.overrides?.isSameYear
|
|
349
|
+
? this.overrides.isSameYear(dateLeft, dateRight)
|
|
350
|
+
: isSameYear(dateLeft, dateRight);
|
|
351
|
+
};
|
|
352
|
+
|
|
353
|
+
/**
|
|
354
|
+
* Returns the latest date in the given array of dates.
|
|
355
|
+
*
|
|
356
|
+
* @param dates The array of dates to compare.
|
|
357
|
+
* @returns The latest date.
|
|
358
|
+
*/
|
|
359
|
+
max: typeof max = (dates) => {
|
|
360
|
+
return this.overrides?.max ? this.overrides.max(dates) : max(dates);
|
|
361
|
+
};
|
|
362
|
+
|
|
363
|
+
/**
|
|
364
|
+
* Returns the earliest date in the given array of dates.
|
|
365
|
+
*
|
|
366
|
+
* @param dates The array of dates to compare.
|
|
367
|
+
* @returns The earliest date.
|
|
368
|
+
*/
|
|
369
|
+
min: typeof min = (dates) => {
|
|
370
|
+
return this.overrides?.min ? this.overrides.min(dates) : min(dates);
|
|
371
|
+
};
|
|
372
|
+
|
|
373
|
+
/**
|
|
374
|
+
* Sets the month of the given date.
|
|
375
|
+
*
|
|
376
|
+
* @param date The date to set the month on.
|
|
377
|
+
* @param month The month to set (0-11).
|
|
378
|
+
* @returns The new date with the month set.
|
|
379
|
+
*/
|
|
380
|
+
setMonth: typeof setMonth = (date, month) => {
|
|
381
|
+
return this.overrides?.setMonth
|
|
382
|
+
? this.overrides.setMonth(date, month)
|
|
383
|
+
: setMonth(date, month);
|
|
384
|
+
};
|
|
385
|
+
|
|
386
|
+
/**
|
|
387
|
+
* Sets the year of the given date.
|
|
388
|
+
*
|
|
389
|
+
* @param date The date to set the year on.
|
|
390
|
+
* @param year The year to set.
|
|
391
|
+
* @returns The new date with the year set.
|
|
392
|
+
*/
|
|
393
|
+
setYear: typeof setYear = (date, year) => {
|
|
394
|
+
return this.overrides?.setYear
|
|
395
|
+
? this.overrides.setYear(date, year)
|
|
396
|
+
: setYear(date, year);
|
|
397
|
+
};
|
|
398
|
+
|
|
399
|
+
/**
|
|
400
|
+
* Returns the start of the day for the given date.
|
|
401
|
+
*
|
|
402
|
+
* @param date The original date.
|
|
403
|
+
* @returns The start of the day.
|
|
404
|
+
*/
|
|
405
|
+
startOfDay: typeof startOfDay = (date) => {
|
|
406
|
+
return this.overrides?.startOfDay
|
|
407
|
+
? this.overrides.startOfDay(date)
|
|
408
|
+
: startOfDay(date);
|
|
409
|
+
};
|
|
410
|
+
|
|
411
|
+
/**
|
|
412
|
+
* Returns the start of the ISO week for the given date.
|
|
413
|
+
*
|
|
414
|
+
* @param date The original date.
|
|
415
|
+
* @returns The start of the ISO week.
|
|
416
|
+
*/
|
|
417
|
+
startOfISOWeek: typeof startOfISOWeek = (date) => {
|
|
418
|
+
return this.overrides?.startOfISOWeek
|
|
419
|
+
? this.overrides.startOfISOWeek(date)
|
|
420
|
+
: startOfISOWeek(date);
|
|
421
|
+
};
|
|
422
|
+
|
|
423
|
+
/**
|
|
424
|
+
* Returns the start of the month for the given date.
|
|
425
|
+
*
|
|
426
|
+
* @param date The original date.
|
|
427
|
+
* @returns The start of the month.
|
|
428
|
+
*/
|
|
429
|
+
startOfMonth: typeof startOfMonth = (date) => {
|
|
430
|
+
return this.overrides?.startOfMonth
|
|
431
|
+
? this.overrides.startOfMonth(date)
|
|
432
|
+
: startOfMonth(date);
|
|
433
|
+
};
|
|
434
|
+
|
|
435
|
+
/**
|
|
436
|
+
* Returns the start of the week for the given date.
|
|
437
|
+
*
|
|
438
|
+
* @param date The original date.
|
|
439
|
+
* @returns The start of the week.
|
|
440
|
+
*/
|
|
441
|
+
startOfWeek: typeof startOfWeek = <
|
|
442
|
+
DateType extends Date,
|
|
443
|
+
ResultDate extends Date = DateType
|
|
444
|
+
>(
|
|
445
|
+
date: DateArg<DateType>
|
|
446
|
+
): ResultDate => {
|
|
447
|
+
return this.overrides?.startOfWeek
|
|
448
|
+
? this.overrides.startOfWeek(
|
|
449
|
+
date,
|
|
450
|
+
this.options as StartOfWeekOptions<ResultDate>
|
|
451
|
+
)
|
|
452
|
+
: startOfWeek(date, this.options as StartOfWeekOptions<ResultDate>);
|
|
453
|
+
};
|
|
454
|
+
|
|
455
|
+
/**
|
|
456
|
+
* Returns the start of the year for the given date.
|
|
457
|
+
*
|
|
458
|
+
* @param date The original date.
|
|
459
|
+
* @returns The start of the year.
|
|
460
|
+
*/
|
|
461
|
+
startOfYear: typeof startOfYear = (date) => {
|
|
462
|
+
return this.overrides?.startOfYear
|
|
463
|
+
? this.overrides.startOfYear(date)
|
|
464
|
+
: startOfYear(date);
|
|
465
|
+
};
|
|
466
|
+
}
|
|
467
|
+
/** The default locale (English). */
|
|
468
|
+
export { enUS as defaultLocale } from "date-fns/locale/en-US";
|
|
469
|
+
|
|
470
|
+
/**
|
|
471
|
+
* The default date library with English locale.
|
|
472
|
+
*
|
|
473
|
+
* @since 9.2.0
|
|
474
|
+
*/
|
|
475
|
+
export const defaultDateLib = new DateLib();
|
|
476
|
+
|
|
477
|
+
/** @deprecated Use `defaultDateLib`. */
|
|
478
|
+
export const dateLib = defaultDateLib;
|
package/src/classes/index.ts
CHANGED
|
@@ -1,19 +1,27 @@
|
|
|
1
1
|
import { es } from "date-fns/locale/es";
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { defaultLocale, DateLib } from "../classes/DateLib.js";
|
|
4
4
|
|
|
5
5
|
import { formatCaption } from "./formatCaption";
|
|
6
6
|
|
|
7
7
|
const date = new Date(2022, 10, 21);
|
|
8
8
|
|
|
9
9
|
test("should return the formatted caption", () => {
|
|
10
|
-
expect(
|
|
10
|
+
expect(
|
|
11
|
+
formatCaption(date, {}, new DateLib({ locale: defaultLocale }))
|
|
12
|
+
).toEqual("November 2022");
|
|
11
13
|
});
|
|
12
14
|
|
|
13
|
-
describe("when a locale is passed in", () => {
|
|
15
|
+
describe("when a locale is passed in through dateLib argument", () => {
|
|
14
16
|
test("should format using the locale", () => {
|
|
15
|
-
expect(formatCaption(date, { locale: es }
|
|
17
|
+
expect(formatCaption(date, {}, new DateLib({ locale: es }))).toEqual(
|
|
16
18
|
"noviembre 2022"
|
|
17
19
|
);
|
|
18
20
|
});
|
|
19
21
|
});
|
|
22
|
+
|
|
23
|
+
describe("when a locale is passed in from options", () => {
|
|
24
|
+
test("should format using the locale", () => {
|
|
25
|
+
expect(formatCaption(date, { locale: es })).toEqual("noviembre 2022");
|
|
26
|
+
});
|
|
27
|
+
});
|
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
FormatOptions,
|
|
3
|
-
dateLib as defaultDateLib,
|
|
4
|
-
type DateLib
|
|
5
|
-
} from "../lib/index.js";
|
|
1
|
+
import { DateLib, type DateLibOptions } from "../classes/DateLib.js";
|
|
6
2
|
|
|
7
3
|
/**
|
|
8
4
|
* Format the caption of the month.
|
|
@@ -13,11 +9,10 @@ import {
|
|
|
13
9
|
*/
|
|
14
10
|
export function formatCaption(
|
|
15
11
|
month: Date,
|
|
16
|
-
options?:
|
|
17
|
-
|
|
18
|
-
dateLib: DateLib = defaultDateLib
|
|
12
|
+
options?: DateLibOptions,
|
|
13
|
+
dateLib?: DateLib
|
|
19
14
|
) {
|
|
20
|
-
return dateLib.format(month, "LLLL y"
|
|
15
|
+
return (dateLib ?? new DateLib(options)).format(month, "LLLL y");
|
|
21
16
|
}
|
|
22
17
|
|
|
23
18
|
/**
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { dateLib as defaultDateLib } from "../lib/index.js";
|
|
1
|
+
import { DateLib, type DateLibOptions } from "../classes/DateLib.js";
|
|
3
2
|
|
|
4
3
|
/**
|
|
5
4
|
* Format the day date shown in the day cell.
|
|
@@ -10,9 +9,8 @@ import { dateLib as defaultDateLib } from "../lib/index.js";
|
|
|
10
9
|
*/
|
|
11
10
|
export function formatDay(
|
|
12
11
|
date: Date,
|
|
13
|
-
options?:
|
|
14
|
-
|
|
15
|
-
dateLib: DateLib = defaultDateLib
|
|
12
|
+
options?: DateLibOptions,
|
|
13
|
+
dateLib?: DateLib
|
|
16
14
|
) {
|
|
17
|
-
return dateLib.format(date, "d"
|
|
15
|
+
return (dateLib ?? new DateLib(options)).format(date, "d");
|
|
18
16
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { DateFnsMonth } from "../
|
|
2
|
-
import {
|
|
1
|
+
import type { DateFnsMonth } from "../classes/DateLib.js";
|
|
2
|
+
import { defaultLocale } from "../classes/DateLib.js";
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Format the month number for the dropdown option label.
|
|
@@ -12,7 +12,7 @@ export function formatMonthDropdown(
|
|
|
12
12
|
/** The month number to format. */
|
|
13
13
|
monthNumber: number,
|
|
14
14
|
/** The locale to use for formatting. */
|
|
15
|
-
locale =
|
|
15
|
+
locale = defaultLocale
|
|
16
16
|
): string {
|
|
17
17
|
return locale.localize?.month(monthNumber as DateFnsMonth);
|
|
18
18
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { dateLib as defaultDateLib } from "../lib/index.js";
|
|
1
|
+
import { DateLib, type DateLibOptions } from "../classes/DateLib.js";
|
|
3
2
|
|
|
4
3
|
/**
|
|
5
4
|
* Format the weekday name to be displayed in the weekdays header.
|
|
@@ -10,9 +9,8 @@ import { dateLib as defaultDateLib } from "../lib/index.js";
|
|
|
10
9
|
*/
|
|
11
10
|
export function formatWeekdayName(
|
|
12
11
|
weekday: Date,
|
|
13
|
-
options?:
|
|
14
|
-
|
|
15
|
-
dateLib: DateLib = defaultDateLib
|
|
12
|
+
options?: DateLibOptions,
|
|
13
|
+
dateLib?: DateLib
|
|
16
14
|
) {
|
|
17
|
-
return dateLib.format(weekday, "cccccc"
|
|
15
|
+
return (dateLib ?? new DateLib(options)).format(weekday, "cccccc");
|
|
18
16
|
}
|