@internationalized/date 3.7.0 → 3.8.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/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/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
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
// Portions of the code in this file are based on code from ICU.
|
|
14
14
|
// Original licensing can be found in the NOTICE file in the root directory of this source tree.
|
|
15
15
|
|
|
16
|
-
import {AnyCalendarDate, Calendar} from '../types';
|
|
16
|
+
import {AnyCalendarDate, Calendar, CalendarIdentifier} from '../types';
|
|
17
17
|
import {CalendarDate} from '../CalendarDate';
|
|
18
18
|
import {Mutable} from '../utils';
|
|
19
19
|
|
|
@@ -66,7 +66,7 @@ function getDaysInMonth(year: number, month: number) {
|
|
|
66
66
|
* on whether it is a leap year. Two eras are supported: 'AA' and 'AM'.
|
|
67
67
|
*/
|
|
68
68
|
export class EthiopicCalendar implements Calendar {
|
|
69
|
-
identifier = 'ethiopic';
|
|
69
|
+
identifier: CalendarIdentifier = 'ethiopic';
|
|
70
70
|
|
|
71
71
|
fromJulianDay(jd: number): CalendarDate {
|
|
72
72
|
let [year, month, day] = julianDayToCE(ETHIOPIC_EPOCH, jd);
|
|
@@ -79,7 +79,7 @@ export class EthiopicCalendar implements Calendar {
|
|
|
79
79
|
return new CalendarDate(this, era, year, month, day);
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
-
toJulianDay(date: AnyCalendarDate) {
|
|
82
|
+
toJulianDay(date: AnyCalendarDate): number {
|
|
83
83
|
let year = date.year;
|
|
84
84
|
if (date.era === 'AA') {
|
|
85
85
|
year -= AMETE_MIHRET_DELTA;
|
|
@@ -107,7 +107,7 @@ export class EthiopicCalendar implements Calendar {
|
|
|
107
107
|
return date.era === 'AA' ? 9999 : 9991;
|
|
108
108
|
}
|
|
109
109
|
|
|
110
|
-
getEras() {
|
|
110
|
+
getEras(): string[] {
|
|
111
111
|
return ['AA', 'AM'];
|
|
112
112
|
}
|
|
113
113
|
}
|
|
@@ -117,7 +117,7 @@ export class EthiopicCalendar implements Calendar {
|
|
|
117
117
|
* except years were measured from a different epoch. Only one era is supported: 'AA'.
|
|
118
118
|
*/
|
|
119
119
|
export class EthiopicAmeteAlemCalendar extends EthiopicCalendar {
|
|
120
|
-
identifier = 'ethioaa'; // also known as 'ethiopic-amete-alem' in ICU
|
|
120
|
+
identifier: CalendarIdentifier = 'ethioaa'; // also known as 'ethiopic-amete-alem' in ICU
|
|
121
121
|
|
|
122
122
|
fromJulianDay(jd: number): CalendarDate {
|
|
123
123
|
let [year, month, day] = julianDayToCE(ETHIOPIC_EPOCH, jd);
|
|
@@ -125,7 +125,7 @@ export class EthiopicAmeteAlemCalendar extends EthiopicCalendar {
|
|
|
125
125
|
return new CalendarDate(this, 'AA', year, month, day);
|
|
126
126
|
}
|
|
127
127
|
|
|
128
|
-
getEras() {
|
|
128
|
+
getEras(): string[] {
|
|
129
129
|
return ['AA'];
|
|
130
130
|
}
|
|
131
131
|
|
|
@@ -141,7 +141,7 @@ export class EthiopicAmeteAlemCalendar extends EthiopicCalendar {
|
|
|
141
141
|
* on whether it is a leap year. Two eras are supported: 'BCE' and 'CE'.
|
|
142
142
|
*/
|
|
143
143
|
export class CopticCalendar extends EthiopicCalendar {
|
|
144
|
-
identifier = 'coptic';
|
|
144
|
+
identifier: CalendarIdentifier = 'coptic';
|
|
145
145
|
|
|
146
146
|
fromJulianDay(jd: number): CalendarDate {
|
|
147
147
|
let [year, month, day] = julianDayToCE(COPTIC_EPOCH, jd);
|
|
@@ -154,7 +154,7 @@ export class CopticCalendar extends EthiopicCalendar {
|
|
|
154
154
|
return new CalendarDate(this, era, year, month, day);
|
|
155
155
|
}
|
|
156
156
|
|
|
157
|
-
toJulianDay(date: AnyCalendarDate) {
|
|
157
|
+
toJulianDay(date: AnyCalendarDate): number {
|
|
158
158
|
let year = date.year;
|
|
159
159
|
if (date.era === 'BCE') {
|
|
160
160
|
year = 1 - year;
|
|
@@ -176,14 +176,14 @@ export class CopticCalendar extends EthiopicCalendar {
|
|
|
176
176
|
return date.era === 'BCE';
|
|
177
177
|
}
|
|
178
178
|
|
|
179
|
-
balanceDate(date: Mutable<AnyCalendarDate>) {
|
|
179
|
+
balanceDate(date: Mutable<AnyCalendarDate>): void {
|
|
180
180
|
if (date.year <= 0) {
|
|
181
181
|
date.era = date.era === 'BCE' ? 'CE' : 'BCE';
|
|
182
182
|
date.year = 1 - date.year;
|
|
183
183
|
}
|
|
184
184
|
}
|
|
185
185
|
|
|
186
|
-
getEras() {
|
|
186
|
+
getEras(): string[] {
|
|
187
187
|
return ['BCE', 'CE'];
|
|
188
188
|
}
|
|
189
189
|
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
// Portions of the code in this file are based on code from ICU.
|
|
14
14
|
// Original licensing can be found in the NOTICE file in the root directory of this source tree.
|
|
15
15
|
|
|
16
|
-
import {AnyCalendarDate, Calendar} from '../types';
|
|
16
|
+
import {AnyCalendarDate, Calendar, CalendarIdentifier} from '../types';
|
|
17
17
|
import {CalendarDate} from '../CalendarDate';
|
|
18
18
|
import {mod, Mutable} from '../utils';
|
|
19
19
|
|
|
@@ -68,7 +68,7 @@ const daysInMonth = {
|
|
|
68
68
|
* Years always contain 12 months, and 365 or 366 days depending on whether it is a leap year.
|
|
69
69
|
*/
|
|
70
70
|
export class GregorianCalendar implements Calendar {
|
|
71
|
-
identifier = 'gregory';
|
|
71
|
+
identifier: CalendarIdentifier = 'gregory';
|
|
72
72
|
|
|
73
73
|
fromJulianDay(jd: number): CalendarDate {
|
|
74
74
|
let jd0 = jd;
|
|
@@ -118,7 +118,7 @@ export class GregorianCalendar implements Calendar {
|
|
|
118
118
|
return 9999;
|
|
119
119
|
}
|
|
120
120
|
|
|
121
|
-
getEras() {
|
|
121
|
+
getEras(): string[] {
|
|
122
122
|
return ['BC', 'AD'];
|
|
123
123
|
}
|
|
124
124
|
|
|
@@ -126,7 +126,7 @@ export class GregorianCalendar implements Calendar {
|
|
|
126
126
|
return date.era === 'BC';
|
|
127
127
|
}
|
|
128
128
|
|
|
129
|
-
balanceDate(date: Mutable<AnyCalendarDate>) {
|
|
129
|
+
balanceDate(date: Mutable<AnyCalendarDate>): void {
|
|
130
130
|
if (date.year <= 0) {
|
|
131
131
|
date.era = date.era === 'BC' ? 'AD' : 'BC';
|
|
132
132
|
date.year = 1 - date.year;
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
// Portions of the code in this file are based on code from ICU.
|
|
14
14
|
// Original licensing can be found in the NOTICE file in the root directory of this source tree.
|
|
15
15
|
|
|
16
|
-
import {AnyCalendarDate, Calendar} from '../types';
|
|
16
|
+
import {AnyCalendarDate, Calendar, CalendarIdentifier} from '../types';
|
|
17
17
|
import {CalendarDate} from '../CalendarDate';
|
|
18
18
|
import {mod, Mutable} from '../utils';
|
|
19
19
|
|
|
@@ -128,7 +128,7 @@ function getDaysInMonth(year: number, month: number): number {
|
|
|
128
128
|
* In leap years, an extra month is inserted at month 6.
|
|
129
129
|
*/
|
|
130
130
|
export class HebrewCalendar implements Calendar {
|
|
131
|
-
identifier = 'hebrew';
|
|
131
|
+
identifier: CalendarIdentifier = 'hebrew';
|
|
132
132
|
|
|
133
133
|
fromJulianDay(jd: number): CalendarDate {
|
|
134
134
|
let d = jd - HEBREW_EPOCH;
|
|
@@ -159,7 +159,7 @@ export class HebrewCalendar implements Calendar {
|
|
|
159
159
|
return new CalendarDate(this, year, month, day);
|
|
160
160
|
}
|
|
161
161
|
|
|
162
|
-
toJulianDay(date: AnyCalendarDate) {
|
|
162
|
+
toJulianDay(date: AnyCalendarDate): number {
|
|
163
163
|
let jd = startOfYear(date.year);
|
|
164
164
|
for (let month = 1; month < date.month; month++) {
|
|
165
165
|
jd += getDaysInMonth(date.year, month);
|
|
@@ -185,11 +185,11 @@ export class HebrewCalendar implements Calendar {
|
|
|
185
185
|
return 9999;
|
|
186
186
|
}
|
|
187
187
|
|
|
188
|
-
getEras() {
|
|
188
|
+
getEras(): string[] {
|
|
189
189
|
return ['AM'];
|
|
190
190
|
}
|
|
191
191
|
|
|
192
|
-
balanceYearMonth(date: Mutable<AnyCalendarDate>, previousDate: AnyCalendarDate) {
|
|
192
|
+
balanceYearMonth(date: Mutable<AnyCalendarDate>, previousDate: AnyCalendarDate): void {
|
|
193
193
|
// Keep date in the same month when switching between leap years and non leap years
|
|
194
194
|
if (previousDate.year !== date.year) {
|
|
195
195
|
if (isLeapYear(previousDate.year) && !isLeapYear(date.year) && previousDate.month > 6) {
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
// Portions of the code in this file are based on code from ICU.
|
|
14
14
|
// Original licensing can be found in the NOTICE file in the root directory of this source tree.
|
|
15
15
|
|
|
16
|
-
import {AnyCalendarDate} from '../types';
|
|
16
|
+
import {AnyCalendarDate, CalendarIdentifier} from '../types';
|
|
17
17
|
import {CalendarDate} from '../CalendarDate';
|
|
18
18
|
import {fromExtendedYear, GregorianCalendar, gregorianToJulianDay, isLeapYear} from './GregorianCalendar';
|
|
19
19
|
|
|
@@ -29,7 +29,7 @@ const INDIAN_YEAR_START = 80;
|
|
|
29
29
|
* in each year, with either 30 or 31 days. Only one era identifier is supported: 'saka'.
|
|
30
30
|
*/
|
|
31
31
|
export class IndianCalendar extends GregorianCalendar {
|
|
32
|
-
identifier = 'indian';
|
|
32
|
+
identifier: CalendarIdentifier = 'indian';
|
|
33
33
|
|
|
34
34
|
fromJulianDay(jd: number): CalendarDate {
|
|
35
35
|
// Gregorian date for Julian day
|
|
@@ -75,7 +75,7 @@ export class IndianCalendar extends GregorianCalendar {
|
|
|
75
75
|
return new CalendarDate(this, indianYear, indianMonth, indianDay);
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
-
toJulianDay(date: AnyCalendarDate) {
|
|
78
|
+
toJulianDay(date: AnyCalendarDate): number {
|
|
79
79
|
let extendedYear = date.year + INDIAN_ERA_START;
|
|
80
80
|
let [era, year] = fromExtendedYear(extendedYear);
|
|
81
81
|
|
|
@@ -121,9 +121,9 @@ export class IndianCalendar extends GregorianCalendar {
|
|
|
121
121
|
return 9919;
|
|
122
122
|
}
|
|
123
123
|
|
|
124
|
-
getEras() {
|
|
124
|
+
getEras(): string[] {
|
|
125
125
|
return ['saka'];
|
|
126
126
|
}
|
|
127
127
|
|
|
128
|
-
balanceDate() {}
|
|
128
|
+
balanceDate(): void {}
|
|
129
129
|
}
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
// Portions of the code in this file are based on code from ICU.
|
|
14
14
|
// Original licensing can be found in the NOTICE file in the root directory of this source tree.
|
|
15
15
|
|
|
16
|
-
import {AnyCalendarDate, Calendar} from '../types';
|
|
16
|
+
import {AnyCalendarDate, Calendar, CalendarIdentifier} from '../types';
|
|
17
17
|
import {CalendarDate} from '../CalendarDate';
|
|
18
18
|
|
|
19
19
|
const CIVIL_EPOC = 1948440; // CE 622 July 16 Friday (Julian calendar) / CE 622 July 19 (Gregorian calendar)
|
|
@@ -50,13 +50,13 @@ function isLeapYear(year: number): boolean {
|
|
|
50
50
|
* Learn more about the available Islamic calendars [here](https://cldr.unicode.org/development/development-process/design-proposals/islamic-calendar-types).
|
|
51
51
|
*/
|
|
52
52
|
export class IslamicCivilCalendar implements Calendar {
|
|
53
|
-
identifier = 'islamic-civil';
|
|
53
|
+
identifier: CalendarIdentifier = 'islamic-civil';
|
|
54
54
|
|
|
55
55
|
fromJulianDay(jd: number): CalendarDate {
|
|
56
56
|
return julianDayToIslamic(this, CIVIL_EPOC, jd);
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
toJulianDay(date: AnyCalendarDate) {
|
|
59
|
+
toJulianDay(date: AnyCalendarDate): number {
|
|
60
60
|
return islamicToJulianDay(CIVIL_EPOC, date.year, date.month, date.day);
|
|
61
61
|
}
|
|
62
62
|
|
|
@@ -82,7 +82,7 @@ export class IslamicCivilCalendar implements Calendar {
|
|
|
82
82
|
return 9665;
|
|
83
83
|
}
|
|
84
84
|
|
|
85
|
-
getEras() {
|
|
85
|
+
getEras(): string[] {
|
|
86
86
|
return ['AH'];
|
|
87
87
|
}
|
|
88
88
|
}
|
|
@@ -95,13 +95,13 @@ export class IslamicCivilCalendar implements Calendar {
|
|
|
95
95
|
* Learn more about the available Islamic calendars [here](https://cldr.unicode.org/development/development-process/design-proposals/islamic-calendar-types).
|
|
96
96
|
*/
|
|
97
97
|
export class IslamicTabularCalendar extends IslamicCivilCalendar {
|
|
98
|
-
identifier = 'islamic-tbla';
|
|
98
|
+
identifier: CalendarIdentifier = 'islamic-tbla';
|
|
99
99
|
|
|
100
100
|
fromJulianDay(jd: number): CalendarDate {
|
|
101
101
|
return julianDayToIslamic(this, ASTRONOMICAL_EPOC, jd);
|
|
102
102
|
}
|
|
103
103
|
|
|
104
|
-
toJulianDay(date: AnyCalendarDate) {
|
|
104
|
+
toJulianDay(date: AnyCalendarDate): number {
|
|
105
105
|
return islamicToJulianDay(ASTRONOMICAL_EPOC, date.year, date.month, date.day);
|
|
106
106
|
}
|
|
107
107
|
}
|
|
@@ -145,7 +145,7 @@ function umalquraYearLength(year: number): number {
|
|
|
145
145
|
* Learn more about the available Islamic calendars [here](https://cldr.unicode.org/development/development-process/design-proposals/islamic-calendar-types).
|
|
146
146
|
*/
|
|
147
147
|
export class IslamicUmalquraCalendar extends IslamicCivilCalendar {
|
|
148
|
-
identifier = 'islamic-umalqura';
|
|
148
|
+
identifier: CalendarIdentifier = 'islamic-umalqura';
|
|
149
149
|
|
|
150
150
|
constructor() {
|
|
151
151
|
super();
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
// Portions of the code in this file are based on code from the TC39 Temporal proposal.
|
|
14
14
|
// Original licensing can be found in the NOTICE file in the root directory of this source tree.
|
|
15
15
|
|
|
16
|
-
import {AnyCalendarDate} from '../types';
|
|
16
|
+
import {AnyCalendarDate, CalendarIdentifier} from '../types';
|
|
17
17
|
import {CalendarDate} from '../CalendarDate';
|
|
18
18
|
import {GregorianCalendar} from './GregorianCalendar';
|
|
19
19
|
import {Mutable} from '../utils';
|
|
@@ -70,7 +70,7 @@ function toGregorian(date: AnyCalendarDate) {
|
|
|
70
70
|
* Note that eras before 1868 (Gregorian) are not currently supported by this implementation.
|
|
71
71
|
*/
|
|
72
72
|
export class JapaneseCalendar extends GregorianCalendar {
|
|
73
|
-
identifier = 'japanese';
|
|
73
|
+
identifier: CalendarIdentifier = 'japanese';
|
|
74
74
|
|
|
75
75
|
fromJulianDay(jd: number): CalendarDate {
|
|
76
76
|
let date = super.fromJulianDay(jd);
|
|
@@ -85,11 +85,11 @@ export class JapaneseCalendar extends GregorianCalendar {
|
|
|
85
85
|
);
|
|
86
86
|
}
|
|
87
87
|
|
|
88
|
-
toJulianDay(date: AnyCalendarDate) {
|
|
88
|
+
toJulianDay(date: AnyCalendarDate): number {
|
|
89
89
|
return super.toJulianDay(toGregorian(date));
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
-
balanceDate(date: Mutable<AnyCalendarDate>) {
|
|
92
|
+
balanceDate(date: Mutable<AnyCalendarDate>): void {
|
|
93
93
|
let gregorianDate = toGregorian(date);
|
|
94
94
|
let era = findEraFromGregorianDate(gregorianDate);
|
|
95
95
|
|
|
@@ -102,7 +102,7 @@ export class JapaneseCalendar extends GregorianCalendar {
|
|
|
102
102
|
this.constrainDate(date);
|
|
103
103
|
}
|
|
104
104
|
|
|
105
|
-
constrainDate(date: Mutable<AnyCalendarDate>) {
|
|
105
|
+
constrainDate(date: Mutable<AnyCalendarDate>): void {
|
|
106
106
|
let idx = ERA_NAMES.indexOf(date.era);
|
|
107
107
|
let end = ERA_END_DATES[idx];
|
|
108
108
|
if (end != null) {
|
|
@@ -131,7 +131,7 @@ export class JapaneseCalendar extends GregorianCalendar {
|
|
|
131
131
|
}
|
|
132
132
|
}
|
|
133
133
|
|
|
134
|
-
getEras() {
|
|
134
|
+
getEras(): string[] {
|
|
135
135
|
return ERA_NAMES;
|
|
136
136
|
}
|
|
137
137
|
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
// Portions of the code in this file are based on code from ICU.
|
|
14
14
|
// Original licensing can be found in the NOTICE file in the root directory of this source tree.
|
|
15
15
|
|
|
16
|
-
import {AnyCalendarDate, Calendar} from '../types';
|
|
16
|
+
import {AnyCalendarDate, Calendar, CalendarIdentifier} from '../types';
|
|
17
17
|
import {CalendarDate} from '../CalendarDate';
|
|
18
18
|
import {mod} from '../utils';
|
|
19
19
|
|
|
@@ -42,7 +42,7 @@ const MONTH_START = [
|
|
|
42
42
|
* around the March equinox.
|
|
43
43
|
*/
|
|
44
44
|
export class PersianCalendar implements Calendar {
|
|
45
|
-
identifier = 'persian';
|
|
45
|
+
identifier: CalendarIdentifier = 'persian';
|
|
46
46
|
|
|
47
47
|
fromJulianDay(jd: number): CalendarDate {
|
|
48
48
|
let daysSinceEpoch = jd - PERSIAN_EPOCH;
|
|
@@ -80,7 +80,7 @@ export class PersianCalendar implements Calendar {
|
|
|
80
80
|
return isLeapYear ? 30 : 29;
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
-
getEras() {
|
|
83
|
+
getEras(): string[] {
|
|
84
84
|
return ['AP'];
|
|
85
85
|
}
|
|
86
86
|
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
// Portions of the code in this file are based on code from ICU.
|
|
14
14
|
// Original licensing can be found in the NOTICE file in the root directory of this source tree.
|
|
15
15
|
|
|
16
|
-
import {AnyCalendarDate} from '../types';
|
|
16
|
+
import {AnyCalendarDate, CalendarIdentifier} from '../types';
|
|
17
17
|
import {CalendarDate} from '../CalendarDate';
|
|
18
18
|
import {fromExtendedYear, getExtendedYear, GregorianCalendar} from './GregorianCalendar';
|
|
19
19
|
import {Mutable} from '../utils';
|
|
@@ -41,7 +41,7 @@ function gregorianToTaiwan(year: number): [string, number] {
|
|
|
41
41
|
* 'before_minguo' and 'minguo'.
|
|
42
42
|
*/
|
|
43
43
|
export class TaiwanCalendar extends GregorianCalendar {
|
|
44
|
-
identifier = 'roc'; // Republic of China
|
|
44
|
+
identifier: CalendarIdentifier = 'roc'; // Republic of China
|
|
45
45
|
|
|
46
46
|
fromJulianDay(jd: number): CalendarDate {
|
|
47
47
|
let date = super.fromJulianDay(jd);
|
|
@@ -50,15 +50,15 @@ export class TaiwanCalendar extends GregorianCalendar {
|
|
|
50
50
|
return new CalendarDate(this, era, year, date.month, date.day);
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
toJulianDay(date: AnyCalendarDate) {
|
|
53
|
+
toJulianDay(date: AnyCalendarDate): number {
|
|
54
54
|
return super.toJulianDay(toGregorian(date));
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
-
getEras() {
|
|
57
|
+
getEras(): string[] {
|
|
58
58
|
return ['before_minguo', 'minguo'];
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
-
balanceDate(date: Mutable<AnyCalendarDate>) {
|
|
61
|
+
balanceDate(date: Mutable<AnyCalendarDate>): void {
|
|
62
62
|
let [era, year] = gregorianToTaiwan(gregorianYear(date));
|
|
63
63
|
date.era = era;
|
|
64
64
|
date.year = year;
|
package/src/conversion.ts
CHANGED
|
@@ -17,16 +17,16 @@ import {AnyCalendarDate, AnyDateTime, AnyTime, Calendar, DateFields, Disambiguat
|
|
|
17
17
|
import {CalendarDate, CalendarDateTime, Time, ZonedDateTime} from './CalendarDate';
|
|
18
18
|
import {constrain} from './manipulation';
|
|
19
19
|
import {getExtendedYear, GregorianCalendar} from './calendars/GregorianCalendar';
|
|
20
|
-
import {getLocalTimeZone} from './queries';
|
|
20
|
+
import {getLocalTimeZone, isEqualCalendar} from './queries';
|
|
21
21
|
import {Mutable} from './utils';
|
|
22
22
|
|
|
23
|
-
export function epochFromDate(date: AnyDateTime) {
|
|
23
|
+
export function epochFromDate(date: AnyDateTime): number {
|
|
24
24
|
date = toCalendar(date, new GregorianCalendar());
|
|
25
25
|
let year = getExtendedYear(date.era, date.year);
|
|
26
26
|
return epochFromParts(year, date.month, date.day, date.hour, date.minute, date.second, date.millisecond);
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
function epochFromParts(year: number, month: number, day: number, hour: number, minute: number, second: number, millisecond: number) {
|
|
29
|
+
function epochFromParts(year: number, month: number, day: number, hour: number, minute: number, second: number, millisecond: number): number {
|
|
30
30
|
// Note: Date.UTC() interprets one and two-digit years as being in the
|
|
31
31
|
// 20th century, so don't use it
|
|
32
32
|
let date = new Date();
|
|
@@ -35,7 +35,7 @@ function epochFromParts(year: number, month: number, day: number, hour: number,
|
|
|
35
35
|
return date.getTime();
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
export function getTimeZoneOffset(ms: number, timeZone: string) {
|
|
38
|
+
export function getTimeZoneOffset(ms: number, timeZone: string): number {
|
|
39
39
|
// Fast path for UTC.
|
|
40
40
|
if (timeZone === 'UTC') {
|
|
41
41
|
return 0;
|
|
@@ -260,7 +260,7 @@ export function toTime(dateTime: CalendarDateTime | ZonedDateTime): Time {
|
|
|
260
260
|
|
|
261
261
|
/** Converts a date from one calendar system to another. */
|
|
262
262
|
export function toCalendar<T extends AnyCalendarDate>(date: T, calendar: Calendar): T {
|
|
263
|
-
if (date.calendar
|
|
263
|
+
if (isEqualCalendar(date.calendar, calendar)) {
|
|
264
264
|
return date;
|
|
265
265
|
}
|
|
266
266
|
|
|
@@ -292,7 +292,7 @@ export function toZoned(date: CalendarDate | CalendarDateTime | ZonedDateTime, t
|
|
|
292
292
|
return fromAbsolute(ms, timeZone);
|
|
293
293
|
}
|
|
294
294
|
|
|
295
|
-
export function zonedToDate(date: ZonedDateTime) {
|
|
295
|
+
export function zonedToDate(date: ZonedDateTime): Date {
|
|
296
296
|
let ms = epochFromDate(date) - date.offset;
|
|
297
297
|
return new Date(ms);
|
|
298
298
|
}
|
package/src/createCalendar.ts
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
13
|
import {BuddhistCalendar} from './calendars/BuddhistCalendar';
|
|
14
|
-
import {Calendar} from './types';
|
|
14
|
+
import {Calendar, CalendarIdentifier} from './types';
|
|
15
15
|
import {CopticCalendar, EthiopicAmeteAlemCalendar, EthiopicCalendar} from './calendars/EthiopicCalendar';
|
|
16
16
|
import {GregorianCalendar} from './calendars/GregorianCalendar';
|
|
17
17
|
import {HebrewCalendar} from './calendars/HebrewCalendar';
|
|
@@ -22,7 +22,7 @@ import {PersianCalendar} from './calendars/PersianCalendar';
|
|
|
22
22
|
import {TaiwanCalendar} from './calendars/TaiwanCalendar';
|
|
23
23
|
|
|
24
24
|
/** Creates a `Calendar` instance from a Unicode calendar identifier string. */
|
|
25
|
-
export function createCalendar(name:
|
|
25
|
+
export function createCalendar(name: CalendarIdentifier): Calendar {
|
|
26
26
|
switch (name) {
|
|
27
27
|
case 'buddhist':
|
|
28
28
|
return new BuddhistCalendar();
|
package/src/index.ts
CHANGED
|
@@ -15,6 +15,7 @@ export type {
|
|
|
15
15
|
AnyTime,
|
|
16
16
|
AnyDateTime,
|
|
17
17
|
Calendar,
|
|
18
|
+
CalendarIdentifier,
|
|
18
19
|
DateDuration,
|
|
19
20
|
TimeDuration,
|
|
20
21
|
DateTimeDuration,
|
|
@@ -74,7 +75,8 @@ export {
|
|
|
74
75
|
minDate,
|
|
75
76
|
maxDate,
|
|
76
77
|
isWeekend,
|
|
77
|
-
isWeekday
|
|
78
|
+
isWeekday,
|
|
79
|
+
isEqualCalendar
|
|
78
80
|
} from './queries';
|
|
79
81
|
export {
|
|
80
82
|
parseDate,
|
package/src/manipulation.ts
CHANGED
|
@@ -21,7 +21,7 @@ const ONE_HOUR = 3600000;
|
|
|
21
21
|
export function add(date: CalendarDateTime, duration: DateTimeDuration): CalendarDateTime;
|
|
22
22
|
export function add(date: CalendarDate, duration: DateDuration): CalendarDate;
|
|
23
23
|
export function add(date: CalendarDate | CalendarDateTime, duration: DateTimeDuration): CalendarDate | CalendarDateTime;
|
|
24
|
-
export function add(date: CalendarDate | CalendarDateTime, duration: DateTimeDuration) {
|
|
24
|
+
export function add(date: CalendarDate | CalendarDateTime, duration: DateTimeDuration): Mutable<AnyCalendarDate | AnyDateTime> {
|
|
25
25
|
let mutableDate: Mutable<AnyCalendarDate | AnyDateTime> = date.copy();
|
|
26
26
|
let days = 'hour' in mutableDate ? addTimeFields(mutableDate, duration) : 0;
|
|
27
27
|
|
|
@@ -118,7 +118,7 @@ function constrainMonthDay(date: Mutable<AnyCalendarDate>) {
|
|
|
118
118
|
date.day = Math.max(1, Math.min(date.calendar.getDaysInMonth(date), date.day));
|
|
119
119
|
}
|
|
120
120
|
|
|
121
|
-
export function constrain(date: Mutable<AnyCalendarDate>) {
|
|
121
|
+
export function constrain(date: Mutable<AnyCalendarDate>): void {
|
|
122
122
|
if (date.calendar.constrainDate) {
|
|
123
123
|
date.calendar.constrainDate(date);
|
|
124
124
|
}
|
|
@@ -146,7 +146,7 @@ export function subtract(date: CalendarDate | CalendarDateTime, duration: DateTi
|
|
|
146
146
|
|
|
147
147
|
export function set(date: CalendarDateTime, fields: DateFields): CalendarDateTime;
|
|
148
148
|
export function set(date: CalendarDate, fields: DateFields): CalendarDate;
|
|
149
|
-
export function set(date: CalendarDate | CalendarDateTime, fields: DateFields) {
|
|
149
|
+
export function set(date: CalendarDate | CalendarDateTime, fields: DateFields): Mutable<AnyCalendarDate> {
|
|
150
150
|
let mutableDate: Mutable<AnyCalendarDate> = date.copy();
|
|
151
151
|
|
|
152
152
|
if (fields.era != null) {
|
|
@@ -171,7 +171,7 @@ export function set(date: CalendarDate | CalendarDateTime, fields: DateFields) {
|
|
|
171
171
|
|
|
172
172
|
export function setTime(value: CalendarDateTime, fields: TimeFields): CalendarDateTime;
|
|
173
173
|
export function setTime(value: Time, fields: TimeFields): Time;
|
|
174
|
-
export function setTime(value: Time | CalendarDateTime, fields: TimeFields) {
|
|
174
|
+
export function setTime(value: Time | CalendarDateTime, fields: TimeFields): Mutable<Time | CalendarDateTime> {
|
|
175
175
|
let mutableValue: Mutable<Time | CalendarDateTime> = value.copy();
|
|
176
176
|
|
|
177
177
|
if (fields.hour != null) {
|
|
@@ -210,7 +210,7 @@ function balanceTime(time: Mutable<AnyTime>): number {
|
|
|
210
210
|
return days;
|
|
211
211
|
}
|
|
212
212
|
|
|
213
|
-
export function constrainTime(time: Mutable<AnyTime>) {
|
|
213
|
+
export function constrainTime(time: Mutable<AnyTime>): void {
|
|
214
214
|
time.millisecond = Math.max(0, Math.min(time.millisecond, 1000));
|
|
215
215
|
time.second = Math.max(0, Math.min(time.second, 59));
|
|
216
216
|
time.minute = Math.max(0, Math.min(time.minute, 59));
|
|
@@ -245,7 +245,7 @@ export function subtractTime(time: Time, duration: TimeDuration): Time {
|
|
|
245
245
|
|
|
246
246
|
export function cycleDate(value: CalendarDateTime, field: DateField, amount: number, options?: CycleOptions): CalendarDateTime;
|
|
247
247
|
export function cycleDate(value: CalendarDate, field: DateField, amount: number, options?: CycleOptions): CalendarDate;
|
|
248
|
-
export function cycleDate(value: CalendarDate | CalendarDateTime, field: DateField, amount: number, options?: CycleOptions) {
|
|
248
|
+
export function cycleDate(value: CalendarDate | CalendarDateTime, field: DateField, amount: number, options?: CycleOptions): Mutable<CalendarDate | CalendarDateTime> {
|
|
249
249
|
let mutable: Mutable<CalendarDate | CalendarDateTime> = value.copy();
|
|
250
250
|
|
|
251
251
|
switch (field) {
|
|
@@ -300,7 +300,7 @@ export function cycleDate(value: CalendarDate | CalendarDateTime, field: DateFie
|
|
|
300
300
|
|
|
301
301
|
export function cycleTime(value: CalendarDateTime, field: TimeField, amount: number, options?: CycleTimeOptions): CalendarDateTime;
|
|
302
302
|
export function cycleTime(value: Time, field: TimeField, amount: number, options?: CycleTimeOptions): Time;
|
|
303
|
-
export function cycleTime(value: Time | CalendarDateTime, field: TimeField, amount: number, options?: CycleTimeOptions) {
|
|
303
|
+
export function cycleTime(value: Time | CalendarDateTime, field: TimeField, amount: number, options?: CycleTimeOptions): Mutable<Time | CalendarDateTime> {
|
|
304
304
|
let mutable: Mutable<Time | CalendarDateTime> = value.copy();
|
|
305
305
|
|
|
306
306
|
switch (field) {
|
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,
|