@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.
Files changed (82) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +41 -0
  3. package/dist/date/CalendarDate.d.ts +211 -0
  4. package/dist/date/CalendarDate.js +340 -0
  5. package/dist/date/DateFormatter.d.ts +26 -0
  6. package/dist/date/DateFormatter.js +114 -0
  7. package/dist/date/calendars/BuddhistCalendar.d.ts +20 -0
  8. package/dist/date/calendars/BuddhistCalendar.js +33 -0
  9. package/dist/date/calendars/EthiopicCalendar.d.ts +49 -0
  10. package/dist/date/calendars/EthiopicCalendar.js +129 -0
  11. package/dist/date/calendars/GregorianCalendar.d.ts +26 -0
  12. package/dist/date/calendars/GregorianCalendar.js +117 -0
  13. package/dist/date/calendars/HebrewCalendar.d.ts +25 -0
  14. package/dist/date/calendars/HebrewCalendar.js +114 -0
  15. package/dist/date/calendars/IndianCalendar.d.ts +21 -0
  16. package/dist/date/calendars/IndianCalendar.js +75 -0
  17. package/dist/date/calendars/IslamicCalendar.d.ts +55 -0
  18. package/dist/date/calendars/IslamicCalendar.js +162 -0
  19. package/dist/date/calendars/JapaneseCalendar.d.ts +26 -0
  20. package/dist/date/calendars/JapaneseCalendar.js +154 -0
  21. package/dist/date/calendars/PersianCalendar.d.ts +23 -0
  22. package/dist/date/calendars/PersianCalendar.js +63 -0
  23. package/dist/date/calendars/TaiwanCalendar.d.ts +23 -0
  24. package/dist/date/calendars/TaiwanCalendar.js +51 -0
  25. package/dist/date/conversion.d.ts +41 -0
  26. package/dist/date/conversion.js +181 -0
  27. package/dist/date/createCalendar.d.ts +7 -0
  28. package/dist/date/createCalendar.js +30 -0
  29. package/dist/date/manipulation.js +274 -0
  30. package/dist/date/queries.d.ts +92 -0
  31. package/dist/date/queries.js +233 -0
  32. package/dist/date/string.d.ts +36 -0
  33. package/dist/date/string.js +162 -0
  34. package/dist/date/types.d.ts +138 -0
  35. package/dist/date/utils.d.ts +4 -0
  36. package/dist/date/utils.js +6 -0
  37. package/dist/date/weekStartData.js +100 -0
  38. package/dist/date.d.ts +17 -0
  39. package/dist/date.js +16 -0
  40. package/dist/i18n/context.d.ts +17 -0
  41. package/dist/i18n/context.js +13 -0
  42. package/dist/i18n/use-collator.d.ts +8 -0
  43. package/dist/i18n/use-collator.js +19 -0
  44. package/dist/i18n/use-date-formatter.d.ts +14 -0
  45. package/dist/i18n/use-date-formatter.js +25 -0
  46. package/dist/i18n/use-deep-memo.d.ts +8 -0
  47. package/dist/i18n/use-deep-memo.js +15 -0
  48. package/dist/i18n/use-filter.d.ts +17 -0
  49. package/dist/i18n/use-filter.js +49 -0
  50. package/dist/i18n/use-list-formatter.d.ts +5 -0
  51. package/dist/i18n/use-list-formatter.js +11 -0
  52. package/dist/i18n/use-locale.d.ts +7 -0
  53. package/dist/i18n/use-locale.js +13 -0
  54. package/dist/i18n/use-localized-string-formatter.d.ts +13 -0
  55. package/dist/i18n/use-localized-string-formatter.js +30 -0
  56. package/dist/i18n/use-number-formatter.d.ts +14 -0
  57. package/dist/i18n/use-number-formatter.js +15 -0
  58. package/dist/i18n/utils.d.ts +15 -0
  59. package/dist/i18n/utils.js +50 -0
  60. package/dist/index.d.ts +22 -0
  61. package/dist/index.js +21 -0
  62. package/dist/messages/en.d.ts +6 -0
  63. package/dist/messages/en.js +68 -0
  64. package/dist/messages/fa.d.ts +6 -0
  65. package/dist/messages/fa.js +68 -0
  66. package/dist/number/NumberFormatter.d.ts +32 -0
  67. package/dist/number/NumberFormatter.js +135 -0
  68. package/dist/number/NumberParser.d.ts +30 -0
  69. package/dist/number/NumberParser.js +234 -0
  70. package/dist/number.d.ts +3 -0
  71. package/dist/number.js +3 -0
  72. package/dist/react.d.ts +17 -0
  73. package/dist/react.js +17 -0
  74. package/dist/ssr/use-is-ssr.d.ts +8 -0
  75. package/dist/ssr/use-is-ssr.js +15 -0
  76. package/dist/string/LocalizedStringDictionary.d.ts +22 -0
  77. package/dist/string/LocalizedStringDictionary.js +58 -0
  78. package/dist/string/LocalizedStringFormatter.d.ts +22 -0
  79. package/dist/string/LocalizedStringFormatter.js +46 -0
  80. package/dist/string.d.ts +3 -0
  81. package/dist/string.js +3 -0
  82. package/package.json +80 -0
