@internationalized/date 3.12.1 → 3.12.2
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/index.cjs.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/private/CalendarDate.cjs +40 -10
- package/dist/private/CalendarDate.cjs.map +1 -1
- package/dist/private/CalendarDate.js +40 -10
- package/dist/private/CalendarDate.js.map +1 -1
- package/dist/private/CalendarDate.mjs +40 -10
- package/dist/private/CalendarDate.mjs.map +1 -1
- package/dist/private/DateFormatter.cjs +4 -1
- package/dist/private/DateFormatter.cjs.map +1 -1
- package/dist/private/DateFormatter.js +4 -1
- package/dist/private/DateFormatter.js.map +1 -1
- package/dist/private/DateFormatter.mjs +4 -1
- package/dist/private/DateFormatter.mjs.map +1 -1
- package/dist/private/calendars/BuddhistCalendar.cjs.map +1 -1
- package/dist/private/calendars/BuddhistCalendar.js.map +1 -1
- package/dist/private/calendars/BuddhistCalendar.mjs.map +1 -1
- package/dist/private/calendars/EthiopicCalendar.cjs +5 -5
- package/dist/private/calendars/EthiopicCalendar.cjs.map +1 -1
- package/dist/private/calendars/EthiopicCalendar.js +5 -5
- package/dist/private/calendars/EthiopicCalendar.js.map +1 -1
- package/dist/private/calendars/EthiopicCalendar.mjs +5 -5
- package/dist/private/calendars/EthiopicCalendar.mjs.map +1 -1
- package/dist/private/calendars/GregorianCalendar.cjs.map +1 -1
- package/dist/private/calendars/GregorianCalendar.js.map +1 -1
- package/dist/private/calendars/GregorianCalendar.mjs.map +1 -1
- package/dist/private/calendars/HebrewCalendar.cjs.map +1 -1
- package/dist/private/calendars/HebrewCalendar.js.map +1 -1
- package/dist/private/calendars/HebrewCalendar.mjs.map +1 -1
- package/dist/private/calendars/IndianCalendar.cjs.map +1 -1
- package/dist/private/calendars/IndianCalendar.js.map +1 -1
- package/dist/private/calendars/IndianCalendar.mjs.map +1 -1
- package/dist/private/calendars/IslamicCalendar.cjs.map +1 -1
- package/dist/private/calendars/IslamicCalendar.js.map +1 -1
- package/dist/private/calendars/IslamicCalendar.mjs.map +1 -1
- package/dist/private/calendars/JapaneseCalendar.cjs.map +1 -1
- package/dist/private/calendars/JapaneseCalendar.js.map +1 -1
- package/dist/private/calendars/JapaneseCalendar.mjs.map +1 -1
- package/dist/private/calendars/PersianCalendar.cjs.map +1 -1
- package/dist/private/calendars/PersianCalendar.js.map +1 -1
- package/dist/private/calendars/PersianCalendar.mjs.map +1 -1
- package/dist/private/calendars/TaiwanCalendar.cjs.map +1 -1
- package/dist/private/calendars/TaiwanCalendar.js.map +1 -1
- package/dist/private/calendars/TaiwanCalendar.mjs.map +1 -1
- package/dist/private/conversion.cjs.map +1 -1
- package/dist/private/conversion.js.map +1 -1
- package/dist/private/conversion.mjs.map +1 -1
- package/dist/private/createCalendar.cjs.map +1 -1
- package/dist/private/createCalendar.js.map +1 -1
- package/dist/private/createCalendar.mjs.map +1 -1
- package/dist/private/manipulation.cjs.map +1 -1
- package/dist/private/manipulation.js.map +1 -1
- package/dist/private/manipulation.mjs.map +1 -1
- package/dist/private/queries.cjs.map +1 -1
- package/dist/private/queries.js.map +1 -1
- package/dist/private/queries.mjs.map +1 -1
- package/dist/private/string.cjs.map +1 -1
- package/dist/private/string.js.map +1 -1
- package/dist/private/string.mjs.map +1 -1
- package/dist/private/utils.cjs.map +1 -1
- package/dist/private/utils.js.map +1 -1
- package/dist/private/utils.mjs.map +1 -1
- package/dist/types/src/CalendarDate.d.ts +40 -10
- package/dist/types/src/DateFormatter.d.ts +4 -1
- package/dist/types/src/calendars/GregorianCalendar.d.ts +3 -2
- package/dist/types/src/calendars/IslamicCalendar.d.ts +18 -15
- package/dist/types/src/calendars/JapaneseCalendar.d.ts +4 -3
- package/dist/types/src/conversion.d.ts +8 -5
- package/dist/types/src/queries.d.ts +8 -2
- package/dist/types/src/string.d.ts +5 -4
- package/dist/types/src/types.d.ts +7 -3
- package/package.json +16 -16
- package/src/CalendarDate.ts +213 -35
- package/src/DateFormatter.ts +36 -16
- package/src/calendars/BuddhistCalendar.ts +1 -6
- package/src/calendars/EthiopicCalendar.ts +6 -5
- package/src/calendars/GregorianCalendar.ts +11 -4
- package/src/calendars/HebrewCalendar.ts +8 -4
- package/src/calendars/IndianCalendar.ts +8 -3
- package/src/calendars/IslamicCalendar.ts +40 -25
- package/src/calendars/JapaneseCalendar.ts +18 -10
- package/src/calendars/PersianCalendar.ts +2 -4
- package/src/calendars/TaiwanCalendar.ts +2 -9
- package/src/conversion.ts +98 -25
- package/src/createCalendar.ts +10 -2
- package/src/index.ts +10 -2
- package/src/manipulation.ts +133 -30
- package/src/queries.ts +56 -12
- package/src/string.ts +52 -25
- package/src/types.ts +73 -51
- package/src/utils.ts +1 -1
|
@@ -23,16 +23,22 @@ const UMALQURA_YEAR_END = 1600;
|
|
|
23
23
|
const UMALQURA_START_DAYS = 460322;
|
|
24
24
|
|
|
25
25
|
function islamicToJulianDay(epoch: number, year: number, month: number, day: number): number {
|
|
26
|
-
return
|
|
26
|
+
return (
|
|
27
|
+
day +
|
|
27
28
|
Math.ceil(29.5 * (month - 1)) +
|
|
28
29
|
(year - 1) * 354 +
|
|
29
30
|
Math.floor((3 + 11 * year) / 30) +
|
|
30
|
-
epoch -
|
|
31
|
+
epoch -
|
|
32
|
+
1
|
|
33
|
+
);
|
|
31
34
|
}
|
|
32
35
|
|
|
33
36
|
function julianDayToIslamic(calendar: Calendar, epoch: number, jd: number) {
|
|
34
37
|
let year = Math.floor((30 * (jd - epoch) + 10646) / 10631);
|
|
35
|
-
let month = Math.min(
|
|
38
|
+
let month = Math.min(
|
|
39
|
+
12,
|
|
40
|
+
Math.ceil((jd - (29 + islamicToJulianDay(epoch, year, 1, 1))) / 29.5) + 1
|
|
41
|
+
);
|
|
36
42
|
let day = jd - islamicToJulianDay(epoch, year, month, 1) + 1;
|
|
37
43
|
|
|
38
44
|
return new CalendarDate(calendar, year, month, day);
|
|
@@ -43,11 +49,12 @@ function isLeapYear(year: number): boolean {
|
|
|
43
49
|
}
|
|
44
50
|
|
|
45
51
|
/**
|
|
46
|
-
* The Islamic calendar, also known as the "Hijri" calendar, is used throughout much of the Arab
|
|
47
|
-
* The civil variant uses simple arithmetic rules rather than astronomical calculations to
|
|
48
|
-
* the traditional calendar, which is based on sighting of the crescent moon. It uses
|
|
49
|
-
* Each year has 12 months, with either 354 or 355
|
|
50
|
-
* Learn more about the available Islamic calendars
|
|
52
|
+
* The Islamic calendar, also known as the "Hijri" calendar, is used throughout much of the Arab
|
|
53
|
+
* world. The civil variant uses simple arithmetic rules rather than astronomical calculations to
|
|
54
|
+
* approximate the traditional calendar, which is based on sighting of the crescent moon. It uses
|
|
55
|
+
* Friday, July 16 622 CE (Julian) as the epoch. Each year has 12 months, with either 354 or 355
|
|
56
|
+
* days depending on whether it is a leap year. Learn more about the available Islamic calendars
|
|
57
|
+
* [here](https://cldr.unicode.org/development/development-process/design-proposals/islamic-calendar-types).
|
|
51
58
|
*/
|
|
52
59
|
export class IslamicCivilCalendar implements Calendar {
|
|
53
60
|
identifier: CalendarIdentifier = 'islamic-civil';
|
|
@@ -61,7 +68,7 @@ export class IslamicCivilCalendar implements Calendar {
|
|
|
61
68
|
}
|
|
62
69
|
|
|
63
70
|
getDaysInMonth(date: AnyCalendarDate): number {
|
|
64
|
-
let length = 29 + date.month % 2;
|
|
71
|
+
let length = 29 + (date.month % 2);
|
|
65
72
|
if (date.month === 12 && isLeapYear(date.year)) {
|
|
66
73
|
length++;
|
|
67
74
|
}
|
|
@@ -96,11 +103,12 @@ export class IslamicCivilCalendar implements Calendar {
|
|
|
96
103
|
}
|
|
97
104
|
|
|
98
105
|
/**
|
|
99
|
-
* The Islamic calendar, also known as the "Hijri" calendar, is used throughout much of the Arab
|
|
100
|
-
* The tabular variant uses simple arithmetic rules rather than astronomical calculations to
|
|
101
|
-
* the traditional calendar, which is based on sighting of the crescent moon. It uses
|
|
102
|
-
* Each year has 12 months, with either 354 or 355
|
|
103
|
-
* Learn more about the available Islamic calendars
|
|
106
|
+
* The Islamic calendar, also known as the "Hijri" calendar, is used throughout much of the Arab
|
|
107
|
+
* world. The tabular variant uses simple arithmetic rules rather than astronomical calculations to
|
|
108
|
+
* approximate the traditional calendar, which is based on sighting of the crescent moon. It uses
|
|
109
|
+
* Thursday, July 15 622 CE (Julian) as the epoch. Each year has 12 months, with either 354 or 355
|
|
110
|
+
* days depending on whether it is a leap year. Learn more about the available Islamic calendars
|
|
111
|
+
* [here](https://cldr.unicode.org/development/development-process/design-proposals/islamic-calendar-types).
|
|
104
112
|
*/
|
|
105
113
|
export class IslamicTabularCalendar extends IslamicCivilCalendar {
|
|
106
114
|
identifier: CalendarIdentifier = 'islamic-tbla';
|
|
@@ -115,7 +123,8 @@ export class IslamicTabularCalendar extends IslamicCivilCalendar {
|
|
|
115
123
|
}
|
|
116
124
|
|
|
117
125
|
// Generated by scripts/generate-umalqura.js
|
|
118
|
-
const UMALQURA_DATA =
|
|
126
|
+
const UMALQURA_DATA =
|
|
127
|
+
'qgpUDckO1AbqBmwDrQpVBakGkgepC9QF2gpcBS0NlQZKB1QLagutBa4ETwoXBYsGpQbVCtYCWwmdBE0KJg2VDawFtgm6AlsKKwWVCsoG6Qr0AnYJtgJWCcoKpAvSC9kF3AJtCU0FpQpSC6ULtAW2CVcFlwJLBaMGUgdlC2oFqworBZUMSg2lDcoF1gpXCasESwmlClILagt1BXYCtwhbBFUFqQW0BdoJ3QRuAjYJqgpUDbIN1QXaAlsJqwRVCkkLZAtxC7QFtQpVCiUNkg7JDtQG6QprCasEkwpJDaQNsg25CroEWworBZUKKgtVC1wFvQQ9Ah0JlQpKC1oLbQW2AjsJmwRVBqkGVAdqC2wFrQpVBSkLkgupC9QF2gpaBasKlQVJB2QHqgu1BbYCVgpNDiULUgtqC60FrgIvCZcESwalBqwG1gpdBZ0ETQoWDZUNqgW1BdoCWwmtBJUFygbkBuoK9QS2AlYJqgpUC9IL2QXqAm0JrQSVCkoLpQuyBbUJ1gSXCkcFkwZJB1ULagVrCisFiwpGDaMNygXWCtsEawJLCaUKUgtpC3UFdgG3CFsCKwVlBbQF2gntBG0BtgimClINqQ3UBdoKWwmrBFMGKQdiB6kLsgW1ClUFJQuSDckO0gbpCmsFqwRVCikNVA2qDbUJugQ7CpsETQqqCtUK2gJdCV4ELgqaDFUNsga5BroEXQotBZUKUguoC7QLuQXaAloJSgukDdEO6AZqC20FNQWVBkoNqA3UDdoGWwWdAisGFQtKC5ULqgWuCi4JjwwnBZUGqgbWCl0FnQI=';
|
|
119
128
|
let UMALQURA_MONTHLENGTH: Uint16Array;
|
|
120
129
|
let UMALQURA_YEAR_START_TABLE: Uint32Array;
|
|
121
130
|
|
|
@@ -124,8 +133,8 @@ function umalquraYearStart(year: number): number {
|
|
|
124
133
|
}
|
|
125
134
|
|
|
126
135
|
function umalquraMonthLength(year: number, month: number): number {
|
|
127
|
-
let idx =
|
|
128
|
-
let mask =
|
|
136
|
+
let idx = year - UMALQURA_YEAR_START;
|
|
137
|
+
let mask = 0x01 << (11 - (month - 1));
|
|
129
138
|
if ((UMALQURA_MONTHLENGTH[idx] & mask) === 0) {
|
|
130
139
|
return 29;
|
|
131
140
|
} else {
|
|
@@ -142,15 +151,19 @@ function umalquraMonthStart(year: number, month: number): number {
|
|
|
142
151
|
}
|
|
143
152
|
|
|
144
153
|
function umalquraYearLength(year: number): number {
|
|
145
|
-
return
|
|
154
|
+
return (
|
|
155
|
+
UMALQURA_YEAR_START_TABLE[year + 1 - UMALQURA_YEAR_START] -
|
|
156
|
+
UMALQURA_YEAR_START_TABLE[year - UMALQURA_YEAR_START]
|
|
157
|
+
);
|
|
146
158
|
}
|
|
147
159
|
|
|
148
160
|
/**
|
|
149
|
-
* The Islamic calendar, also known as the "Hijri" calendar, is used throughout much of the Arab
|
|
150
|
-
* The Umalqura variant is primarily used in Saudi Arabia. It is a lunar calendar, based on
|
|
151
|
-
* calculations that predict the sighting of a crescent moon. Month and year lengths
|
|
152
|
-
* depending on these calculations.
|
|
153
|
-
*
|
|
161
|
+
* The Islamic calendar, also known as the "Hijri" calendar, is used throughout much of the Arab
|
|
162
|
+
* world. The Umalqura variant is primarily used in Saudi Arabia. It is a lunar calendar, based on
|
|
163
|
+
* astronomical calculations that predict the sighting of a crescent moon. Month and year lengths
|
|
164
|
+
* vary between years depending on these calculations. Learn more about the available Islamic
|
|
165
|
+
* calendars
|
|
166
|
+
* [here](https://cldr.unicode.org/development/development-process/design-proposals/islamic-calendar-types).
|
|
154
167
|
*/
|
|
155
168
|
export class IslamicUmalquraCalendar extends IslamicCivilCalendar {
|
|
156
169
|
identifier: CalendarIdentifier = 'islamic-umalqura';
|
|
@@ -158,7 +171,9 @@ export class IslamicUmalquraCalendar extends IslamicCivilCalendar {
|
|
|
158
171
|
constructor() {
|
|
159
172
|
super();
|
|
160
173
|
if (!UMALQURA_MONTHLENGTH) {
|
|
161
|
-
UMALQURA_MONTHLENGTH = new Uint16Array(
|
|
174
|
+
UMALQURA_MONTHLENGTH = new Uint16Array(
|
|
175
|
+
Uint8Array.from(atob(UMALQURA_DATA), c => c.charCodeAt(0)).buffer
|
|
176
|
+
);
|
|
162
177
|
}
|
|
163
178
|
|
|
164
179
|
if (!UMALQURA_YEAR_START_TABLE) {
|
|
@@ -203,7 +218,7 @@ export class IslamicUmalquraCalendar extends IslamicCivilCalendar {
|
|
|
203
218
|
}
|
|
204
219
|
}
|
|
205
220
|
|
|
206
|
-
return new CalendarDate(this, y, m,
|
|
221
|
+
return new CalendarDate(this, y, m, days - umalquraMonthStart(y, m) + 1);
|
|
207
222
|
}
|
|
208
223
|
}
|
|
209
224
|
|
|
@@ -18,8 +18,19 @@ import {CalendarDate} from '../CalendarDate';
|
|
|
18
18
|
import {GregorianCalendar} from './GregorianCalendar';
|
|
19
19
|
import {Mutable} from '../utils';
|
|
20
20
|
|
|
21
|
-
const ERA_START_DATES = [
|
|
22
|
-
|
|
21
|
+
const ERA_START_DATES = [
|
|
22
|
+
[1868, 9, 8],
|
|
23
|
+
[1912, 7, 30],
|
|
24
|
+
[1926, 12, 25],
|
|
25
|
+
[1989, 1, 8],
|
|
26
|
+
[2019, 5, 1]
|
|
27
|
+
];
|
|
28
|
+
const ERA_END_DATES = [
|
|
29
|
+
[1912, 7, 29],
|
|
30
|
+
[1926, 12, 24],
|
|
31
|
+
[1989, 1, 7],
|
|
32
|
+
[2019, 4, 30]
|
|
33
|
+
];
|
|
23
34
|
const ERA_ADDENDS = [1867, 1911, 1925, 1988, 2018];
|
|
24
35
|
const ERA_NAMES = ['meiji', 'taisho', 'showa', 'heisei', 'reiwa'];
|
|
25
36
|
|
|
@@ -57,17 +68,14 @@ function toGregorian(date: AnyCalendarDate) {
|
|
|
57
68
|
throw new Error('Unknown era: ' + date.era);
|
|
58
69
|
}
|
|
59
70
|
|
|
60
|
-
return new CalendarDate(
|
|
61
|
-
date.year + eraAddend,
|
|
62
|
-
date.month,
|
|
63
|
-
date.day
|
|
64
|
-
);
|
|
71
|
+
return new CalendarDate(date.year + eraAddend, date.month, date.day);
|
|
65
72
|
}
|
|
66
73
|
|
|
67
74
|
/**
|
|
68
|
-
* The Japanese calendar is based on the Gregorian calendar, but with eras for the reign of each
|
|
69
|
-
* Whenever a new emperor ascends to the throne, a new era begins and the year
|
|
70
|
-
* Note that eras before 1868 (Gregorian) are not currently supported by this
|
|
75
|
+
* The Japanese calendar is based on the Gregorian calendar, but with eras for the reign of each
|
|
76
|
+
* Japanese emperor. Whenever a new emperor ascends to the throne, a new era begins and the year
|
|
77
|
+
* starts again from 1. Note that eras before 1868 (Gregorian) are not currently supported by this
|
|
78
|
+
* implementation.
|
|
71
79
|
*/
|
|
72
80
|
export class JapaneseCalendar extends GregorianCalendar {
|
|
73
81
|
identifier: CalendarIdentifier = 'japanese';
|
|
@@ -32,7 +32,7 @@ const MONTH_START = [
|
|
|
32
32
|
246, // Azar
|
|
33
33
|
276, // Dey
|
|
34
34
|
306, // Bahman
|
|
35
|
-
336
|
|
35
|
+
336 // Esfand
|
|
36
36
|
];
|
|
37
37
|
|
|
38
38
|
/**
|
|
@@ -49,9 +49,7 @@ export class PersianCalendar implements Calendar {
|
|
|
49
49
|
let year = 1 + Math.floor((33 * daysSinceEpoch + 3) / 12053);
|
|
50
50
|
let farvardin1 = 365 * (year - 1) + Math.floor((8 * year + 21) / 33);
|
|
51
51
|
let dayOfYear = daysSinceEpoch - farvardin1;
|
|
52
|
-
let month = dayOfYear < 216
|
|
53
|
-
? Math.floor(dayOfYear / 31)
|
|
54
|
-
: Math.floor((dayOfYear - 6) / 30);
|
|
52
|
+
let month = dayOfYear < 216 ? Math.floor(dayOfYear / 31) : Math.floor((dayOfYear - 6) / 30);
|
|
55
53
|
let day = dayOfYear - MONTH_START[month] + 1;
|
|
56
54
|
return new CalendarDate(this, year, month + 1, day);
|
|
57
55
|
}
|
|
@@ -21,9 +21,7 @@ import {Mutable} from '../utils';
|
|
|
21
21
|
const TAIWAN_ERA_START = 1911;
|
|
22
22
|
|
|
23
23
|
function gregorianYear(date: AnyCalendarDate) {
|
|
24
|
-
return date.era === 'minguo'
|
|
25
|
-
? date.year + TAIWAN_ERA_START
|
|
26
|
-
: 1 - date.year + TAIWAN_ERA_START;
|
|
24
|
+
return date.era === 'minguo' ? date.year + TAIWAN_ERA_START : 1 - date.year + TAIWAN_ERA_START;
|
|
27
25
|
}
|
|
28
26
|
|
|
29
27
|
function gregorianToTaiwan(year: number): [string, number] {
|
|
@@ -79,10 +77,5 @@ export class TaiwanCalendar extends GregorianCalendar {
|
|
|
79
77
|
|
|
80
78
|
function toGregorian(date: AnyCalendarDate) {
|
|
81
79
|
let [era, year] = fromExtendedYear(gregorianYear(date));
|
|
82
|
-
return new CalendarDate(
|
|
83
|
-
era,
|
|
84
|
-
year,
|
|
85
|
-
date.month,
|
|
86
|
-
date.day
|
|
87
|
-
);
|
|
80
|
+
return new CalendarDate(era, year, date.month, date.day);
|
|
88
81
|
}
|
package/src/conversion.ts
CHANGED
|
@@ -13,7 +13,15 @@
|
|
|
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 {
|
|
16
|
+
import {
|
|
17
|
+
AnyCalendarDate,
|
|
18
|
+
AnyDateTime,
|
|
19
|
+
AnyTime,
|
|
20
|
+
Calendar,
|
|
21
|
+
DateFields,
|
|
22
|
+
Disambiguation,
|
|
23
|
+
TimeFields
|
|
24
|
+
} from './types';
|
|
17
25
|
import {CalendarDate, CalendarDateTime, Time, ZonedDateTime} from './CalendarDate';
|
|
18
26
|
import {constrain} from './manipulation';
|
|
19
27
|
import {getExtendedYear, GregorianCalendar} from './calendars/GregorianCalendar';
|
|
@@ -23,10 +31,26 @@ import {Mutable} from './utils';
|
|
|
23
31
|
export function epochFromDate(date: AnyDateTime): number {
|
|
24
32
|
date = toCalendar(date, new GregorianCalendar());
|
|
25
33
|
let year = getExtendedYear(date.era, date.year);
|
|
26
|
-
return epochFromParts(
|
|
34
|
+
return epochFromParts(
|
|
35
|
+
year,
|
|
36
|
+
date.month,
|
|
37
|
+
date.day,
|
|
38
|
+
date.hour,
|
|
39
|
+
date.minute,
|
|
40
|
+
date.second,
|
|
41
|
+
date.millisecond
|
|
42
|
+
);
|
|
27
43
|
}
|
|
28
44
|
|
|
29
|
-
function epochFromParts(
|
|
45
|
+
function epochFromParts(
|
|
46
|
+
year: number,
|
|
47
|
+
month: number,
|
|
48
|
+
day: number,
|
|
49
|
+
hour: number,
|
|
50
|
+
minute: number,
|
|
51
|
+
second: number,
|
|
52
|
+
millisecond: number
|
|
53
|
+
): number {
|
|
30
54
|
// Note: Date.UTC() interprets one and two-digit years as being in the
|
|
31
55
|
// 20th century, so don't use it
|
|
32
56
|
let date = new Date();
|
|
@@ -81,10 +105,10 @@ function getTimeZoneParts(ms: number, timeZone: string) {
|
|
|
81
105
|
}
|
|
82
106
|
}
|
|
83
107
|
|
|
84
|
-
|
|
85
108
|
return {
|
|
86
109
|
// Firefox returns B instead of BC... https://bugzilla.mozilla.org/show_bug.cgi?id=1752253
|
|
87
|
-
year:
|
|
110
|
+
year:
|
|
111
|
+
namedParts.era === 'BC' || namedParts.era === 'B' ? -namedParts.year + 1 : +namedParts.year,
|
|
88
112
|
month: +namedParts.month,
|
|
89
113
|
day: +namedParts.day,
|
|
90
114
|
hour: namedParts.hour === '24' ? 0 : +namedParts.hour, // bugs.chromium.org/p/chromium/issues/detail?id=1045791
|
|
@@ -102,22 +126,33 @@ export function possibleAbsolutes(date: CalendarDateTime, timeZone: string): num
|
|
|
102
126
|
return getValidWallTimes(date, timeZone, earlier, later);
|
|
103
127
|
}
|
|
104
128
|
|
|
105
|
-
function getValidWallTimes(
|
|
129
|
+
function getValidWallTimes(
|
|
130
|
+
date: CalendarDateTime,
|
|
131
|
+
timeZone: string,
|
|
132
|
+
earlier: number,
|
|
133
|
+
later: number
|
|
134
|
+
): number[] {
|
|
106
135
|
let found = earlier === later ? [earlier] : [earlier, later];
|
|
107
136
|
return found.filter(absolute => isValidWallTime(date, timeZone, absolute));
|
|
108
137
|
}
|
|
109
138
|
|
|
110
139
|
function isValidWallTime(date: CalendarDateTime, timeZone: string, absolute: number) {
|
|
111
140
|
let parts = getTimeZoneParts(absolute, timeZone);
|
|
112
|
-
return
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
141
|
+
return (
|
|
142
|
+
date.year === parts.year &&
|
|
143
|
+
date.month === parts.month &&
|
|
144
|
+
date.day === parts.day &&
|
|
145
|
+
date.hour === parts.hour &&
|
|
146
|
+
date.minute === parts.minute &&
|
|
147
|
+
date.second === parts.second
|
|
148
|
+
);
|
|
118
149
|
}
|
|
119
150
|
|
|
120
|
-
export function toAbsolute(
|
|
151
|
+
export function toAbsolute(
|
|
152
|
+
date: CalendarDate | CalendarDateTime,
|
|
153
|
+
timeZone: string,
|
|
154
|
+
disambiguation: Disambiguation = 'compatible'
|
|
155
|
+
): number {
|
|
121
156
|
let dateTime = toCalendarDateTime(date);
|
|
122
157
|
|
|
123
158
|
// Fast path: if the time zone is UTC, use native Date.
|
|
@@ -128,7 +163,11 @@ export function toAbsolute(date: CalendarDate | CalendarDateTime, timeZone: stri
|
|
|
128
163
|
// Fast path: if the time zone is the local timezone and disambiguation is compatible, use native Date.
|
|
129
164
|
// Skip this fast path if the local timezone was explicitly overridden via setLocalTimeZone,
|
|
130
165
|
// since native Date always uses the browser's timezone, not the overridden one.
|
|
131
|
-
if (
|
|
166
|
+
if (
|
|
167
|
+
timeZone === getLocalTimeZone() &&
|
|
168
|
+
disambiguation === 'compatible' &&
|
|
169
|
+
!isLocalTimeZoneOverridden()
|
|
170
|
+
) {
|
|
132
171
|
dateTime = toCalendar(dateTime, new GregorianCalendar());
|
|
133
172
|
|
|
134
173
|
// Don't use Date constructor here because two-digit years are interpreted in the 20th century.
|
|
@@ -173,7 +212,11 @@ export function toAbsolute(date: CalendarDate | CalendarDateTime, timeZone: stri
|
|
|
173
212
|
}
|
|
174
213
|
}
|
|
175
214
|
|
|
176
|
-
export function toDate(
|
|
215
|
+
export function toDate(
|
|
216
|
+
dateTime: CalendarDate | CalendarDateTime,
|
|
217
|
+
timeZone: string,
|
|
218
|
+
disambiguation: Disambiguation = 'compatible'
|
|
219
|
+
): Date {
|
|
177
220
|
return new Date(toAbsolute(dateTime, timeZone, disambiguation));
|
|
178
221
|
}
|
|
179
222
|
|
|
@@ -191,7 +234,18 @@ export function fromAbsolute(ms: number, timeZone: string): ZonedDateTime {
|
|
|
191
234
|
let second = date.getUTCSeconds();
|
|
192
235
|
let millisecond = date.getUTCMilliseconds();
|
|
193
236
|
|
|
194
|
-
return new ZonedDateTime(
|
|
237
|
+
return new ZonedDateTime(
|
|
238
|
+
year < 1 ? 'BC' : 'AD',
|
|
239
|
+
year < 1 ? -year + 1 : year,
|
|
240
|
+
month,
|
|
241
|
+
day,
|
|
242
|
+
timeZone,
|
|
243
|
+
offset,
|
|
244
|
+
hour,
|
|
245
|
+
minute,
|
|
246
|
+
second,
|
|
247
|
+
millisecond
|
|
248
|
+
);
|
|
195
249
|
}
|
|
196
250
|
|
|
197
251
|
/**
|
|
@@ -208,9 +262,18 @@ export function fromDateToLocal(date: Date): ZonedDateTime {
|
|
|
208
262
|
return fromDate(date, getLocalTimeZone());
|
|
209
263
|
}
|
|
210
264
|
|
|
211
|
-
/**
|
|
265
|
+
/**
|
|
266
|
+
* Converts a value with date components such as a `CalendarDateTime` or `ZonedDateTime` into a
|
|
267
|
+
* `CalendarDate`.
|
|
268
|
+
*/
|
|
212
269
|
export function toCalendarDate(dateTime: AnyCalendarDate): CalendarDate {
|
|
213
|
-
return new CalendarDate(
|
|
270
|
+
return new CalendarDate(
|
|
271
|
+
dateTime.calendar,
|
|
272
|
+
dateTime.era,
|
|
273
|
+
dateTime.year,
|
|
274
|
+
dateTime.month,
|
|
275
|
+
dateTime.day
|
|
276
|
+
);
|
|
214
277
|
}
|
|
215
278
|
|
|
216
279
|
export function toDateFields(date: AnyCalendarDate): DateFields {
|
|
@@ -232,11 +295,17 @@ export function toTimeFields(date: AnyTime): TimeFields {
|
|
|
232
295
|
}
|
|
233
296
|
|
|
234
297
|
/**
|
|
235
|
-
* Converts a date value to a `CalendarDateTime`. An optional `Time` value can be passed to set the
|
|
236
|
-
* of the resulting value, otherwise it will default to midnight.
|
|
298
|
+
* Converts a date value to a `CalendarDateTime`. An optional `Time` value can be passed to set the
|
|
299
|
+
* time of the resulting value, otherwise it will default to midnight.
|
|
237
300
|
*/
|
|
238
|
-
export function toCalendarDateTime(
|
|
239
|
-
|
|
301
|
+
export function toCalendarDateTime(
|
|
302
|
+
date: CalendarDate | CalendarDateTime | ZonedDateTime,
|
|
303
|
+
time?: AnyTime
|
|
304
|
+
): CalendarDateTime {
|
|
305
|
+
let hour = 0,
|
|
306
|
+
minute = 0,
|
|
307
|
+
second = 0,
|
|
308
|
+
millisecond = 0;
|
|
240
309
|
if ('timeZone' in date) {
|
|
241
310
|
({hour, minute, second, millisecond} = date);
|
|
242
311
|
} else if ('hour' in date && !time) {
|
|
@@ -283,10 +352,14 @@ export function toCalendar<T extends AnyCalendarDate>(date: T, calendar: Calenda
|
|
|
283
352
|
}
|
|
284
353
|
|
|
285
354
|
/**
|
|
286
|
-
* Converts a date value to a `ZonedDateTime` in the provided time zone. The `disambiguation` option
|
|
287
|
-
* to control how values that fall on daylight saving time changes are interpreted.
|
|
355
|
+
* Converts a date value to a `ZonedDateTime` in the provided time zone. The `disambiguation` option
|
|
356
|
+
* can be set to control how values that fall on daylight saving time changes are interpreted.
|
|
288
357
|
*/
|
|
289
|
-
export function toZoned(
|
|
358
|
+
export function toZoned(
|
|
359
|
+
date: CalendarDate | CalendarDateTime | ZonedDateTime,
|
|
360
|
+
timeZone: string,
|
|
361
|
+
disambiguation?: Disambiguation
|
|
362
|
+
): ZonedDateTime {
|
|
290
363
|
if (date instanceof ZonedDateTime) {
|
|
291
364
|
if (date.timeZone === timeZone) {
|
|
292
365
|
return date;
|
package/src/createCalendar.ts
CHANGED
|
@@ -12,11 +12,19 @@
|
|
|
12
12
|
|
|
13
13
|
import {BuddhistCalendar} from './calendars/BuddhistCalendar';
|
|
14
14
|
import {Calendar, CalendarIdentifier} from './types';
|
|
15
|
-
import {
|
|
15
|
+
import {
|
|
16
|
+
CopticCalendar,
|
|
17
|
+
EthiopicAmeteAlemCalendar,
|
|
18
|
+
EthiopicCalendar
|
|
19
|
+
} from './calendars/EthiopicCalendar';
|
|
16
20
|
import {GregorianCalendar} from './calendars/GregorianCalendar';
|
|
17
21
|
import {HebrewCalendar} from './calendars/HebrewCalendar';
|
|
18
22
|
import {IndianCalendar} from './calendars/IndianCalendar';
|
|
19
|
-
import {
|
|
23
|
+
import {
|
|
24
|
+
IslamicCivilCalendar,
|
|
25
|
+
IslamicTabularCalendar,
|
|
26
|
+
IslamicUmalquraCalendar
|
|
27
|
+
} from './calendars/IslamicCalendar';
|
|
20
28
|
import {JapaneseCalendar} from './calendars/JapaneseCalendar';
|
|
21
29
|
import {PersianCalendar} from './calendars/PersianCalendar';
|
|
22
30
|
import {TaiwanCalendar} from './calendars/TaiwanCalendar';
|
package/src/index.ts
CHANGED
|
@@ -36,9 +36,17 @@ export {BuddhistCalendar} from './calendars/BuddhistCalendar';
|
|
|
36
36
|
export {TaiwanCalendar} from './calendars/TaiwanCalendar';
|
|
37
37
|
export {PersianCalendar} from './calendars/PersianCalendar';
|
|
38
38
|
export {IndianCalendar} from './calendars/IndianCalendar';
|
|
39
|
-
export {
|
|
39
|
+
export {
|
|
40
|
+
IslamicCivilCalendar,
|
|
41
|
+
IslamicTabularCalendar,
|
|
42
|
+
IslamicUmalquraCalendar
|
|
43
|
+
} from './calendars/IslamicCalendar';
|
|
40
44
|
export {HebrewCalendar} from './calendars/HebrewCalendar';
|
|
41
|
-
export {
|
|
45
|
+
export {
|
|
46
|
+
EthiopicCalendar,
|
|
47
|
+
EthiopicAmeteAlemCalendar,
|
|
48
|
+
CopticCalendar
|
|
49
|
+
} from './calendars/EthiopicCalendar';
|
|
42
50
|
export {createCalendar} from './createCalendar';
|
|
43
51
|
export {
|
|
44
52
|
toCalendarDate,
|