@internationalized/date 3.7.0 → 3.8.1
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/BuddhistCalendar.main.js.map +1 -1
- package/dist/BuddhistCalendar.module.js.map +1 -1
- package/dist/CalendarDate.main.js.map +1 -1
- package/dist/CalendarDate.module.js.map +1 -1
- package/dist/EthiopicCalendar.main.js.map +1 -1
- package/dist/EthiopicCalendar.module.js.map +1 -1
- package/dist/GregorianCalendar.main.js.map +1 -1
- package/dist/GregorianCalendar.module.js.map +1 -1
- package/dist/HebrewCalendar.main.js.map +1 -1
- package/dist/HebrewCalendar.module.js.map +1 -1
- package/dist/IndianCalendar.main.js.map +1 -1
- package/dist/IndianCalendar.module.js.map +1 -1
- package/dist/IslamicCalendar.main.js.map +1 -1
- package/dist/IslamicCalendar.module.js.map +1 -1
- package/dist/JapaneseCalendar.main.js.map +1 -1
- package/dist/JapaneseCalendar.module.js.map +1 -1
- package/dist/PersianCalendar.main.js.map +1 -1
- package/dist/PersianCalendar.module.js.map +1 -1
- package/dist/TaiwanCalendar.main.js.map +1 -1
- package/dist/TaiwanCalendar.module.js.map +1 -1
- package/dist/conversion.main.js +1 -1
- package/dist/conversion.main.js.map +1 -1
- package/dist/conversion.mjs +2 -2
- package/dist/conversion.module.js +2 -2
- package/dist/conversion.module.js.map +1 -1
- package/dist/createCalendar.main.js.map +1 -1
- package/dist/createCalendar.module.js.map +1 -1
- package/dist/import.mjs +2 -2
- package/dist/main.js +1 -0
- package/dist/main.js.map +1 -1
- package/dist/manipulation.main.js.map +1 -1
- package/dist/manipulation.module.js.map +1 -1
- package/dist/module.js +2 -2
- package/dist/module.js.map +1 -1
- package/dist/queries.main.js +9 -7
- package/dist/queries.main.js.map +1 -1
- package/dist/queries.mjs +9 -8
- package/dist/queries.module.js +9 -8
- package/dist/queries.module.js.map +1 -1
- package/dist/types.d.ts +31 -16
- package/dist/types.d.ts.map +1 -1
- package/dist/utils.main.js +1 -12
- package/dist/utils.main.js.map +1 -1
- package/dist/utils.mjs +2 -13
- package/dist/utils.module.js +2 -13
- package/dist/utils.module.js.map +1 -1
- package/package.json +2 -2
- package/src/CalendarDate.ts +14 -14
- package/src/calendars/BuddhistCalendar.ts +5 -5
- package/src/calendars/EthiopicCalendar.ts +10 -10
- package/src/calendars/GregorianCalendar.ts +4 -4
- package/src/calendars/HebrewCalendar.ts +5 -5
- package/src/calendars/IndianCalendar.ts +5 -5
- package/src/calendars/IslamicCalendar.ts +7 -7
- package/src/calendars/JapaneseCalendar.ts +6 -6
- package/src/calendars/PersianCalendar.ts +3 -3
- package/src/calendars/TaiwanCalendar.ts +5 -5
- package/src/conversion.ts +6 -6
- package/src/createCalendar.ts +2 -2
- package/src/index.ts +3 -1
- package/src/manipulation.ts +7 -7
- package/src/queries.ts +11 -10
- package/src/types.ts +17 -2
- package/src/utils.ts +0 -18
package/src/queries.ts
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* governing permissions and limitations under the License.
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
-
import {AnyCalendarDate, AnyTime} from './types';
|
|
13
|
+
import {AnyCalendarDate, AnyTime, Calendar} from './types';
|
|
14
14
|
import {CalendarDate, CalendarDateTime, ZonedDateTime} from './CalendarDate';
|
|
15
15
|
import {fromAbsolute, toAbsolute, toCalendar, toCalendarDate} from './conversion';
|
|
16
16
|
import {weekStartData} from './weekStartData';
|
|
@@ -42,21 +42,22 @@ export function isSameYear(a: DateValue, b: DateValue): boolean {
|
|
|
42
42
|
|
|
43
43
|
/** Returns whether the given dates occur on the same day, and are of the same calendar system. */
|
|
44
44
|
export function isEqualDay(a: DateValue, b: DateValue): boolean {
|
|
45
|
-
return a.calendar
|
|
45
|
+
return isEqualCalendar(a.calendar, b.calendar) && isSameDay(a, b);
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
/** Returns whether the given dates occur in the same month, and are of the same calendar system. */
|
|
49
49
|
export function isEqualMonth(a: DateValue, b: DateValue): boolean {
|
|
50
|
-
a
|
|
51
|
-
b = startOfMonth(b);
|
|
52
|
-
return a.calendar.identifier === b.calendar.identifier && a.era === b.era && a.year === b.year && a.month === b.month;
|
|
50
|
+
return isEqualCalendar(a.calendar, b.calendar) && isSameMonth(a, b);
|
|
53
51
|
}
|
|
54
52
|
|
|
55
53
|
/** Returns whether the given dates occur in the same year, and are of the same calendar system. */
|
|
56
54
|
export function isEqualYear(a: DateValue, b: DateValue): boolean {
|
|
57
|
-
a
|
|
58
|
-
|
|
59
|
-
|
|
55
|
+
return isEqualCalendar(a.calendar, b.calendar) && isSameYear(a, b);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** Returns whether two calendars are the same. */
|
|
59
|
+
export function isEqualCalendar(a: Calendar, b: Calendar): boolean {
|
|
60
|
+
return a.isEqual?.(b) ?? b.isEqual?.(a) ?? a.identifier === b.identifier;
|
|
60
61
|
}
|
|
61
62
|
|
|
62
63
|
/** Returns whether the date is today in the given time zone. */
|
|
@@ -177,7 +178,7 @@ export function endOfYear(date: DateValue): DateValue {
|
|
|
177
178
|
return endOfMonth(date.add({months: date.calendar.getMonthsInYear(date) - date.month}));
|
|
178
179
|
}
|
|
179
180
|
|
|
180
|
-
export function getMinimumMonthInYear(date: AnyCalendarDate) {
|
|
181
|
+
export function getMinimumMonthInYear(date: AnyCalendarDate): number {
|
|
181
182
|
if (date.calendar.getMinimumMonthInYear) {
|
|
182
183
|
return date.calendar.getMinimumMonthInYear(date);
|
|
183
184
|
}
|
|
@@ -185,7 +186,7 @@ export function getMinimumMonthInYear(date: AnyCalendarDate) {
|
|
|
185
186
|
return 1;
|
|
186
187
|
}
|
|
187
188
|
|
|
188
|
-
export function getMinimumDayInMonth(date: AnyCalendarDate) {
|
|
189
|
+
export function getMinimumDayInMonth(date: AnyCalendarDate): number {
|
|
189
190
|
if (date.calendar.getMinimumDayInMonth) {
|
|
190
191
|
return date.calendar.getMinimumDayInMonth(date);
|
|
191
192
|
}
|
package/src/types.ts
CHANGED
|
@@ -34,14 +34,19 @@ export interface AnyTime {
|
|
|
34
34
|
/** An interface that is compatible with any object with both date and time fields. */
|
|
35
35
|
export interface AnyDateTime extends AnyCalendarDate, AnyTime {}
|
|
36
36
|
|
|
37
|
+
export type CalendarIdentifier = 'gregory' | 'buddhist' | 'chinese' | 'coptic' | 'dangi' | 'ethioaa' | 'ethiopic' | 'hebrew' | 'indian' | 'islamic' | 'islamic-umalqura' | 'islamic-tbla' | 'islamic-civil' | 'islamic-rgsa' | 'iso8601' | 'japanese' | 'persian' | 'roc';
|
|
38
|
+
|
|
37
39
|
/**
|
|
38
40
|
* The Calendar interface represents a calendar system, including information
|
|
39
41
|
* about how days, months, years, and eras are organized, and methods to perform
|
|
40
42
|
* arithmetic on dates.
|
|
41
43
|
*/
|
|
42
44
|
export interface Calendar {
|
|
43
|
-
/**
|
|
44
|
-
|
|
45
|
+
/**
|
|
46
|
+
* A string identifier for the calendar, as defined by Unicode CLDR.
|
|
47
|
+
* See [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/supportedValuesOf#supported_calendar_types).
|
|
48
|
+
*/
|
|
49
|
+
identifier: CalendarIdentifier,
|
|
45
50
|
|
|
46
51
|
/** Creates a CalendarDate in this calendar from the given Julian day number. */
|
|
47
52
|
fromJulianDay(jd: number): CalendarDate,
|
|
@@ -69,6 +74,16 @@ export interface Calendar {
|
|
|
69
74
|
* eras may begin in the middle of a month.
|
|
70
75
|
*/
|
|
71
76
|
getMinimumDayInMonth?(date: AnyCalendarDate): number,
|
|
77
|
+
/**
|
|
78
|
+
* Returns a date that is the first day of the month for the given date.
|
|
79
|
+
* This is used to determine the month that the given date falls in, if
|
|
80
|
+
* the calendar has months that do not align with the standard calendar months
|
|
81
|
+
* (e.g. fiscal calendars).
|
|
82
|
+
*/
|
|
83
|
+
getFormattableMonth?(date: AnyCalendarDate): CalendarDate,
|
|
84
|
+
|
|
85
|
+
/** Returns whether the given calendar is the same as this calendar. */
|
|
86
|
+
isEqual?(calendar: Calendar): boolean,
|
|
72
87
|
|
|
73
88
|
/** @private */
|
|
74
89
|
balanceDate?(date: AnyCalendarDate): void,
|
package/src/utils.ts
CHANGED
|
@@ -10,8 +10,6 @@
|
|
|
10
10
|
* governing permissions and limitations under the License.
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
-
import {CalendarDate, CalendarDateTime} from './CalendarDate';
|
|
14
|
-
|
|
15
13
|
export type Mutable<T> = {
|
|
16
14
|
-readonly[P in keyof T]: T[P]
|
|
17
15
|
};
|
|
@@ -19,19 +17,3 @@ export type Mutable<T> = {
|
|
|
19
17
|
export function mod(amount: number, numerator: number): number {
|
|
20
18
|
return amount - numerator * Math.floor(amount / numerator);
|
|
21
19
|
}
|
|
22
|
-
|
|
23
|
-
export function copy(date: CalendarDate): Mutable<CalendarDate> {
|
|
24
|
-
if (date.era) {
|
|
25
|
-
return new CalendarDate(date.calendar, date.era, date.year, date.month, date.day);
|
|
26
|
-
} else {
|
|
27
|
-
return new CalendarDate(date.calendar, date.year, date.month, date.day);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export function copyDateTime(date: CalendarDateTime): Mutable<CalendarDateTime> {
|
|
32
|
-
if (date.era) {
|
|
33
|
-
return new CalendarDateTime(date.calendar, date.era, date.year, date.month, date.day, date.hour, date.minute, date.second, date.millisecond);
|
|
34
|
-
} else {
|
|
35
|
-
return new CalendarDateTime(date.calendar, date.year, date.month, date.day, date.hour, date.minute, date.second);
|
|
36
|
-
}
|
|
37
|
-
}
|