react-day-picker 9.13.2 → 9.14.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/README.md +1 -1
- package/dist/cjs/DayPicker.js +1 -1
- package/dist/cjs/UI.d.ts +21 -14
- package/dist/cjs/UI.js +2 -2
- package/dist/cjs/hijri/index.d.ts +28 -0
- package/dist/cjs/hijri/index.js +98 -0
- package/dist/cjs/hijri/lib/addMonths.d.ts +1 -0
- package/dist/cjs/hijri/lib/addMonths.js +9 -0
- package/dist/cjs/hijri/lib/addYears.d.ts +1 -0
- package/dist/cjs/hijri/lib/addYears.js +9 -0
- package/dist/cjs/hijri/lib/differenceInCalendarMonths.d.ts +1 -0
- package/dist/cjs/hijri/lib/differenceInCalendarMonths.js +10 -0
- package/dist/cjs/hijri/lib/eachMonthOfInterval.d.ts +2 -0
- package/dist/cjs/hijri/lib/eachMonthOfInterval.js +29 -0
- package/dist/cjs/hijri/lib/eachYearOfInterval.d.ts +2 -0
- package/dist/cjs/hijri/lib/eachYearOfInterval.js +19 -0
- package/dist/cjs/hijri/lib/endOfMonth.d.ts +1 -0
- package/dist/cjs/hijri/lib/endOfMonth.js +14 -0
- package/dist/cjs/hijri/lib/endOfYear.d.ts +1 -0
- package/dist/cjs/hijri/lib/endOfYear.js +14 -0
- package/dist/cjs/hijri/lib/fallbackLocaleData.d.ts +5 -0
- package/dist/cjs/hijri/lib/fallbackLocaleData.js +111 -0
- package/dist/cjs/hijri/lib/format.d.ts +3 -0
- package/dist/cjs/hijri/lib/format.js +149 -0
- package/dist/cjs/hijri/lib/getMonth.d.ts +1 -0
- package/dist/cjs/hijri/lib/getMonth.js +7 -0
- package/dist/cjs/hijri/lib/getYear.d.ts +1 -0
- package/dist/cjs/hijri/lib/getYear.js +7 -0
- package/dist/cjs/hijri/lib/index.d.ts +17 -0
- package/dist/cjs/hijri/lib/index.js +33 -0
- package/dist/cjs/hijri/lib/isSameMonth.d.ts +1 -0
- package/dist/cjs/hijri/lib/isSameMonth.js +10 -0
- package/dist/cjs/hijri/lib/isSameYear.d.ts +1 -0
- package/dist/cjs/hijri/lib/isSameYear.js +9 -0
- package/dist/cjs/hijri/lib/newDate.d.ts +1 -0
- package/dist/cjs/hijri/lib/newDate.js +7 -0
- package/dist/cjs/hijri/lib/setMonth.d.ts +1 -0
- package/dist/cjs/hijri/lib/setMonth.js +27 -0
- package/dist/cjs/hijri/lib/setYear.d.ts +1 -0
- package/dist/cjs/hijri/lib/setYear.js +15 -0
- package/dist/cjs/hijri/lib/startOfMonth.d.ts +1 -0
- package/dist/cjs/hijri/lib/startOfMonth.js +12 -0
- package/dist/cjs/hijri/lib/startOfYear.d.ts +1 -0
- package/dist/cjs/hijri/lib/startOfYear.js +12 -0
- package/dist/cjs/hijri/utils/conversion.d.ts +5 -0
- package/dist/cjs/hijri/utils/conversion.js +40 -0
- package/dist/cjs/hijri/utils/daysInMonth.d.ts +1 -0
- package/dist/cjs/hijri/utils/daysInMonth.js +24 -0
- package/dist/cjs/hijri/utils/range.d.ts +21 -0
- package/dist/cjs/hijri/utils/range.js +104 -0
- package/dist/cjs/hijri/utils/types.d.ts +5 -0
- package/dist/cjs/hijri/utils/types.js +2 -0
- package/dist/cjs/selection/useRange.js +22 -4
- package/dist/cjs/types/props.d.ts +27 -3
- package/dist/esm/DayPicker.js +1 -1
- package/dist/esm/UI.d.ts +21 -14
- package/dist/esm/UI.js +2 -2
- package/dist/esm/hijri/index.d.ts +28 -0
- package/dist/esm/hijri/index.js +55 -0
- package/dist/esm/hijri/lib/addMonths.d.ts +1 -0
- package/dist/esm/hijri/lib/addMonths.js +6 -0
- package/dist/esm/hijri/lib/addYears.d.ts +1 -0
- package/dist/esm/hijri/lib/addYears.js +6 -0
- package/dist/esm/hijri/lib/differenceInCalendarMonths.d.ts +1 -0
- package/dist/esm/hijri/lib/differenceInCalendarMonths.js +7 -0
- package/dist/esm/hijri/lib/eachMonthOfInterval.d.ts +2 -0
- package/dist/esm/hijri/lib/eachMonthOfInterval.js +26 -0
- package/dist/esm/hijri/lib/eachYearOfInterval.d.ts +2 -0
- package/dist/esm/hijri/lib/eachYearOfInterval.js +16 -0
- package/dist/esm/hijri/lib/endOfMonth.d.ts +1 -0
- package/dist/esm/hijri/lib/endOfMonth.js +11 -0
- package/dist/esm/hijri/lib/endOfYear.d.ts +1 -0
- package/dist/esm/hijri/lib/endOfYear.js +11 -0
- package/dist/esm/hijri/lib/fallbackLocaleData.d.ts +5 -0
- package/dist/esm/hijri/lib/fallbackLocaleData.js +105 -0
- package/dist/esm/hijri/lib/format.d.ts +3 -0
- package/dist/esm/hijri/lib/format.js +146 -0
- package/dist/esm/hijri/lib/getMonth.d.ts +1 -0
- package/dist/esm/hijri/lib/getMonth.js +4 -0
- package/dist/esm/hijri/lib/getYear.d.ts +1 -0
- package/dist/esm/hijri/lib/getYear.js +4 -0
- package/dist/esm/hijri/lib/index.d.ts +17 -0
- package/dist/esm/hijri/lib/index.js +17 -0
- package/dist/esm/hijri/lib/isSameMonth.d.ts +1 -0
- package/dist/esm/hijri/lib/isSameMonth.js +7 -0
- package/dist/esm/hijri/lib/isSameYear.d.ts +1 -0
- package/dist/esm/hijri/lib/isSameYear.js +6 -0
- package/dist/esm/hijri/lib/newDate.d.ts +1 -0
- package/dist/esm/hijri/lib/newDate.js +4 -0
- package/dist/esm/hijri/lib/setMonth.d.ts +1 -0
- package/dist/esm/hijri/lib/setMonth.js +24 -0
- package/dist/esm/hijri/lib/setYear.d.ts +1 -0
- package/dist/esm/hijri/lib/setYear.js +12 -0
- package/dist/esm/hijri/lib/startOfMonth.d.ts +1 -0
- package/dist/esm/hijri/lib/startOfMonth.js +9 -0
- package/dist/esm/hijri/lib/startOfYear.d.ts +1 -0
- package/dist/esm/hijri/lib/startOfYear.js +9 -0
- package/dist/esm/hijri/utils/conversion.d.ts +5 -0
- package/dist/esm/hijri/utils/conversion.js +36 -0
- package/dist/esm/hijri/utils/daysInMonth.d.ts +1 -0
- package/dist/esm/hijri/utils/daysInMonth.js +21 -0
- package/dist/esm/hijri/utils/range.d.ts +21 -0
- package/dist/esm/hijri/utils/range.js +96 -0
- package/dist/esm/hijri/utils/types.d.ts +5 -0
- package/dist/esm/hijri/utils/types.js +1 -0
- package/dist/esm/selection/useRange.js +22 -4
- package/dist/esm/types/props.d.ts +27 -3
- package/hijri.d.ts +1 -0
- package/hijri.js +2 -0
- package/package.json +24 -11
package/dist/esm/DayPicker.js
CHANGED
|
@@ -243,7 +243,7 @@ export function DayPicker(initialProps) {
|
|
|
243
243
|
formatters,
|
|
244
244
|
};
|
|
245
245
|
return (React.createElement(dayPickerContext.Provider, { value: contextValue },
|
|
246
|
-
React.createElement(components.Root, { rootRef: props.animate ? rootElRef : undefined, className: className, style: style, dir: props.dir, id: props.id, lang: props.lang, nonce: props.nonce, title: props.title, role: props.role, "aria-label": props["aria-label"], "aria-labelledby": props["aria-labelledby"], ...dataAttributes },
|
|
246
|
+
React.createElement(components.Root, { rootRef: props.animate ? rootElRef : undefined, className: className, style: style, dir: props.dir, id: props.id, lang: props.lang ?? locale.code, nonce: props.nonce, title: props.title, role: props.role, "aria-label": props["aria-label"], "aria-labelledby": props["aria-labelledby"], ...dataAttributes },
|
|
247
247
|
React.createElement(components.Months, { className: classNames[UI.Months], style: styles?.[UI.Months] },
|
|
248
248
|
!props.hideNavigation && !navLayout && (React.createElement(components.Nav, { "data-animated-nav": props.animate ? "true" : undefined, className: classNames[UI.Nav], style: styles?.[UI.Nav], "aria-label": labelNav(), onPreviousClick: handlePreviousClick, onNextClick: handleNextClick, previousMonth: previousMonth, nextMonth: nextMonth })),
|
|
249
249
|
months.map((calendarMonth, displayIndex) => {
|
package/dist/esm/UI.d.ts
CHANGED
|
@@ -80,8 +80,8 @@ export declare enum DayFlag {
|
|
|
80
80
|
today = "today"
|
|
81
81
|
}
|
|
82
82
|
/**
|
|
83
|
-
* Enum representing selection states that can be applied to the
|
|
84
|
-
* element in selection mode.
|
|
83
|
+
* Enum representing selection states that can be applied to the
|
|
84
|
+
* {@link UI | UI.Day} element in selection mode.
|
|
85
85
|
*/
|
|
86
86
|
export declare enum SelectionState {
|
|
87
87
|
/** The day is at the end of a selected range. */
|
|
@@ -131,14 +131,16 @@ export declare enum Animation {
|
|
|
131
131
|
export type DeprecatedUI<T extends CSSProperties | string> = {
|
|
132
132
|
/**
|
|
133
133
|
* This element was applied to the style of any button in DayPicker and it is
|
|
134
|
-
* replaced by {@link UI | UI.PreviousMonthButton} and
|
|
134
|
+
* replaced by {@link UI | UI.PreviousMonthButton} and
|
|
135
|
+
* {@link UI | UI.NextMonthButton}.
|
|
135
136
|
*
|
|
136
137
|
* @deprecated
|
|
137
138
|
*/
|
|
138
139
|
button: T;
|
|
139
140
|
/**
|
|
140
141
|
* This element was resetting the style of any button in DayPicker and it is
|
|
141
|
-
* replaced by {@link UI | UI.PreviousMonthButton} and
|
|
142
|
+
* replaced by {@link UI | UI.PreviousMonthButton} and
|
|
143
|
+
* {@link UI | UI.NextMonthButton}.
|
|
142
144
|
*
|
|
143
145
|
* @deprecated
|
|
144
146
|
*/
|
|
@@ -200,25 +202,29 @@ export type DeprecatedUI<T extends CSSProperties | string> = {
|
|
|
200
202
|
*/
|
|
201
203
|
day_outside: T;
|
|
202
204
|
/**
|
|
203
|
-
* This element has been renamed to
|
|
205
|
+
* This element has been renamed to
|
|
206
|
+
* {@link SelectionState | SelectionState.range_end}.
|
|
204
207
|
*
|
|
205
208
|
* @deprecated
|
|
206
209
|
*/
|
|
207
210
|
day_range_end: T;
|
|
208
211
|
/**
|
|
209
|
-
* This element has been renamed to
|
|
212
|
+
* This element has been renamed to
|
|
213
|
+
* {@link SelectionState | SelectionState.range_middle}.
|
|
210
214
|
*
|
|
211
215
|
* @deprecated
|
|
212
216
|
*/
|
|
213
217
|
day_range_middle: T;
|
|
214
218
|
/**
|
|
215
|
-
* This element has been renamed to
|
|
219
|
+
* This element has been renamed to
|
|
220
|
+
* {@link SelectionState | SelectionState.range_start}.
|
|
216
221
|
*
|
|
217
222
|
* @deprecated
|
|
218
223
|
*/
|
|
219
224
|
day_range_start: T;
|
|
220
225
|
/**
|
|
221
|
-
* This element has been renamed to
|
|
226
|
+
* This element has been renamed to
|
|
227
|
+
* {@link SelectionState | SelectionState.selected}.
|
|
222
228
|
*
|
|
223
229
|
* @deprecated
|
|
224
230
|
*/
|
|
@@ -230,8 +236,8 @@ export type DeprecatedUI<T extends CSSProperties | string> = {
|
|
|
230
236
|
*/
|
|
231
237
|
day_today: T;
|
|
232
238
|
/**
|
|
233
|
-
* This element has been removed. The dropdown icon is now
|
|
234
|
-
* inside a {@link UI | UI.CaptionLabel}.
|
|
239
|
+
* This element has been removed. The dropdown icon is now
|
|
240
|
+
* {@link UI | UI.Chevron} inside a {@link UI | UI.CaptionLabel}.
|
|
235
241
|
*
|
|
236
242
|
* @deprecated
|
|
237
243
|
*/
|
|
@@ -293,8 +299,9 @@ export type DeprecatedUI<T extends CSSProperties | string> = {
|
|
|
293
299
|
*/
|
|
294
300
|
nav_button_previous: T;
|
|
295
301
|
/**
|
|
296
|
-
* This element has been removed. The dropdown icon is now
|
|
297
|
-
*
|
|
302
|
+
* This element has been removed. The dropdown icon is now
|
|
303
|
+
* {@link UI | UI.Chevron} inside a {@link UI | UI.NextMonthButton} or a
|
|
304
|
+
* {@link UI | UI.PreviousMonthButton}.
|
|
298
305
|
*
|
|
299
306
|
* @deprecated
|
|
300
307
|
*/
|
|
@@ -318,8 +325,8 @@ export type DeprecatedUI<T extends CSSProperties | string> = {
|
|
|
318
325
|
*/
|
|
319
326
|
tbody: T;
|
|
320
327
|
/**
|
|
321
|
-
* This element has been removed. The {@link UI | UI.Footer} is now a single
|
|
322
|
-
* below the months.
|
|
328
|
+
* This element has been removed. The {@link UI | UI.Footer} is now a single
|
|
329
|
+
* element below the months.
|
|
323
330
|
*
|
|
324
331
|
* @deprecated
|
|
325
332
|
*/
|
package/dist/esm/UI.js
CHANGED
|
@@ -81,8 +81,8 @@ export var DayFlag;
|
|
|
81
81
|
DayFlag["today"] = "today";
|
|
82
82
|
})(DayFlag || (DayFlag = {}));
|
|
83
83
|
/**
|
|
84
|
-
* Enum representing selection states that can be applied to the
|
|
85
|
-
* element in selection mode.
|
|
84
|
+
* Enum representing selection states that can be applied to the
|
|
85
|
+
* {@link UI | UI.Day} element in selection mode.
|
|
86
86
|
*/
|
|
87
87
|
export var SelectionState;
|
|
88
88
|
(function (SelectionState) {
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { Locale } from "date-fns";
|
|
2
|
+
import React from "react";
|
|
3
|
+
import { DateLib, type DateLibOptions } from "../index.js";
|
|
4
|
+
import type { DayPickerProps } from "../types/props.js";
|
|
5
|
+
/**
|
|
6
|
+
* Render the Hijri (Umm al-Qura) calendar.
|
|
7
|
+
*
|
|
8
|
+
* Defaults:
|
|
9
|
+
*
|
|
10
|
+
* - `locale`: `ar-SA`
|
|
11
|
+
* - `dir`: `rtl`
|
|
12
|
+
* - `numerals`: `arab`
|
|
13
|
+
* - `startMonth`: `1924-08-01`
|
|
14
|
+
* - `endMonth`: `2077-11-16`
|
|
15
|
+
*
|
|
16
|
+
* Out-of-range date props are clamped to the supported Umm al-Qura conversion
|
|
17
|
+
* range, preventing runtime conversion errors.
|
|
18
|
+
*/
|
|
19
|
+
export declare function DayPicker(props: DayPickerProps & {
|
|
20
|
+
locale?: Locale;
|
|
21
|
+
dir?: DayPickerProps["dir"];
|
|
22
|
+
numerals?: DayPickerProps["numerals"];
|
|
23
|
+
dateLib?: DayPickerProps["dateLib"];
|
|
24
|
+
}): React.JSX.Element;
|
|
25
|
+
/** Returns the date library used in the Hijri calendar. */
|
|
26
|
+
export declare const getDateLib: (options?: DateLibOptions) => DateLib;
|
|
27
|
+
export { arSA } from "../locale/ar-SA.js";
|
|
28
|
+
export { enUS } from "../locale/en-US.js";
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { DateLib, DayPicker as DayPickerComponent, } from "../index.js";
|
|
3
|
+
import { arSA } from "../locale/ar-SA.js";
|
|
4
|
+
import * as hijriDateLib from "./lib/index.js";
|
|
5
|
+
import { clampGregorianDate, GREGORIAN_MAX_DATE, GREGORIAN_MIN_DATE, } from "./utils/range.js";
|
|
6
|
+
function clampDateProp(date) {
|
|
7
|
+
if (!date) {
|
|
8
|
+
return undefined;
|
|
9
|
+
}
|
|
10
|
+
return clampGregorianDate(date);
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Render the Hijri (Umm al-Qura) calendar.
|
|
14
|
+
*
|
|
15
|
+
* Defaults:
|
|
16
|
+
*
|
|
17
|
+
* - `locale`: `ar-SA`
|
|
18
|
+
* - `dir`: `rtl`
|
|
19
|
+
* - `numerals`: `arab`
|
|
20
|
+
* - `startMonth`: `1924-08-01`
|
|
21
|
+
* - `endMonth`: `2077-11-16`
|
|
22
|
+
*
|
|
23
|
+
* Out-of-range date props are clamped to the supported Umm al-Qura conversion
|
|
24
|
+
* range, preventing runtime conversion errors.
|
|
25
|
+
*/
|
|
26
|
+
export function DayPicker(props) {
|
|
27
|
+
const { dateLib: dateLibProp, ...dayPickerProps } = props;
|
|
28
|
+
const hasStartBound = props.startMonth !== undefined ||
|
|
29
|
+
props.fromMonth !== undefined ||
|
|
30
|
+
props.fromYear !== undefined;
|
|
31
|
+
const hasEndBound = props.endMonth !== undefined ||
|
|
32
|
+
props.toMonth !== undefined ||
|
|
33
|
+
props.toYear !== undefined;
|
|
34
|
+
const clampedProps = {
|
|
35
|
+
...dayPickerProps,
|
|
36
|
+
month: clampDateProp(props.month),
|
|
37
|
+
defaultMonth: clampDateProp(props.defaultMonth),
|
|
38
|
+
today: clampDateProp(props.today),
|
|
39
|
+
startMonth: hasStartBound
|
|
40
|
+
? clampDateProp(props.startMonth)
|
|
41
|
+
: new Date(GREGORIAN_MIN_DATE),
|
|
42
|
+
endMonth: hasEndBound
|
|
43
|
+
? clampDateProp(props.endMonth)
|
|
44
|
+
: new Date(GREGORIAN_MAX_DATE),
|
|
45
|
+
fromMonth: clampDateProp(props.fromMonth),
|
|
46
|
+
toMonth: clampDateProp(props.toMonth),
|
|
47
|
+
};
|
|
48
|
+
return (React.createElement(DayPickerComponent, { ...clampedProps, locale: props.locale ?? arSA, numerals: props.numerals ?? "arab", dir: props.dir ?? "rtl", dateLib: { ...hijriDateLib, ...dateLibProp } }));
|
|
49
|
+
}
|
|
50
|
+
/** Returns the date library used in the Hijri calendar. */
|
|
51
|
+
export const getDateLib = (options) => {
|
|
52
|
+
return new DateLib(options, hijriDateLib);
|
|
53
|
+
};
|
|
54
|
+
export { arSA } from "../locale/ar-SA.js";
|
|
55
|
+
export { enUS } from "../locale/en-US.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function addMonths(date: Date, amount: number): Date;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function addYears(date: Date, amount: number): Date;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function differenceInCalendarMonths(dateLeft: Date, dateRight: Date): number;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { toHijriDate } from "../utils/conversion.js";
|
|
2
|
+
export function differenceInCalendarMonths(dateLeft, dateRight) {
|
|
3
|
+
const hijriLeft = toHijriDate(dateLeft);
|
|
4
|
+
const hijriRight = toHijriDate(dateRight);
|
|
5
|
+
return ((hijriLeft.year - hijriRight.year) * 12 +
|
|
6
|
+
(hijriLeft.monthIndex - hijriRight.monthIndex));
|
|
7
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { toDate } from "date-fns";
|
|
2
|
+
import { toGregorianDate, toHijriDate } from "../utils/conversion.js";
|
|
3
|
+
export function eachMonthOfInterval(interval) {
|
|
4
|
+
const start = toDate(interval.start);
|
|
5
|
+
const end = toDate(interval.end);
|
|
6
|
+
if (end.getTime() < start.getTime()) {
|
|
7
|
+
throw new RangeError("Invalid interval");
|
|
8
|
+
}
|
|
9
|
+
const startDate = toHijriDate(start);
|
|
10
|
+
const endDate = toHijriDate(end);
|
|
11
|
+
const months = [];
|
|
12
|
+
let currentYear = startDate.year;
|
|
13
|
+
let currentMonth = startDate.monthIndex;
|
|
14
|
+
const endYear = endDate.year;
|
|
15
|
+
const endMonth = endDate.monthIndex;
|
|
16
|
+
while (currentYear < endYear ||
|
|
17
|
+
(currentYear === endYear && currentMonth <= endMonth)) {
|
|
18
|
+
months.push(toGregorianDate({ year: currentYear, monthIndex: currentMonth, day: 1 }));
|
|
19
|
+
currentMonth += 1;
|
|
20
|
+
if (currentMonth > 11) {
|
|
21
|
+
currentMonth = 0;
|
|
22
|
+
currentYear += 1;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return months;
|
|
26
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { toDate } from "date-fns";
|
|
2
|
+
import { toGregorianDate, toHijriDate } from "../utils/conversion.js";
|
|
3
|
+
export function eachYearOfInterval(interval) {
|
|
4
|
+
const start = toDate(interval.start);
|
|
5
|
+
const end = toDate(interval.end);
|
|
6
|
+
if (end.getTime() < start.getTime()) {
|
|
7
|
+
return [];
|
|
8
|
+
}
|
|
9
|
+
const startYear = toHijriDate(start).year;
|
|
10
|
+
const endYear = toHijriDate(end).year;
|
|
11
|
+
const years = [];
|
|
12
|
+
for (let year = startYear; year <= endYear; year += 1) {
|
|
13
|
+
years.push(toGregorianDate({ year, monthIndex: 0, day: 1 }));
|
|
14
|
+
}
|
|
15
|
+
return years;
|
|
16
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function endOfMonth(date: Date): Date;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { toGregorianDate, toHijriDate } from "../utils/conversion.js";
|
|
2
|
+
import { getDaysInMonth } from "../utils/daysInMonth.js";
|
|
3
|
+
export function endOfMonth(date) {
|
|
4
|
+
const hijri = toHijriDate(date);
|
|
5
|
+
const day = getDaysInMonth(hijri.year, hijri.monthIndex);
|
|
6
|
+
return toGregorianDate({
|
|
7
|
+
year: hijri.year,
|
|
8
|
+
monthIndex: hijri.monthIndex,
|
|
9
|
+
day,
|
|
10
|
+
});
|
|
11
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function endOfYear(date: Date): Date;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { toGregorianDate, toHijriDate } from "../utils/conversion.js";
|
|
2
|
+
import { getDaysInMonth } from "../utils/daysInMonth.js";
|
|
3
|
+
export function endOfYear(date) {
|
|
4
|
+
const hijri = toHijriDate(date);
|
|
5
|
+
const day = getDaysInMonth(hijri.year, 11);
|
|
6
|
+
return toGregorianDate({
|
|
7
|
+
year: hijri.year,
|
|
8
|
+
monthIndex: 11,
|
|
9
|
+
day,
|
|
10
|
+
});
|
|
11
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export type FallbackLocaleCode = "ar" | "en";
|
|
2
|
+
export type IntlNameWidth = "long" | "short" | "narrow";
|
|
3
|
+
export declare const getFallbackLocaleCode: (localeCode: string) => FallbackLocaleCode;
|
|
4
|
+
export declare const getFallbackMonthName: (date: Date, localeCode: string, width: IntlNameWidth) => string;
|
|
5
|
+
export declare const getFallbackWeekdayName: (date: Date, localeCode: string, width: IntlNameWidth) => string;
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { toHijriDate } from "../utils/conversion.js";
|
|
2
|
+
const fallbackMonthNames = {
|
|
3
|
+
en: {
|
|
4
|
+
long: [
|
|
5
|
+
"Muharram",
|
|
6
|
+
"Safar",
|
|
7
|
+
"Rabi I",
|
|
8
|
+
"Rabi II",
|
|
9
|
+
"Jumada I",
|
|
10
|
+
"Jumada II",
|
|
11
|
+
"Rajab",
|
|
12
|
+
"Shaban",
|
|
13
|
+
"Ramadan",
|
|
14
|
+
"Shawwal",
|
|
15
|
+
"Dhu al-Qadah",
|
|
16
|
+
"Dhu al-Hijjah",
|
|
17
|
+
],
|
|
18
|
+
short: [
|
|
19
|
+
"Muh",
|
|
20
|
+
"Saf",
|
|
21
|
+
"Rab-I",
|
|
22
|
+
"Rab-II",
|
|
23
|
+
"Jum-I",
|
|
24
|
+
"Jum-II",
|
|
25
|
+
"Raj",
|
|
26
|
+
"Sha",
|
|
27
|
+
"Ram",
|
|
28
|
+
"Shw",
|
|
29
|
+
"Dhu-Q",
|
|
30
|
+
"Dhu-H",
|
|
31
|
+
],
|
|
32
|
+
narrow: ["M", "S", "R", "R", "J", "J", "R", "S", "R", "S", "D", "D"],
|
|
33
|
+
},
|
|
34
|
+
ar: {
|
|
35
|
+
long: [
|
|
36
|
+
"محرم",
|
|
37
|
+
"صفر",
|
|
38
|
+
"ربيع الأول",
|
|
39
|
+
"ربيع الآخر",
|
|
40
|
+
"جمادى الأولى",
|
|
41
|
+
"جمادى الآخرة",
|
|
42
|
+
"رجب",
|
|
43
|
+
"شعبان",
|
|
44
|
+
"رمضان",
|
|
45
|
+
"شوال",
|
|
46
|
+
"ذو القعدة",
|
|
47
|
+
"ذو الحجة",
|
|
48
|
+
],
|
|
49
|
+
short: [
|
|
50
|
+
"محرم",
|
|
51
|
+
"صفر",
|
|
52
|
+
"ربيع ١",
|
|
53
|
+
"ربيع ٢",
|
|
54
|
+
"جمادى ١",
|
|
55
|
+
"جمادى ٢",
|
|
56
|
+
"رجب",
|
|
57
|
+
"شعبان",
|
|
58
|
+
"رمضان",
|
|
59
|
+
"شوال",
|
|
60
|
+
"ذو القعدة",
|
|
61
|
+
"ذو الحجة",
|
|
62
|
+
],
|
|
63
|
+
narrow: ["م", "ص", "ر", "ر", "ج", "ج", "ر", "ش", "ر", "ش", "ذ", "ذ"],
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
const fallbackWeekdayNames = {
|
|
67
|
+
en: {
|
|
68
|
+
long: [
|
|
69
|
+
"Sunday",
|
|
70
|
+
"Monday",
|
|
71
|
+
"Tuesday",
|
|
72
|
+
"Wednesday",
|
|
73
|
+
"Thursday",
|
|
74
|
+
"Friday",
|
|
75
|
+
"Saturday",
|
|
76
|
+
],
|
|
77
|
+
short: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
|
|
78
|
+
narrow: ["S", "M", "T", "W", "T", "F", "S"],
|
|
79
|
+
},
|
|
80
|
+
ar: {
|
|
81
|
+
long: [
|
|
82
|
+
"الأحد",
|
|
83
|
+
"الاثنين",
|
|
84
|
+
"الثلاثاء",
|
|
85
|
+
"الأربعاء",
|
|
86
|
+
"الخميس",
|
|
87
|
+
"الجمعة",
|
|
88
|
+
"السبت",
|
|
89
|
+
],
|
|
90
|
+
short: ["أحد", "اثن", "ثلا", "أرب", "خمي", "جمع", "سبت"],
|
|
91
|
+
narrow: ["ح", "ن", "ث", "ر", "خ", "ج", "س"],
|
|
92
|
+
},
|
|
93
|
+
};
|
|
94
|
+
export const getFallbackLocaleCode = (localeCode) => {
|
|
95
|
+
return localeCode.toLowerCase().startsWith("ar") ? "ar" : "en";
|
|
96
|
+
};
|
|
97
|
+
export const getFallbackMonthName = (date, localeCode, width) => {
|
|
98
|
+
const hijri = toHijriDate(date);
|
|
99
|
+
const locale = getFallbackLocaleCode(localeCode);
|
|
100
|
+
return fallbackMonthNames[locale][width][hijri.monthIndex];
|
|
101
|
+
};
|
|
102
|
+
export const getFallbackWeekdayName = (date, localeCode, width) => {
|
|
103
|
+
const locale = getFallbackLocaleCode(localeCode);
|
|
104
|
+
return fallbackWeekdayNames[locale][width][date.getDay()];
|
|
105
|
+
};
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { toHijriDate } from "../utils/conversion.js";
|
|
2
|
+
import { clampGregorianDate, getGregorianDateParts } from "../utils/range.js";
|
|
3
|
+
import { getFallbackMonthName, getFallbackWeekdayName, } from "./fallbackLocaleData.js";
|
|
4
|
+
const DEFAULT_LOCALE_CODE = "ar-SA";
|
|
5
|
+
const BASE_NUMBERING_SYSTEM = "latn";
|
|
6
|
+
const UMM_AL_QURA_CALENDAR = "islamic-umalqura";
|
|
7
|
+
const getLocaleCode = (options) => {
|
|
8
|
+
return options?.locale?.code ?? DEFAULT_LOCALE_CODE;
|
|
9
|
+
};
|
|
10
|
+
const formatWithUmmAlQura = (date, localeCode, options) => {
|
|
11
|
+
try {
|
|
12
|
+
return new Intl.DateTimeFormat(localeCode, {
|
|
13
|
+
...options,
|
|
14
|
+
calendar: UMM_AL_QURA_CALENDAR,
|
|
15
|
+
numberingSystem: BASE_NUMBERING_SYSTEM,
|
|
16
|
+
}).format(date);
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
return undefined;
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
const formatNumber = (value) => {
|
|
23
|
+
return value.toString();
|
|
24
|
+
};
|
|
25
|
+
const formatPaddedNumber = (value) => {
|
|
26
|
+
return formatNumber(value).padStart(2, "0");
|
|
27
|
+
};
|
|
28
|
+
const formatMonthName = (date, localeCode, width) => {
|
|
29
|
+
const formatted = formatWithUmmAlQura(date, localeCode, {
|
|
30
|
+
month: width,
|
|
31
|
+
});
|
|
32
|
+
return formatted ?? getFallbackMonthName(date, localeCode, width);
|
|
33
|
+
};
|
|
34
|
+
const formatWeekdayName = (date, localeCode, width) => {
|
|
35
|
+
const formatted = formatWithUmmAlQura(date, localeCode, {
|
|
36
|
+
weekday: width,
|
|
37
|
+
});
|
|
38
|
+
return formatted ?? getFallbackWeekdayName(date, localeCode, width);
|
|
39
|
+
};
|
|
40
|
+
const formatDateStyle = (date, localeCode, style) => {
|
|
41
|
+
const formatted = formatWithUmmAlQura(date, localeCode, {
|
|
42
|
+
dateStyle: style,
|
|
43
|
+
});
|
|
44
|
+
if (formatted) {
|
|
45
|
+
return formatted;
|
|
46
|
+
}
|
|
47
|
+
const hijri = toHijriDate(date);
|
|
48
|
+
const monthName = getFallbackMonthName(date, localeCode, "long");
|
|
49
|
+
switch (style) {
|
|
50
|
+
case "full":
|
|
51
|
+
return `${getFallbackWeekdayName(date, localeCode, "long")}, ${monthName} ${hijri.day}, ${hijri.year}`;
|
|
52
|
+
case "long":
|
|
53
|
+
return `${monthName} ${hijri.day}, ${hijri.year}`;
|
|
54
|
+
case "medium":
|
|
55
|
+
return `${formatPaddedNumber(hijri.day)} ${monthName} ${hijri.year}`;
|
|
56
|
+
case "short":
|
|
57
|
+
return `${hijri.monthIndex + 1}/${hijri.day}/${hijri.year}`;
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
const buildTimeFormat = (date, localeCode, formatStr) => {
|
|
61
|
+
const hour12 = formatStr.includes("a");
|
|
62
|
+
const formatted = formatWithUmmAlQura(date, localeCode, {
|
|
63
|
+
hour: "numeric",
|
|
64
|
+
minute: "numeric",
|
|
65
|
+
hour12,
|
|
66
|
+
});
|
|
67
|
+
if (formatted) {
|
|
68
|
+
return formatted;
|
|
69
|
+
}
|
|
70
|
+
try {
|
|
71
|
+
return new Intl.DateTimeFormat(localeCode, {
|
|
72
|
+
hour: "numeric",
|
|
73
|
+
minute: "numeric",
|
|
74
|
+
hour12,
|
|
75
|
+
numberingSystem: BASE_NUMBERING_SYSTEM,
|
|
76
|
+
}).format(date);
|
|
77
|
+
}
|
|
78
|
+
catch {
|
|
79
|
+
const minutes = formatPaddedNumber(date.getMinutes());
|
|
80
|
+
if (hour12) {
|
|
81
|
+
const hour = date.getHours() % 12 || 12;
|
|
82
|
+
const period = date.getHours() >= 12 ? "PM" : "AM";
|
|
83
|
+
return `${hour}:${minutes} ${period}`;
|
|
84
|
+
}
|
|
85
|
+
return `${formatNumber(date.getHours())}:${minutes}`;
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
/** Hijri calendar formatting override. */
|
|
89
|
+
export function format(date, formatStr, options) {
|
|
90
|
+
const extendedOptions = options;
|
|
91
|
+
const localeCode = getLocaleCode(extendedOptions);
|
|
92
|
+
const hijri = toHijriDate(date);
|
|
93
|
+
const gregorian = getGregorianDateParts(date);
|
|
94
|
+
const isOutOfRange = clampGregorianDate(date) !== date;
|
|
95
|
+
const numericDate = isOutOfRange
|
|
96
|
+
? {
|
|
97
|
+
year: gregorian.year,
|
|
98
|
+
monthIndex: gregorian.month - 1,
|
|
99
|
+
day: gregorian.day,
|
|
100
|
+
}
|
|
101
|
+
: hijri;
|
|
102
|
+
switch (formatStr) {
|
|
103
|
+
case "LLLL y":
|
|
104
|
+
case "LLLL yyyy":
|
|
105
|
+
return `${formatMonthName(date, localeCode, "long")} ${formatNumber(numericDate.year)}`;
|
|
106
|
+
case "LLLL":
|
|
107
|
+
return formatMonthName(date, localeCode, "long");
|
|
108
|
+
case "LLL":
|
|
109
|
+
return formatMonthName(date, localeCode, "short");
|
|
110
|
+
case "PPP":
|
|
111
|
+
return formatDateStyle(date, localeCode, "long");
|
|
112
|
+
case "PPPP":
|
|
113
|
+
return formatDateStyle(date, localeCode, "full");
|
|
114
|
+
case "PP":
|
|
115
|
+
return formatDateStyle(date, localeCode, "medium");
|
|
116
|
+
case "P":
|
|
117
|
+
return formatDateStyle(date, localeCode, "short");
|
|
118
|
+
case "cccc":
|
|
119
|
+
return formatWeekdayName(date, localeCode, "long");
|
|
120
|
+
case "ccc":
|
|
121
|
+
return formatWeekdayName(date, localeCode, "short");
|
|
122
|
+
case "ccccc":
|
|
123
|
+
case "cccccc":
|
|
124
|
+
return formatWeekdayName(date, localeCode, "narrow");
|
|
125
|
+
case "yyyy":
|
|
126
|
+
case "y":
|
|
127
|
+
return formatNumber(numericDate.year);
|
|
128
|
+
case "yyyy-MM":
|
|
129
|
+
return `${formatNumber(numericDate.year)}-${formatPaddedNumber(numericDate.monthIndex + 1)}`;
|
|
130
|
+
case "yyyy-MM-dd":
|
|
131
|
+
return `${formatNumber(numericDate.year)}-${formatPaddedNumber(numericDate.monthIndex + 1)}-${formatPaddedNumber(numericDate.day)}`;
|
|
132
|
+
case "MM":
|
|
133
|
+
return formatPaddedNumber(numericDate.monthIndex + 1);
|
|
134
|
+
case "M":
|
|
135
|
+
return formatNumber(numericDate.monthIndex + 1);
|
|
136
|
+
case "dd":
|
|
137
|
+
return formatPaddedNumber(numericDate.day);
|
|
138
|
+
case "d":
|
|
139
|
+
return formatNumber(numericDate.day);
|
|
140
|
+
default:
|
|
141
|
+
if (/[Hh]/.test(formatStr) && /m/.test(formatStr)) {
|
|
142
|
+
return buildTimeFormat(date, localeCode, formatStr);
|
|
143
|
+
}
|
|
144
|
+
return formatDateStyle(date, localeCode, "medium");
|
|
145
|
+
}
|
|
146
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getMonth(date: Date): number;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getYear(date: Date): number;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export * from "./addMonths.js";
|
|
2
|
+
export * from "./addYears.js";
|
|
3
|
+
export * from "./differenceInCalendarMonths.js";
|
|
4
|
+
export * from "./eachMonthOfInterval.js";
|
|
5
|
+
export * from "./eachYearOfInterval.js";
|
|
6
|
+
export * from "./endOfMonth.js";
|
|
7
|
+
export * from "./endOfYear.js";
|
|
8
|
+
export * from "./format.js";
|
|
9
|
+
export * from "./getMonth.js";
|
|
10
|
+
export * from "./getYear.js";
|
|
11
|
+
export * from "./isSameMonth.js";
|
|
12
|
+
export * from "./isSameYear.js";
|
|
13
|
+
export * from "./newDate.js";
|
|
14
|
+
export * from "./setMonth.js";
|
|
15
|
+
export * from "./setYear.js";
|
|
16
|
+
export * from "./startOfMonth.js";
|
|
17
|
+
export * from "./startOfYear.js";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export * from "./addMonths.js";
|
|
2
|
+
export * from "./addYears.js";
|
|
3
|
+
export * from "./differenceInCalendarMonths.js";
|
|
4
|
+
export * from "./eachMonthOfInterval.js";
|
|
5
|
+
export * from "./eachYearOfInterval.js";
|
|
6
|
+
export * from "./endOfMonth.js";
|
|
7
|
+
export * from "./endOfYear.js";
|
|
8
|
+
export * from "./format.js";
|
|
9
|
+
export * from "./getMonth.js";
|
|
10
|
+
export * from "./getYear.js";
|
|
11
|
+
export * from "./isSameMonth.js";
|
|
12
|
+
export * from "./isSameYear.js";
|
|
13
|
+
export * from "./newDate.js";
|
|
14
|
+
export * from "./setMonth.js";
|
|
15
|
+
export * from "./setYear.js";
|
|
16
|
+
export * from "./startOfMonth.js";
|
|
17
|
+
export * from "./startOfYear.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function isSameMonth(dateLeft: Date, dateRight: Date): boolean;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { toHijriDate } from "../utils/conversion.js";
|
|
2
|
+
export function isSameMonth(dateLeft, dateRight) {
|
|
3
|
+
const hijriLeft = toHijriDate(dateLeft);
|
|
4
|
+
const hijriRight = toHijriDate(dateRight);
|
|
5
|
+
return (hijriLeft.year === hijriRight.year &&
|
|
6
|
+
hijriLeft.monthIndex === hijriRight.monthIndex);
|
|
7
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function isSameYear(dateLeft: Date, dateRight: Date): boolean;
|