@@ -0,0 +1,129 @@
1
+ import { CalendarDate } from "../CalendarDate.js";
2
+ //#region src/date/calendars/EthiopicCalendar.ts
3
+ const ETHIOPIC_EPOCH = 1723856;
4
+ const COPTIC_EPOCH = 1824665;
5
+ const AMETE_MIHRET_DELTA = 5500;
6
+ function ceToJulianDay(epoch, year, month, day) {
7
+ return epoch + 365 * year + Math.floor(year / 4) + 30 * (month - 1) + day - 1;
8
+ }
9
+ function julianDayToCE(epoch, jd) {
10
+ let year = Math.floor(4 * (jd - epoch) / 1461);
11
+ let month = 1 + Math.floor((jd - ceToJulianDay(epoch, year, 1, 1)) / 30);
12
+ return [
13
+ year,
14
+ month,
15
+ jd + 1 - ceToJulianDay(epoch, year, month, 1)
16
+ ];
17
+ }
18
+ function getLeapDay(year) {
19
+ return Math.floor(year % 4 / 3);
20
+ }
21
+ function getDaysInMonth(year, month) {
22
+ if (month % 13 !== 0) return 30;
23
+ else return getLeapDay(year) + 5;
24
+ }
25
+ /**
26
+ * The Ethiopic calendar system is the official calendar used in Ethiopia.
27
+ * It includes 12 months of 30 days each, plus 5 or 6 intercalary days depending
28
+ * on whether it is a leap year. Two eras are supported: 'AA' and 'AM'.
29
+ */
30
+ var EthiopicCalendar = class {
31
+ identifier = "ethiopic";
32
+ fromJulianDay(jd) {
33
+ let [year, month, day] = julianDayToCE(ETHIOPIC_EPOCH, jd);
34
+ let era = "AM";
35
+ if (year <= 0) {
36
+ era = "AA";
37
+ year += AMETE_MIHRET_DELTA;
38
+ }
39
+ return new CalendarDate(this, era, year, month, day);
40
+ }
41
+ toJulianDay(date) {
42
+ let year = date.year;
43
+ if (date.era === "AA") year -= AMETE_MIHRET_DELTA;
44
+ return ceToJulianDay(ETHIOPIC_EPOCH, year, date.month, date.day);
45
+ }
46
+ getDaysInMonth(date) {
47
+ return getDaysInMonth(date.year, date.month);
48
+ }
49
+ getMonthsInYear() {
50
+ return 13;
51
+ }
52
+ getDaysInYear(date) {
53
+ return 365 + getLeapDay(date.year);
54
+ }
55
+ getMaximumMonthsInYear() {
56
+ return 13;
57
+ }
58
+ getMaximumDaysInMonth() {
59
+ return 30;
60
+ }
61
+ getYearsInEra(date) {
62
+ return date.era === "AA" ? 9999 : 9991;
63
+ }
64
+ getEras() {
65
+ return ["AA", "AM"];
66
+ }
67
+ };
68
+ /**
69
+ * The Ethiopic (Amete Alem) calendar is the same as the modern Ethiopic calendar,
70
+ * except years were measured from a different epoch. Only one era is supported: 'AA'.
71
+ */
72
+ var EthiopicAmeteAlemCalendar = class extends EthiopicCalendar {
73
+ identifier = "ethioaa";
74
+ fromJulianDay(jd) {
75
+ let [year, month, day] = julianDayToCE(ETHIOPIC_EPOCH, jd);
76
+ year += AMETE_MIHRET_DELTA;
77
+ return new CalendarDate(this, "AA", year, month, day);
78
+ }
79
+ getEras() {
80
+ return ["AA"];
81
+ }
82
+ getYearsInEra() {
83
+ return 9999;
84
+ }
85
+ };
86
+ /**
87
+ * The Coptic calendar is similar to the Ethiopic calendar.
88
+ * It includes 12 months of 30 days each, plus 5 or 6 intercalary days depending
89
+ * on whether it is a leap year. Two eras are supported: 'BCE' and 'CE'.
90
+ */
91
+ var CopticCalendar = class extends EthiopicCalendar {
92
+ identifier = "coptic";
93
+ fromJulianDay(jd) {
94
+ let [year, month, day] = julianDayToCE(COPTIC_EPOCH, jd);
95
+ let era = "CE";
96
+ if (year <= 0) {
97
+ era = "BCE";
98
+ year = 1 - year;
99
+ }
100
+ return new CalendarDate(this, era, year, month, day);
101
+ }
102
+ toJulianDay(date) {
103
+ let year = date.year;
104
+ if (date.era === "BCE") year = 1 - year;
105
+ return ceToJulianDay(COPTIC_EPOCH, year, date.month, date.day);
106
+ }
107
+ getDaysInMonth(date) {
108
+ let year = date.year;
109
+ if (date.era === "BCE") year = 1 - year;
110
+ return getDaysInMonth(year, date.month);
111
+ }
112
+ isInverseEra(date) {
113
+ return date.era === "BCE";
114
+ }
115
+ balanceDate(date) {
116
+ if (date.year <= 0) {
117
+ date.era = date.era === "BCE" ? "CE" : "BCE";
118
+ date.year = 1 - date.year;
119
+ }
120
+ }
121
+ getEras() {
122
+ return ["BCE", "CE"];
123
+ }
124
+ getYearsInEra(date) {
125
+ return date.era === "BCE" ? 9999 : 9715;
126
+ }
127
+ };
128
+ //#endregion
129
+ export { CopticCalendar, EthiopicAmeteAlemCalendar, EthiopicCalendar };
@@ -0,0 +1,26 @@
1
+ import { CalendarDate } from "../CalendarDate.js";
2
+ import { AnyCalendarDate, Calendar, CalendarIdentifier } from "../types.js";
3
+ import { Mutable } from "../utils.js";
4
+
5
+ //#region src/date/calendars/GregorianCalendar.d.ts
6
+ /**
7
+ * The Gregorian calendar is the most commonly used calendar system in the world. It supports two
8
+ * eras: BC, and AD. Years always contain 12 months, and 365 or 366 days depending on whether it is
9
+ * a leap year.
10
+ */
11
+ declare class GregorianCalendar implements Calendar {
12
+ identifier: CalendarIdentifier;
13
+ fromJulianDay(jd: number): CalendarDate;
14
+ toJulianDay(date: AnyCalendarDate): number;
15
+ getDaysInMonth(date: AnyCalendarDate): number;
16
+ getMonthsInYear(date: AnyCalendarDate): number;
17
+ getDaysInYear(date: AnyCalendarDate): number;
18
+ getMaximumMonthsInYear(): number;
19
+ getMaximumDaysInMonth(): number;
20
+ getYearsInEra(date: AnyCalendarDate): number;
21
+ getEras(): string[];
22
+ isInverseEra(date: AnyCalendarDate): boolean;
23
+ balanceDate(date: Mutable<AnyCalendarDate>): void;
24
+ }
25
+ //#endregion
26
+ export { GregorianCalendar };
@@ -0,0 +1,117 @@
1
+ import { mod } from "../utils.js";
2
+ import { CalendarDate } from "../CalendarDate.js";
3
+ //#region src/date/calendars/GregorianCalendar.ts
4
+ const EPOCH = 1721426;
5
+ function gregorianToJulianDay(era, year, month, day) {
6
+ year = getExtendedYear(era, year);
7
+ let y1 = year - 1;
8
+ let monthOffset = -2;
9
+ if (month <= 2) monthOffset = 0;
10
+ else if (isLeapYear(year)) monthOffset = -1;
11
+ return EPOCH - 1 + 365 * y1 + Math.floor(y1 / 4) - Math.floor(y1 / 100) + Math.floor(y1 / 400) + Math.floor((367 * month - 362) / 12 + monthOffset + day);
12
+ }
13
+ function isLeapYear(year) {
14
+ return year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0);
15
+ }
16
+ function getExtendedYear(era, year) {
17
+ return era === "BC" ? 1 - year : year;
18
+ }
19
+ function fromExtendedYear(year) {
20
+ let era = "AD";
21
+ if (year <= 0) {
22
+ era = "BC";
23
+ year = 1 - year;
24
+ }
25
+ return [era, year];
26
+ }
27
+ const daysInMonth = {
28
+ standard: [
29
+ 31,
30
+ 28,
31
+ 31,
32
+ 30,
33
+ 31,
34
+ 30,
35
+ 31,
36
+ 31,
37
+ 30,
38
+ 31,
39
+ 30,
40
+ 31
41
+ ],
42
+ leapyear: [
43
+ 31,
44
+ 29,
45
+ 31,
46
+ 30,
47
+ 31,
48
+ 30,
49
+ 31,
50
+ 31,
51
+ 30,
52
+ 31,
53
+ 30,
54
+ 31
55
+ ]
56
+ };
57
+ /**
58
+ * The Gregorian calendar is the most commonly used calendar system in the world. It supports two
59
+ * eras: BC, and AD. Years always contain 12 months, and 365 or 366 days depending on whether it is
60
+ * a leap year.
61
+ */
62
+ var GregorianCalendar = class {
63
+ identifier = "gregory";
64
+ fromJulianDay(jd) {
65
+ let jd0 = jd;
66
+ let depoch = jd0 - EPOCH;
67
+ let quadricent = Math.floor(depoch / 146097);
68
+ let dqc = mod(depoch, 146097);
69
+ let cent = Math.floor(dqc / 36524);
70
+ let dcent = mod(dqc, 36524);
71
+ let quad = Math.floor(dcent / 1461);
72
+ let dquad = mod(dcent, 1461);
73
+ let yindex = Math.floor(dquad / 365);
74
+ let [era, year] = fromExtendedYear(quadricent * 400 + cent * 100 + quad * 4 + yindex + (cent !== 4 && yindex !== 4 ? 1 : 0));
75
+ let yearDay = jd0 - gregorianToJulianDay(era, year, 1, 1);
76
+ let leapAdj = 2;
77
+ if (jd0 < gregorianToJulianDay(era, year, 3, 1)) leapAdj = 0;
78
+ else if (isLeapYear(year)) leapAdj = 1;
79
+ let month = Math.floor(((yearDay + leapAdj) * 12 + 373) / 367);
80
+ return new CalendarDate(era, year, month, jd0 - gregorianToJulianDay(era, year, month, 1) + 1);
81
+ }
82
+ toJulianDay(date) {
83
+ return gregorianToJulianDay(date.era, date.year, date.month, date.day);
84
+ }
85
+ getDaysInMonth(date) {
86
+ return daysInMonth[isLeapYear(date.year) ? "leapyear" : "standard"][date.month - 1];
87
+ }
88
+ getMonthsInYear(date) {
89
+ return 12;
90
+ }
91
+ getDaysInYear(date) {
92
+ return isLeapYear(date.year) ? 366 : 365;
93
+ }
94
+ getMaximumMonthsInYear() {
95
+ return 12;
96
+ }
97
+ getMaximumDaysInMonth() {
98
+ return 31;
99
+ }
100
+ getYearsInEra(date) {
101
+ return 9999;
102
+ }
103
+ getEras() {
104
+ return ["BC", "AD"];
105
+ }
106
+ isInverseEra(date) {
107
+ return date.era === "BC";
108
+ }
109
+ balanceDate(date) {
110
+ if (date.year <= 0) {
111
+ date.era = date.era === "BC" ? "AD" : "BC";
112
+ date.year = 1 - date.year;
113
+ }
114
+ }
115
+ };
116
+ //#endregion
117
+ export { GregorianCalendar, fromExtendedYear, getExtendedYear, gregorianToJulianDay, isLeapYear };
@@ -0,0 +1,25 @@
1
+ import { CalendarDate } from "../CalendarDate.js";
2
+ import { AnyCalendarDate, Calendar, CalendarIdentifier } from "../types.js";
3
+ import { Mutable } from "../utils.js";
4
+
5
+ //#region src/date/calendars/HebrewCalendar.d.ts
6
+ /**
7
+ * The Hebrew calendar is used in Israel and around the world by the Jewish faith.
8
+ * Years include either 12 or 13 months depending on whether it is a leap year.
9
+ * In leap years, an extra month is inserted at month 6.
10
+ */
11
+ declare class HebrewCalendar implements Calendar {
12
+ identifier: CalendarIdentifier;
13
+ fromJulianDay(jd: number): CalendarDate;
14
+ toJulianDay(date: AnyCalendarDate): number;
15
+ getDaysInMonth(date: AnyCalendarDate): number;
16
+ getMonthsInYear(date: AnyCalendarDate): number;
17
+ getDaysInYear(date: AnyCalendarDate): number;
18
+ getMaximumMonthsInYear(): number;
19
+ getMaximumDaysInMonth(): number;
20
+ getYearsInEra(): number;
21
+ getEras(): string[];
22
+ balanceYearMonth(date: Mutable<AnyCalendarDate>, previousDate: AnyCalendarDate): void;
23
+ }
24
+ //#endregion
25
+ export { HebrewCalendar };
@@ -0,0 +1,114 @@
1
+ import { mod } from "../utils.js";
2
+ import { CalendarDate } from "../CalendarDate.js";
3
+ //#region src/date/calendars/HebrewCalendar.ts
4
+ const HEBREW_EPOCH = 347997;
5
+ const HOUR_PARTS = 1080;
6
+ const DAY_PARTS = 24 * HOUR_PARTS;
7
+ const MONTH_DAYS = 29;
8
+ const MONTH_FRACT = 12 * HOUR_PARTS + 793;
9
+ const MONTH_PARTS = MONTH_DAYS * DAY_PARTS + MONTH_FRACT;
10
+ function isLeapYear(year) {
11
+ return mod(year * 7 + 1, 19) < 7;
12
+ }
13
+ function hebrewDelay1(year) {
14
+ let months = Math.floor((235 * year - 234) / 19);
15
+ let parts = 12084 + 13753 * months;
16
+ let day = months * 29 + Math.floor(parts / 25920);
17
+ if (mod(3 * (day + 1), 7) < 3) day += 1;
18
+ return day;
19
+ }
20
+ function hebrewDelay2(year) {
21
+ let last = hebrewDelay1(year - 1);
22
+ let present = hebrewDelay1(year);
23
+ if (hebrewDelay1(year + 1) - present === 356) return 2;
24
+ if (present - last === 382) return 1;
25
+ return 0;
26
+ }
27
+ function startOfYear(year) {
28
+ return hebrewDelay1(year) + hebrewDelay2(year);
29
+ }
30
+ function getDaysInYear(year) {
31
+ return startOfYear(year + 1) - startOfYear(year);
32
+ }
33
+ function getYearType(year) {
34
+ let yearLength = getDaysInYear(year);
35
+ if (yearLength > 380) yearLength -= 30;
36
+ switch (yearLength) {
37
+ case 353: return 0;
38
+ case 354: return 1;
39
+ case 355: return 2;
40
+ }
41
+ }
42
+ function getDaysInMonth(year, month) {
43
+ if (month >= 6 && !isLeapYear(year)) month++;
44
+ if (month === 4 || month === 7 || month === 9 || month === 11 || month === 13) return 29;
45
+ let yearType = getYearType(year);
46
+ if (month === 2) return yearType === 2 ? 30 : 29;
47
+ if (month === 3) return yearType === 0 ? 29 : 30;
48
+ if (month === 6) return isLeapYear(year) ? 30 : 0;
49
+ return 30;
50
+ }
51
+ /**
52
+ * The Hebrew calendar is used in Israel and around the world by the Jewish faith.
53
+ * Years include either 12 or 13 months depending on whether it is a leap year.
54
+ * In leap years, an extra month is inserted at month 6.
55
+ */
56
+ var HebrewCalendar = class {
57
+ identifier = "hebrew";
58
+ fromJulianDay(jd) {
59
+ let d = jd - HEBREW_EPOCH;
60
+ let m = d * DAY_PARTS / MONTH_PARTS;
61
+ let year = Math.floor((19 * m + 234) / 235) + 1;
62
+ let ys = startOfYear(year);
63
+ let dayOfYear = Math.floor(d - ys);
64
+ while (dayOfYear < 1) {
65
+ year--;
66
+ ys = startOfYear(year);
67
+ dayOfYear = Math.floor(d - ys);
68
+ }
69
+ let month = 1;
70
+ let monthStart = 0;
71
+ while (monthStart < dayOfYear) {
72
+ monthStart += getDaysInMonth(year, month);
73
+ month++;
74
+ }
75
+ month--;
76
+ monthStart -= getDaysInMonth(year, month);
77
+ let day = dayOfYear - monthStart;
78
+ return new CalendarDate(this, year, month, day);
79
+ }
80
+ toJulianDay(date) {
81
+ let jd = startOfYear(date.year);
82
+ for (let month = 1; month < date.month; month++) jd += getDaysInMonth(date.year, month);
83
+ return jd + date.day + HEBREW_EPOCH;
84
+ }
85
+ getDaysInMonth(date) {
86
+ return getDaysInMonth(date.year, date.month);
87
+ }
88
+ getMonthsInYear(date) {
89
+ return isLeapYear(date.year) ? 13 : 12;
90
+ }
91
+ getDaysInYear(date) {
92
+ return getDaysInYear(date.year);
93
+ }
94
+ getMaximumMonthsInYear() {
95
+ return 13;
96
+ }
97
+ getMaximumDaysInMonth() {
98
+ return 30;
99
+ }
100
+ getYearsInEra() {
101
+ return 9999;
102
+ }
103
+ getEras() {
104
+ return ["AM"];
105
+ }
106
+ balanceYearMonth(date, previousDate) {
107
+ if (previousDate.year !== date.year) {
108
+ if (isLeapYear(previousDate.year) && !isLeapYear(date.year) && previousDate.month > 6) date.month--;
109
+ else if (!isLeapYear(previousDate.year) && isLeapYear(date.year) && previousDate.month > 6) date.month++;
110
+ }
111
+ }
112
+ };
113
+ //#endregion
114
+ export { HebrewCalendar };
@@ -0,0 +1,21 @@
1
+ import { CalendarDate } from "../CalendarDate.js";
2
+ import { AnyCalendarDate, CalendarIdentifier } from "../types.js";
3
+ import { GregorianCalendar } from "./GregorianCalendar.js";
4
+
5
+ //#region src/date/calendars/IndianCalendar.d.ts
6
+ /**
7
+ * The Indian National Calendar is similar to the Gregorian calendar, but with
8
+ * years numbered since the Saka era in 78 AD (Gregorian). There are 12 months
9
+ * in each year, with either 30 or 31 days. Only one era identifier is supported: 'saka'.
10
+ */
11
+ declare class IndianCalendar extends GregorianCalendar {
12
+ identifier: CalendarIdentifier;
13
+ fromJulianDay(jd: number): CalendarDate;
14
+ toJulianDay(date: AnyCalendarDate): number;
15
+ getDaysInMonth(date: AnyCalendarDate): number;
16
+ getYearsInEra(): number;
17
+ getEras(): string[];
18
+ balanceDate(): void;
19
+ }
20
+ //#endregion
21
+ export { IndianCalendar };
@@ -0,0 +1,75 @@
1
+ import { GregorianCalendar, fromExtendedYear, gregorianToJulianDay, isLeapYear } from "./GregorianCalendar.js";
2
+ import { CalendarDate } from "../CalendarDate.js";
3
+ //#region src/date/calendars/IndianCalendar.ts
4
+ const INDIAN_ERA_START = 78;
5
+ const INDIAN_YEAR_START = 80;
6
+ /**
7
+ * The Indian National Calendar is similar to the Gregorian calendar, but with
8
+ * years numbered since the Saka era in 78 AD (Gregorian). There are 12 months
9
+ * in each year, with either 30 or 31 days. Only one era identifier is supported: 'saka'.
10
+ */
11
+ var IndianCalendar = class extends GregorianCalendar {
12
+ identifier = "indian";
13
+ fromJulianDay(jd) {
14
+ let date = super.fromJulianDay(jd);
15
+ let indianYear = date.year - INDIAN_ERA_START;
16
+ let yDay = jd - gregorianToJulianDay(date.era, date.year, 1, 1);
17
+ let leapMonth;
18
+ if (yDay < INDIAN_YEAR_START) {
19
+ indianYear--;
20
+ leapMonth = isLeapYear(date.year - 1) ? 31 : 30;
21
+ yDay += leapMonth + 155 + 90 + 10;
22
+ } else {
23
+ leapMonth = isLeapYear(date.year) ? 31 : 30;
24
+ yDay -= INDIAN_YEAR_START;
25
+ }
26
+ let indianMonth;
27
+ let indianDay;
28
+ if (yDay < leapMonth) {
29
+ indianMonth = 1;
30
+ indianDay = yDay + 1;
31
+ } else {
32
+ let mDay = yDay - leapMonth;
33
+ if (mDay < 155) {
34
+ indianMonth = Math.floor(mDay / 31) + 2;
35
+ indianDay = mDay % 31 + 1;
36
+ } else {
37
+ mDay -= 155;
38
+ indianMonth = Math.floor(mDay / 30) + 7;
39
+ indianDay = mDay % 30 + 1;
40
+ }
41
+ }
42
+ return new CalendarDate(this, indianYear, indianMonth, indianDay);
43
+ }
44
+ toJulianDay(date) {
45
+ let [era, year] = fromExtendedYear(date.year + INDIAN_ERA_START);
46
+ let leapMonth;
47
+ let jd;
48
+ if (isLeapYear(year)) {
49
+ leapMonth = 31;
50
+ jd = gregorianToJulianDay(era, year, 3, 21);
51
+ } else {
52
+ leapMonth = 30;
53
+ jd = gregorianToJulianDay(era, year, 3, 22);
54
+ }
55
+ if (date.month === 1) return jd + date.day - 1;
56
+ jd += leapMonth + Math.min(date.month - 2, 5) * 31;
57
+ if (date.month >= 8) jd += (date.month - 7) * 30;
58
+ jd += date.day - 1;
59
+ return jd;
60
+ }
61
+ getDaysInMonth(date) {
62
+ if (date.month === 1 && isLeapYear(date.year + INDIAN_ERA_START)) return 31;
63
+ if (date.month >= 2 && date.month <= 6) return 31;
64
+ return 30;
65
+ }
66
+ getYearsInEra() {
67
+ return 9919;
68
+ }
69
+ getEras() {
70
+ return ["saka"];
71
+ }
72
+ balanceDate() {}
73
+ };
74
+ //#endregion
75
+ export { IndianCalendar };
@@ -0,0 +1,55 @@
1
+ import { CalendarDate } from "../CalendarDate.js";
2
+ import { AnyCalendarDate, Calendar, CalendarIdentifier } from "../types.js";
3
+
4
+ //#region src/date/calendars/IslamicCalendar.d.ts
5
+ /**
6
+ * The Islamic calendar, also known as the "Hijri" calendar, is used throughout much of the Arab
7
+ * world. The civil variant uses simple arithmetic rules rather than astronomical calculations to
8
+ * approximate the traditional calendar, which is based on sighting of the crescent moon. It uses
9
+ * Friday, July 16 622 CE (Julian) as the epoch. Each year has 12 months, with either 354 or 355
10
+ * days depending on whether it is a leap year. Learn more about the available Islamic calendars
11
+ * [here](https://cldr.unicode.org/development/development-process/design-proposals/islamic-calendar-types).
12
+ */
13
+ declare class IslamicCivilCalendar implements Calendar {
14
+ identifier: CalendarIdentifier;
15
+ fromJulianDay(jd: number): CalendarDate;
16
+ toJulianDay(date: AnyCalendarDate): number;
17
+ getDaysInMonth(date: AnyCalendarDate): number;
18
+ getMonthsInYear(): number;
19
+ getDaysInYear(date: AnyCalendarDate): number;
20
+ getMaximumMonthsInYear(): number;
21
+ getMaximumDaysInMonth(): number;
22
+ getYearsInEra(): number;
23
+ getEras(): string[];
24
+ }
25
+ /**
26
+ * The Islamic calendar, also known as the "Hijri" calendar, is used throughout much of the Arab
27
+ * world. The tabular variant uses simple arithmetic rules rather than astronomical calculations to
28
+ * approximate the traditional calendar, which is based on sighting of the crescent moon. It uses
29
+ * Thursday, July 15 622 CE (Julian) as the epoch. Each year has 12 months, with either 354 or 355
30
+ * days depending on whether it is a leap year. Learn more about the available Islamic calendars
31
+ * [here](https://cldr.unicode.org/development/development-process/design-proposals/islamic-calendar-types).
32
+ */
33
+ declare class IslamicTabularCalendar extends IslamicCivilCalendar {
34
+ identifier: CalendarIdentifier;
35
+ fromJulianDay(jd: number): CalendarDate;
36
+ toJulianDay(date: AnyCalendarDate): number;
37
+ }
38
+ /**
39
+ * The Islamic calendar, also known as the "Hijri" calendar, is used throughout much of the Arab
40
+ * world. The Umalqura variant is primarily used in Saudi Arabia. It is a lunar calendar, based on
41
+ * astronomical calculations that predict the sighting of a crescent moon. Month and year lengths
42
+ * vary between years depending on these calculations. Learn more about the available Islamic
43
+ * calendars
44
+ * [here](https://cldr.unicode.org/development/development-process/design-proposals/islamic-calendar-types).
45
+ */
46
+ declare class IslamicUmalquraCalendar extends IslamicCivilCalendar {
47
+ identifier: CalendarIdentifier;
48
+ constructor();
49
+ fromJulianDay(jd: number): CalendarDate;
50
+ toJulianDay(date: AnyCalendarDate): number;
51
+ getDaysInMonth(date: AnyCalendarDate): number;
52
+ getDaysInYear(date: AnyCalendarDate): number;
53
+ }
54
+ //#endregion
55
+ export { IslamicCivilCalendar, IslamicTabularCalendar, IslamicUmalquraCalendar };