@stridge/noctis-intl 1.0.0-beta.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/LICENSE +201 -0
- package/README.md +41 -0
- package/dist/date/CalendarDate.d.ts +211 -0
- package/dist/date/CalendarDate.js +340 -0
- package/dist/date/DateFormatter.d.ts +26 -0
- package/dist/date/DateFormatter.js +114 -0
- package/dist/date/calendars/BuddhistCalendar.d.ts +20 -0
- package/dist/date/calendars/BuddhistCalendar.js +33 -0
- package/dist/date/calendars/EthiopicCalendar.d.ts +49 -0
- package/dist/date/calendars/EthiopicCalendar.js +129 -0
- package/dist/date/calendars/GregorianCalendar.d.ts +26 -0
- package/dist/date/calendars/GregorianCalendar.js +117 -0
- package/dist/date/calendars/HebrewCalendar.d.ts +25 -0
- package/dist/date/calendars/HebrewCalendar.js +114 -0
- package/dist/date/calendars/IndianCalendar.d.ts +21 -0
- package/dist/date/calendars/IndianCalendar.js +75 -0
- package/dist/date/calendars/IslamicCalendar.d.ts +55 -0
- package/dist/date/calendars/IslamicCalendar.js +162 -0
- package/dist/date/calendars/JapaneseCalendar.d.ts +26 -0
- package/dist/date/calendars/JapaneseCalendar.js +154 -0
- package/dist/date/calendars/PersianCalendar.d.ts +23 -0
- package/dist/date/calendars/PersianCalendar.js +63 -0
- package/dist/date/calendars/TaiwanCalendar.d.ts +23 -0
- package/dist/date/calendars/TaiwanCalendar.js +51 -0
- package/dist/date/conversion.d.ts +41 -0
- package/dist/date/conversion.js +181 -0
- package/dist/date/createCalendar.d.ts +7 -0
- package/dist/date/createCalendar.js +30 -0
- package/dist/date/manipulation.js +274 -0
- package/dist/date/queries.d.ts +92 -0
- package/dist/date/queries.js +233 -0
- package/dist/date/string.d.ts +36 -0
- package/dist/date/string.js +162 -0
- package/dist/date/types.d.ts +138 -0
- package/dist/date/utils.d.ts +4 -0
- package/dist/date/utils.js +6 -0
- package/dist/date/weekStartData.js +100 -0
- package/dist/date.d.ts +17 -0
- package/dist/date.js +16 -0
- package/dist/i18n/context.d.ts +17 -0
- package/dist/i18n/context.js +13 -0
- package/dist/i18n/use-collator.d.ts +8 -0
- package/dist/i18n/use-collator.js +19 -0
- package/dist/i18n/use-date-formatter.d.ts +14 -0
- package/dist/i18n/use-date-formatter.js +25 -0
- package/dist/i18n/use-deep-memo.d.ts +8 -0
- package/dist/i18n/use-deep-memo.js +15 -0
- package/dist/i18n/use-filter.d.ts +17 -0
- package/dist/i18n/use-filter.js +49 -0
- package/dist/i18n/use-list-formatter.d.ts +5 -0
- package/dist/i18n/use-list-formatter.js +11 -0
- package/dist/i18n/use-locale.d.ts +7 -0
- package/dist/i18n/use-locale.js +13 -0
- package/dist/i18n/use-localized-string-formatter.d.ts +13 -0
- package/dist/i18n/use-localized-string-formatter.js +30 -0
- package/dist/i18n/use-number-formatter.d.ts +14 -0
- package/dist/i18n/use-number-formatter.js +15 -0
- package/dist/i18n/utils.d.ts +15 -0
- package/dist/i18n/utils.js +50 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.js +21 -0
- package/dist/messages/en.d.ts +6 -0
- package/dist/messages/en.js +68 -0
- package/dist/messages/fa.d.ts +6 -0
- package/dist/messages/fa.js +68 -0
- package/dist/number/NumberFormatter.d.ts +32 -0
- package/dist/number/NumberFormatter.js +135 -0
- package/dist/number/NumberParser.d.ts +30 -0
- package/dist/number/NumberParser.js +234 -0
- package/dist/number.d.ts +3 -0
- package/dist/number.js +3 -0
- package/dist/react.d.ts +17 -0
- package/dist/react.js +17 -0
- package/dist/ssr/use-is-ssr.d.ts +8 -0
- package/dist/ssr/use-is-ssr.js +15 -0
- package/dist/string/LocalizedStringDictionary.d.ts +22 -0
- package/dist/string/LocalizedStringDictionary.js +58 -0
- package/dist/string/LocalizedStringFormatter.d.ts +22 -0
- package/dist/string/LocalizedStringFormatter.js +46 -0
- package/dist/string.d.ts +3 -0
- package/dist/string.js +3 -0
- package/package.json +80 -0
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { CalendarDate } from "../CalendarDate.js";
|
|
2
|
+
//#region src/date/calendars/IslamicCalendar.ts
|
|
3
|
+
const CIVIL_EPOC = 1948440;
|
|
4
|
+
const ASTRONOMICAL_EPOC = 1948439;
|
|
5
|
+
const UMALQURA_YEAR_START = 1300;
|
|
6
|
+
const UMALQURA_YEAR_END = 1600;
|
|
7
|
+
const UMALQURA_START_DAYS = 460322;
|
|
8
|
+
function islamicToJulianDay(epoch, year, month, day) {
|
|
9
|
+
return day + Math.ceil(29.5 * (month - 1)) + (year - 1) * 354 + Math.floor((3 + 11 * year) / 30) + epoch - 1;
|
|
10
|
+
}
|
|
11
|
+
function julianDayToIslamic(calendar, epoch, jd) {
|
|
12
|
+
let year = Math.floor((30 * (jd - epoch) + 10646) / 10631);
|
|
13
|
+
let month = Math.min(12, Math.ceil((jd - (29 + islamicToJulianDay(epoch, year, 1, 1))) / 29.5) + 1);
|
|
14
|
+
return new CalendarDate(calendar, year, month, jd - islamicToJulianDay(epoch, year, month, 1) + 1);
|
|
15
|
+
}
|
|
16
|
+
function isLeapYear(year) {
|
|
17
|
+
return (14 + 11 * year) % 30 < 11;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* The Islamic calendar, also known as the "Hijri" calendar, is used throughout much of the Arab
|
|
21
|
+
* world. The civil variant uses simple arithmetic rules rather than astronomical calculations to
|
|
22
|
+
* approximate the traditional calendar, which is based on sighting of the crescent moon. It uses
|
|
23
|
+
* Friday, July 16 622 CE (Julian) as the epoch. Each year has 12 months, with either 354 or 355
|
|
24
|
+
* days depending on whether it is a leap year. Learn more about the available Islamic calendars
|
|
25
|
+
* [here](https://cldr.unicode.org/development/development-process/design-proposals/islamic-calendar-types).
|
|
26
|
+
*/
|
|
27
|
+
var IslamicCivilCalendar = class {
|
|
28
|
+
identifier = "islamic-civil";
|
|
29
|
+
fromJulianDay(jd) {
|
|
30
|
+
return julianDayToIslamic(this, CIVIL_EPOC, jd);
|
|
31
|
+
}
|
|
32
|
+
toJulianDay(date) {
|
|
33
|
+
return islamicToJulianDay(CIVIL_EPOC, date.year, date.month, date.day);
|
|
34
|
+
}
|
|
35
|
+
getDaysInMonth(date) {
|
|
36
|
+
let length = 29 + date.month % 2;
|
|
37
|
+
if (date.month === 12 && isLeapYear(date.year)) length++;
|
|
38
|
+
return length;
|
|
39
|
+
}
|
|
40
|
+
getMonthsInYear() {
|
|
41
|
+
return 12;
|
|
42
|
+
}
|
|
43
|
+
getDaysInYear(date) {
|
|
44
|
+
return isLeapYear(date.year) ? 355 : 354;
|
|
45
|
+
}
|
|
46
|
+
getMaximumMonthsInYear() {
|
|
47
|
+
return 12;
|
|
48
|
+
}
|
|
49
|
+
getMaximumDaysInMonth() {
|
|
50
|
+
return 30;
|
|
51
|
+
}
|
|
52
|
+
getYearsInEra() {
|
|
53
|
+
return 9665;
|
|
54
|
+
}
|
|
55
|
+
getEras() {
|
|
56
|
+
return ["AH"];
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* The Islamic calendar, also known as the "Hijri" calendar, is used throughout much of the Arab
|
|
61
|
+
* world. The tabular variant uses simple arithmetic rules rather than astronomical calculations to
|
|
62
|
+
* approximate the traditional calendar, which is based on sighting of the crescent moon. It uses
|
|
63
|
+
* Thursday, July 15 622 CE (Julian) as the epoch. Each year has 12 months, with either 354 or 355
|
|
64
|
+
* days depending on whether it is a leap year. Learn more about the available Islamic calendars
|
|
65
|
+
* [here](https://cldr.unicode.org/development/development-process/design-proposals/islamic-calendar-types).
|
|
66
|
+
*/
|
|
67
|
+
var IslamicTabularCalendar = class extends IslamicCivilCalendar {
|
|
68
|
+
identifier = "islamic-tbla";
|
|
69
|
+
fromJulianDay(jd) {
|
|
70
|
+
return julianDayToIslamic(this, ASTRONOMICAL_EPOC, jd);
|
|
71
|
+
}
|
|
72
|
+
toJulianDay(date) {
|
|
73
|
+
return islamicToJulianDay(ASTRONOMICAL_EPOC, date.year, date.month, date.day);
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
const UMALQURA_DATA = "qgpUDckO1AbqBmwDrQpVBakGkgepC9QF2gpcBS0NlQZKB1QLagutBa4ETwoXBYsGpQbVCtYCWwmdBE0KJg2VDawFtgm6AlsKKwWVCsoG6Qr0AnYJtgJWCcoKpAvSC9kF3AJtCU0FpQpSC6ULtAW2CVcFlwJLBaMGUgdlC2oFqworBZUMSg2lDcoF1gpXCasESwmlClILagt1BXYCtwhbBFUFqQW0BdoJ3QRuAjYJqgpUDbIN1QXaAlsJqwRVCkkLZAtxC7QFtQpVCiUNkg7JDtQG6QprCasEkwpJDaQNsg25CroEWworBZUKKgtVC1wFvQQ9Ah0JlQpKC1oLbQW2AjsJmwRVBqkGVAdqC2wFrQpVBSkLkgupC9QF2gpaBasKlQVJB2QHqgu1BbYCVgpNDiULUgtqC60FrgIvCZcESwalBqwG1gpdBZ0ETQoWDZUNqgW1BdoCWwmtBJUFygbkBuoK9QS2AlYJqgpUC9IL2QXqAm0JrQSVCkoLpQuyBbUJ1gSXCkcFkwZJB1ULagVrCisFiwpGDaMNygXWCtsEawJLCaUKUgtpC3UFdgG3CFsCKwVlBbQF2gntBG0BtgimClINqQ3UBdoKWwmrBFMGKQdiB6kLsgW1ClUFJQuSDckO0gbpCmsFqwRVCikNVA2qDbUJugQ7CpsETQqqCtUK2gJdCV4ELgqaDFUNsga5BroEXQotBZUKUguoC7QLuQXaAloJSgukDdEO6AZqC20FNQWVBkoNqA3UDdoGWwWdAisGFQtKC5ULqgWuCi4JjwwnBZUGqgbWCl0FnQI=";
|
|
77
|
+
let UMALQURA_MONTHLENGTH;
|
|
78
|
+
let UMALQURA_YEAR_START_TABLE;
|
|
79
|
+
function umalquraYearStart(year) {
|
|
80
|
+
return UMALQURA_START_DAYS + UMALQURA_YEAR_START_TABLE[year - UMALQURA_YEAR_START];
|
|
81
|
+
}
|
|
82
|
+
function umalquraMonthLength(year, month) {
|
|
83
|
+
let idx = year - UMALQURA_YEAR_START;
|
|
84
|
+
let mask = 1 << 11 - (month - 1);
|
|
85
|
+
if ((UMALQURA_MONTHLENGTH[idx] & mask) === 0) return 29;
|
|
86
|
+
else return 30;
|
|
87
|
+
}
|
|
88
|
+
function umalquraMonthStart(year, month) {
|
|
89
|
+
let day = umalquraYearStart(year);
|
|
90
|
+
for (let i = 1; i < month; i++) day += umalquraMonthLength(year, i);
|
|
91
|
+
return day;
|
|
92
|
+
}
|
|
93
|
+
function umalquraYearLength(year) {
|
|
94
|
+
return UMALQURA_YEAR_START_TABLE[year + 1 - UMALQURA_YEAR_START] - UMALQURA_YEAR_START_TABLE[year - UMALQURA_YEAR_START];
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* The Islamic calendar, also known as the "Hijri" calendar, is used throughout much of the Arab
|
|
98
|
+
* world. The Umalqura variant is primarily used in Saudi Arabia. It is a lunar calendar, based on
|
|
99
|
+
* astronomical calculations that predict the sighting of a crescent moon. Month and year lengths
|
|
100
|
+
* vary between years depending on these calculations. Learn more about the available Islamic
|
|
101
|
+
* calendars
|
|
102
|
+
* [here](https://cldr.unicode.org/development/development-process/design-proposals/islamic-calendar-types).
|
|
103
|
+
*/
|
|
104
|
+
var IslamicUmalquraCalendar = class extends IslamicCivilCalendar {
|
|
105
|
+
identifier = "islamic-umalqura";
|
|
106
|
+
constructor() {
|
|
107
|
+
super();
|
|
108
|
+
if (!UMALQURA_MONTHLENGTH) UMALQURA_MONTHLENGTH = new Uint16Array(Uint8Array.from(atob(UMALQURA_DATA), (c) => c.charCodeAt(0)).buffer);
|
|
109
|
+
if (!UMALQURA_YEAR_START_TABLE) {
|
|
110
|
+
UMALQURA_YEAR_START_TABLE = new Uint32Array(UMALQURA_YEAR_END - UMALQURA_YEAR_START + 1);
|
|
111
|
+
let yearStart = 0;
|
|
112
|
+
for (let year = UMALQURA_YEAR_START; year <= UMALQURA_YEAR_END; year++) {
|
|
113
|
+
UMALQURA_YEAR_START_TABLE[year - UMALQURA_YEAR_START] = yearStart;
|
|
114
|
+
for (let i = 1; i <= 12; i++) yearStart += umalquraMonthLength(year, i);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
fromJulianDay(jd) {
|
|
119
|
+
let days = jd - CIVIL_EPOC;
|
|
120
|
+
let startDays = umalquraYearStart(UMALQURA_YEAR_START);
|
|
121
|
+
let endDays = umalquraYearStart(UMALQURA_YEAR_END);
|
|
122
|
+
if (days < startDays || days > endDays) return super.fromJulianDay(jd);
|
|
123
|
+
else {
|
|
124
|
+
let y = UMALQURA_YEAR_START - 1;
|
|
125
|
+
let m = 1;
|
|
126
|
+
let d = 1;
|
|
127
|
+
while (d > 0) {
|
|
128
|
+
y++;
|
|
129
|
+
d = days - umalquraYearStart(y) + 1;
|
|
130
|
+
let yearLength = umalquraYearLength(y);
|
|
131
|
+
if (d === yearLength) {
|
|
132
|
+
m = 12;
|
|
133
|
+
break;
|
|
134
|
+
} else if (d < yearLength) {
|
|
135
|
+
let monthLength = umalquraMonthLength(y, m);
|
|
136
|
+
m = 1;
|
|
137
|
+
while (d > monthLength) {
|
|
138
|
+
d -= monthLength;
|
|
139
|
+
m++;
|
|
140
|
+
monthLength = umalquraMonthLength(y, m);
|
|
141
|
+
}
|
|
142
|
+
break;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
return new CalendarDate(this, y, m, days - umalquraMonthStart(y, m) + 1);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
toJulianDay(date) {
|
|
149
|
+
if (date.year < UMALQURA_YEAR_START || date.year > UMALQURA_YEAR_END) return super.toJulianDay(date);
|
|
150
|
+
return CIVIL_EPOC + umalquraMonthStart(date.year, date.month) + (date.day - 1);
|
|
151
|
+
}
|
|
152
|
+
getDaysInMonth(date) {
|
|
153
|
+
if (date.year < UMALQURA_YEAR_START || date.year > UMALQURA_YEAR_END) return super.getDaysInMonth(date);
|
|
154
|
+
return umalquraMonthLength(date.year, date.month);
|
|
155
|
+
}
|
|
156
|
+
getDaysInYear(date) {
|
|
157
|
+
if (date.year < UMALQURA_YEAR_START || date.year > UMALQURA_YEAR_END) return super.getDaysInYear(date);
|
|
158
|
+
return umalquraYearLength(date.year);
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
//#endregion
|
|
162
|
+
export { IslamicCivilCalendar, IslamicTabularCalendar, IslamicUmalquraCalendar };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { CalendarDate } from "../CalendarDate.js";
|
|
2
|
+
import { AnyCalendarDate, CalendarIdentifier } from "../types.js";
|
|
3
|
+
import { Mutable } from "../utils.js";
|
|
4
|
+
import { GregorianCalendar } from "./GregorianCalendar.js";
|
|
5
|
+
|
|
6
|
+
//#region src/date/calendars/JapaneseCalendar.d.ts
|
|
7
|
+
/**
|
|
8
|
+
* The Japanese calendar is based on the Gregorian calendar, but with eras for the reign of each
|
|
9
|
+
* Japanese emperor. Whenever a new emperor ascends to the throne, a new era begins and the year
|
|
10
|
+
* starts again from 1. Note that eras before 1868 (Gregorian) are not currently supported by this
|
|
11
|
+
* implementation.
|
|
12
|
+
*/
|
|
13
|
+
declare class JapaneseCalendar extends GregorianCalendar {
|
|
14
|
+
identifier: CalendarIdentifier;
|
|
15
|
+
fromJulianDay(jd: number): CalendarDate;
|
|
16
|
+
toJulianDay(date: AnyCalendarDate): number;
|
|
17
|
+
balanceDate(date: Mutable<AnyCalendarDate>): void;
|
|
18
|
+
constrainDate(date: Mutable<AnyCalendarDate>): void;
|
|
19
|
+
getEras(): string[];
|
|
20
|
+
getYearsInEra(date: AnyCalendarDate): number;
|
|
21
|
+
getDaysInMonth(date: AnyCalendarDate): number;
|
|
22
|
+
getMinimumMonthInYear(date: AnyCalendarDate): number;
|
|
23
|
+
getMinimumDayInMonth(date: AnyCalendarDate): number;
|
|
24
|
+
}
|
|
25
|
+
//#endregion
|
|
26
|
+
export { JapaneseCalendar };
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { GregorianCalendar } from "./GregorianCalendar.js";
|
|
2
|
+
import { CalendarDate } from "../CalendarDate.js";
|
|
3
|
+
//#region src/date/calendars/JapaneseCalendar.ts
|
|
4
|
+
const ERA_START_DATES = [
|
|
5
|
+
[
|
|
6
|
+
1868,
|
|
7
|
+
9,
|
|
8
|
+
8
|
|
9
|
+
],
|
|
10
|
+
[
|
|
11
|
+
1912,
|
|
12
|
+
7,
|
|
13
|
+
30
|
|
14
|
+
],
|
|
15
|
+
[
|
|
16
|
+
1926,
|
|
17
|
+
12,
|
|
18
|
+
25
|
|
19
|
+
],
|
|
20
|
+
[
|
|
21
|
+
1989,
|
|
22
|
+
1,
|
|
23
|
+
8
|
|
24
|
+
],
|
|
25
|
+
[
|
|
26
|
+
2019,
|
|
27
|
+
5,
|
|
28
|
+
1
|
|
29
|
+
]
|
|
30
|
+
];
|
|
31
|
+
const ERA_END_DATES = [
|
|
32
|
+
[
|
|
33
|
+
1912,
|
|
34
|
+
7,
|
|
35
|
+
29
|
|
36
|
+
],
|
|
37
|
+
[
|
|
38
|
+
1926,
|
|
39
|
+
12,
|
|
40
|
+
24
|
|
41
|
+
],
|
|
42
|
+
[
|
|
43
|
+
1989,
|
|
44
|
+
1,
|
|
45
|
+
7
|
|
46
|
+
],
|
|
47
|
+
[
|
|
48
|
+
2019,
|
|
49
|
+
4,
|
|
50
|
+
30
|
|
51
|
+
]
|
|
52
|
+
];
|
|
53
|
+
const ERA_ADDENDS = [
|
|
54
|
+
1867,
|
|
55
|
+
1911,
|
|
56
|
+
1925,
|
|
57
|
+
1988,
|
|
58
|
+
2018
|
|
59
|
+
];
|
|
60
|
+
const ERA_NAMES = [
|
|
61
|
+
"meiji",
|
|
62
|
+
"taisho",
|
|
63
|
+
"showa",
|
|
64
|
+
"heisei",
|
|
65
|
+
"reiwa"
|
|
66
|
+
];
|
|
67
|
+
function findEraFromGregorianDate(date) {
|
|
68
|
+
const idx = ERA_START_DATES.findIndex(([year, month, day]) => {
|
|
69
|
+
if (date.year < year) return true;
|
|
70
|
+
if (date.year === year && date.month < month) return true;
|
|
71
|
+
if (date.year === year && date.month === month && date.day < day) return true;
|
|
72
|
+
return false;
|
|
73
|
+
});
|
|
74
|
+
if (idx === -1) return ERA_START_DATES.length - 1;
|
|
75
|
+
if (idx === 0) return 0;
|
|
76
|
+
return idx - 1;
|
|
77
|
+
}
|
|
78
|
+
function toGregorian(date) {
|
|
79
|
+
let eraAddend = ERA_ADDENDS[ERA_NAMES.indexOf(date.era)];
|
|
80
|
+
if (!eraAddend) throw new Error("Unknown era: " + date.era);
|
|
81
|
+
return new CalendarDate(date.year + eraAddend, date.month, date.day);
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* The Japanese calendar is based on the Gregorian calendar, but with eras for the reign of each
|
|
85
|
+
* Japanese emperor. Whenever a new emperor ascends to the throne, a new era begins and the year
|
|
86
|
+
* starts again from 1. Note that eras before 1868 (Gregorian) are not currently supported by this
|
|
87
|
+
* implementation.
|
|
88
|
+
*/
|
|
89
|
+
var JapaneseCalendar = class extends GregorianCalendar {
|
|
90
|
+
identifier = "japanese";
|
|
91
|
+
fromJulianDay(jd) {
|
|
92
|
+
let date = super.fromJulianDay(jd);
|
|
93
|
+
let era = findEraFromGregorianDate(date);
|
|
94
|
+
return new CalendarDate(this, ERA_NAMES[era], date.year - ERA_ADDENDS[era], date.month, date.day);
|
|
95
|
+
}
|
|
96
|
+
toJulianDay(date) {
|
|
97
|
+
return super.toJulianDay(toGregorian(date));
|
|
98
|
+
}
|
|
99
|
+
balanceDate(date) {
|
|
100
|
+
let gregorianDate = toGregorian(date);
|
|
101
|
+
let era = findEraFromGregorianDate(gregorianDate);
|
|
102
|
+
if (ERA_NAMES[era] !== date.era) {
|
|
103
|
+
date.era = ERA_NAMES[era];
|
|
104
|
+
date.year = gregorianDate.year - ERA_ADDENDS[era];
|
|
105
|
+
}
|
|
106
|
+
this.constrainDate(date);
|
|
107
|
+
}
|
|
108
|
+
constrainDate(date) {
|
|
109
|
+
let idx = ERA_NAMES.indexOf(date.era);
|
|
110
|
+
let end = ERA_END_DATES[idx];
|
|
111
|
+
if (end != null) {
|
|
112
|
+
let [endYear, endMonth, endDay] = end;
|
|
113
|
+
let maxYear = endYear - ERA_ADDENDS[idx];
|
|
114
|
+
date.year = Math.max(1, Math.min(maxYear, date.year));
|
|
115
|
+
if (date.year === maxYear) {
|
|
116
|
+
date.month = Math.min(endMonth, date.month);
|
|
117
|
+
if (date.month === endMonth) date.day = Math.min(endDay, date.day);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
if (date.year === 1 && idx >= 0) {
|
|
121
|
+
let [, startMonth, startDay] = ERA_START_DATES[idx];
|
|
122
|
+
date.month = Math.max(startMonth, date.month);
|
|
123
|
+
if (date.month === startMonth) date.day = Math.max(startDay, date.day);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
getEras() {
|
|
127
|
+
return ERA_NAMES;
|
|
128
|
+
}
|
|
129
|
+
getYearsInEra(date) {
|
|
130
|
+
let era = ERA_NAMES.indexOf(date.era);
|
|
131
|
+
let cur = ERA_START_DATES[era];
|
|
132
|
+
let next = ERA_START_DATES[era + 1];
|
|
133
|
+
if (next == null) return 9999 - cur[0] + 1;
|
|
134
|
+
let years = next[0] - cur[0];
|
|
135
|
+
if (date.month < next[1] || date.month === next[1] && date.day < next[2]) years++;
|
|
136
|
+
return years;
|
|
137
|
+
}
|
|
138
|
+
getDaysInMonth(date) {
|
|
139
|
+
return super.getDaysInMonth(toGregorian(date));
|
|
140
|
+
}
|
|
141
|
+
getMinimumMonthInYear(date) {
|
|
142
|
+
let start = getMinimums(date);
|
|
143
|
+
return start ? start[1] : 1;
|
|
144
|
+
}
|
|
145
|
+
getMinimumDayInMonth(date) {
|
|
146
|
+
let start = getMinimums(date);
|
|
147
|
+
return start && date.month === start[1] ? start[2] : 1;
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
function getMinimums(date) {
|
|
151
|
+
if (date.year === 1) return ERA_START_DATES[ERA_NAMES.indexOf(date.era)];
|
|
152
|
+
}
|
|
153
|
+
//#endregion
|
|
154
|
+
export { JapaneseCalendar };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { CalendarDate } from "../CalendarDate.js";
|
|
2
|
+
import { AnyCalendarDate, Calendar, CalendarIdentifier } from "../types.js";
|
|
3
|
+
|
|
4
|
+
//#region src/date/calendars/PersianCalendar.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* The Persian calendar is the main calendar used in Iran and Afghanistan. It has 12 months
|
|
7
|
+
* in each year, the first 6 of which have 31 days, and the next 5 have 30 days. The 12th month
|
|
8
|
+
* has either 29 or 30 days depending on whether it is a leap year. The Persian year starts
|
|
9
|
+
* around the March equinox.
|
|
10
|
+
*/
|
|
11
|
+
declare class PersianCalendar implements Calendar {
|
|
12
|
+
identifier: CalendarIdentifier;
|
|
13
|
+
fromJulianDay(jd: number): CalendarDate;
|
|
14
|
+
toJulianDay(date: AnyCalendarDate): number;
|
|
15
|
+
getMonthsInYear(): number;
|
|
16
|
+
getDaysInMonth(date: AnyCalendarDate): number;
|
|
17
|
+
getMaximumMonthsInYear(): number;
|
|
18
|
+
getMaximumDaysInMonth(): number;
|
|
19
|
+
getEras(): string[];
|
|
20
|
+
getYearsInEra(): number;
|
|
21
|
+
}
|
|
22
|
+
//#endregion
|
|
23
|
+
export { PersianCalendar };
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { mod } from "../utils.js";
|
|
2
|
+
import { CalendarDate } from "../CalendarDate.js";
|
|
3
|
+
//#region src/date/calendars/PersianCalendar.ts
|
|
4
|
+
const PERSIAN_EPOCH = 1948320;
|
|
5
|
+
const MONTH_START = [
|
|
6
|
+
0,
|
|
7
|
+
31,
|
|
8
|
+
62,
|
|
9
|
+
93,
|
|
10
|
+
124,
|
|
11
|
+
155,
|
|
12
|
+
186,
|
|
13
|
+
216,
|
|
14
|
+
246,
|
|
15
|
+
276,
|
|
16
|
+
306,
|
|
17
|
+
336
|
|
18
|
+
];
|
|
19
|
+
/**
|
|
20
|
+
* The Persian calendar is the main calendar used in Iran and Afghanistan. It has 12 months
|
|
21
|
+
* in each year, the first 6 of which have 31 days, and the next 5 have 30 days. The 12th month
|
|
22
|
+
* has either 29 or 30 days depending on whether it is a leap year. The Persian year starts
|
|
23
|
+
* around the March equinox.
|
|
24
|
+
*/
|
|
25
|
+
var PersianCalendar = class {
|
|
26
|
+
identifier = "persian";
|
|
27
|
+
fromJulianDay(jd) {
|
|
28
|
+
let daysSinceEpoch = jd - PERSIAN_EPOCH;
|
|
29
|
+
let year = 1 + Math.floor((33 * daysSinceEpoch + 3) / 12053);
|
|
30
|
+
let dayOfYear = daysSinceEpoch - (365 * (year - 1) + Math.floor((8 * year + 21) / 33));
|
|
31
|
+
let month = dayOfYear < 216 ? Math.floor(dayOfYear / 31) : Math.floor((dayOfYear - 6) / 30);
|
|
32
|
+
let day = dayOfYear - MONTH_START[month] + 1;
|
|
33
|
+
return new CalendarDate(this, year, month + 1, day);
|
|
34
|
+
}
|
|
35
|
+
toJulianDay(date) {
|
|
36
|
+
let jd = PERSIAN_EPOCH - 1 + 365 * (date.year - 1) + Math.floor((8 * date.year + 21) / 33);
|
|
37
|
+
jd += MONTH_START[date.month - 1];
|
|
38
|
+
jd += date.day;
|
|
39
|
+
return jd;
|
|
40
|
+
}
|
|
41
|
+
getMonthsInYear() {
|
|
42
|
+
return 12;
|
|
43
|
+
}
|
|
44
|
+
getDaysInMonth(date) {
|
|
45
|
+
if (date.month <= 6) return 31;
|
|
46
|
+
if (date.month <= 11) return 30;
|
|
47
|
+
return mod(25 * date.year + 11, 33) < 8 ? 30 : 29;
|
|
48
|
+
}
|
|
49
|
+
getMaximumMonthsInYear() {
|
|
50
|
+
return 12;
|
|
51
|
+
}
|
|
52
|
+
getMaximumDaysInMonth() {
|
|
53
|
+
return 31;
|
|
54
|
+
}
|
|
55
|
+
getEras() {
|
|
56
|
+
return ["AP"];
|
|
57
|
+
}
|
|
58
|
+
getYearsInEra() {
|
|
59
|
+
return 9377;
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
//#endregion
|
|
63
|
+
export { PersianCalendar };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { CalendarDate } from "../CalendarDate.js";
|
|
2
|
+
import { AnyCalendarDate, CalendarIdentifier } from "../types.js";
|
|
3
|
+
import { Mutable } from "../utils.js";
|
|
4
|
+
import { GregorianCalendar } from "./GregorianCalendar.js";
|
|
5
|
+
|
|
6
|
+
//#region src/date/calendars/TaiwanCalendar.d.ts
|
|
7
|
+
/**
|
|
8
|
+
* The Taiwanese calendar is the same as the Gregorian calendar, but years
|
|
9
|
+
* are numbered starting from 1912 (Gregorian). Two eras are supported:
|
|
10
|
+
* 'before_minguo' and 'minguo'.
|
|
11
|
+
*/
|
|
12
|
+
declare class TaiwanCalendar extends GregorianCalendar {
|
|
13
|
+
identifier: CalendarIdentifier;
|
|
14
|
+
fromJulianDay(jd: number): CalendarDate;
|
|
15
|
+
toJulianDay(date: AnyCalendarDate): number;
|
|
16
|
+
getEras(): string[];
|
|
17
|
+
balanceDate(date: Mutable<AnyCalendarDate>): void;
|
|
18
|
+
isInverseEra(date: AnyCalendarDate): boolean;
|
|
19
|
+
getDaysInMonth(date: AnyCalendarDate): number;
|
|
20
|
+
getYearsInEra(date: AnyCalendarDate): number;
|
|
21
|
+
}
|
|
22
|
+
//#endregion
|
|
23
|
+
export { TaiwanCalendar };
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { GregorianCalendar, fromExtendedYear, getExtendedYear } from "./GregorianCalendar.js";
|
|
2
|
+
import { CalendarDate } from "../CalendarDate.js";
|
|
3
|
+
//#region src/date/calendars/TaiwanCalendar.ts
|
|
4
|
+
const TAIWAN_ERA_START = 1911;
|
|
5
|
+
function gregorianYear(date) {
|
|
6
|
+
return date.era === "minguo" ? date.year + TAIWAN_ERA_START : 1 - date.year + TAIWAN_ERA_START;
|
|
7
|
+
}
|
|
8
|
+
function gregorianToTaiwan(year) {
|
|
9
|
+
let y = year - TAIWAN_ERA_START;
|
|
10
|
+
if (y > 0) return ["minguo", y];
|
|
11
|
+
else return ["before_minguo", 1 - y];
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* The Taiwanese calendar is the same as the Gregorian calendar, but years
|
|
15
|
+
* are numbered starting from 1912 (Gregorian). Two eras are supported:
|
|
16
|
+
* 'before_minguo' and 'minguo'.
|
|
17
|
+
*/
|
|
18
|
+
var TaiwanCalendar = class extends GregorianCalendar {
|
|
19
|
+
identifier = "roc";
|
|
20
|
+
fromJulianDay(jd) {
|
|
21
|
+
let date = super.fromJulianDay(jd);
|
|
22
|
+
let [era, year] = gregorianToTaiwan(getExtendedYear(date.era, date.year));
|
|
23
|
+
return new CalendarDate(this, era, year, date.month, date.day);
|
|
24
|
+
}
|
|
25
|
+
toJulianDay(date) {
|
|
26
|
+
return super.toJulianDay(toGregorian(date));
|
|
27
|
+
}
|
|
28
|
+
getEras() {
|
|
29
|
+
return ["before_minguo", "minguo"];
|
|
30
|
+
}
|
|
31
|
+
balanceDate(date) {
|
|
32
|
+
let [era, year] = gregorianToTaiwan(gregorianYear(date));
|
|
33
|
+
date.era = era;
|
|
34
|
+
date.year = year;
|
|
35
|
+
}
|
|
36
|
+
isInverseEra(date) {
|
|
37
|
+
return date.era === "before_minguo";
|
|
38
|
+
}
|
|
39
|
+
getDaysInMonth(date) {
|
|
40
|
+
return super.getDaysInMonth(toGregorian(date));
|
|
41
|
+
}
|
|
42
|
+
getYearsInEra(date) {
|
|
43
|
+
return date.era === "before_minguo" ? 9999 : 9999 - TAIWAN_ERA_START;
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
function toGregorian(date) {
|
|
47
|
+
let [era, year] = fromExtendedYear(gregorianYear(date));
|
|
48
|
+
return new CalendarDate(era, year, date.month, date.day);
|
|
49
|
+
}
|
|
50
|
+
//#endregion
|
|
51
|
+
export { TaiwanCalendar };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { CalendarDate, CalendarDateTime, Time, ZonedDateTime } from "./CalendarDate.js";
|
|
2
|
+
import { AnyCalendarDate, AnyTime, Calendar, Disambiguation } from "./types.js";
|
|
3
|
+
|
|
4
|
+
//#region src/date/conversion.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Takes a Unix epoch (milliseconds since 1970) and converts it to the provided time zone.
|
|
7
|
+
*/
|
|
8
|
+
declare function fromAbsolute(ms: number, timeZone: string): ZonedDateTime;
|
|
9
|
+
/**
|
|
10
|
+
* Takes a `Date` object and converts it to the provided time zone.
|
|
11
|
+
*/
|
|
12
|
+
declare function fromDate(date: Date, timeZone: string): ZonedDateTime;
|
|
13
|
+
/**
|
|
14
|
+
* Takes a `Date` object and converts it to the time zone identifier for the current user.
|
|
15
|
+
*/
|
|
16
|
+
declare function fromDateToLocal(date: Date): ZonedDateTime;
|
|
17
|
+
/**
|
|
18
|
+
* Converts a value with date components such as a `CalendarDateTime` or `ZonedDateTime` into a
|
|
19
|
+
* `CalendarDate`.
|
|
20
|
+
*/
|
|
21
|
+
declare function toCalendarDate(dateTime: AnyCalendarDate): CalendarDate;
|
|
22
|
+
/**
|
|
23
|
+
* Converts a date value to a `CalendarDateTime`. An optional `Time` value can be passed to set the
|
|
24
|
+
* time of the resulting value, otherwise it will default to midnight.
|
|
25
|
+
*/
|
|
26
|
+
declare function toCalendarDateTime(date: CalendarDate | CalendarDateTime | ZonedDateTime, time?: AnyTime): CalendarDateTime;
|
|
27
|
+
/** Extracts the time components from a value containing a date and time. */
|
|
28
|
+
declare function toTime(dateTime: CalendarDateTime | ZonedDateTime): Time;
|
|
29
|
+
/** Converts a date from one calendar system to another. */
|
|
30
|
+
declare function toCalendar<T extends AnyCalendarDate>(date: T, calendar: Calendar): T;
|
|
31
|
+
/**
|
|
32
|
+
* Converts a date value to a `ZonedDateTime` in the provided time zone. The `disambiguation` option
|
|
33
|
+
* can be set to control how values that fall on daylight saving time changes are interpreted.
|
|
34
|
+
*/
|
|
35
|
+
declare function toZoned(date: CalendarDate | CalendarDateTime | ZonedDateTime, timeZone: string, disambiguation?: Disambiguation): ZonedDateTime;
|
|
36
|
+
/** Converts a `ZonedDateTime` from one time zone to another. */
|
|
37
|
+
declare function toTimeZone(date: ZonedDateTime, timeZone: string): ZonedDateTime;
|
|
38
|
+
/** Converts the given `ZonedDateTime` into the user's local time zone. */
|
|
39
|
+
declare function toLocalTimeZone(date: ZonedDateTime): ZonedDateTime;
|
|
40
|
+
//#endregion
|
|
41
|
+
export { fromAbsolute, fromDate, fromDateToLocal, toCalendar, toCalendarDate, toCalendarDateTime, toLocalTimeZone, toTime, toTimeZone, toZoned };
|