@timestamp-js/calendar-hebrew 0.1.0-rc.4
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 +21 -0
- package/README.md +65 -0
- package/dist/index.d.ts +43 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.global.js +358 -0
- package/dist/index.global.min.js +1 -0
- package/dist/index.js +278 -0
- package/dist/index.js.map +1 -0
- package/package.json +71 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Jeff Galbraith
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# @timestamp-js/calendar-hebrew
|
|
2
|
+
|
|
3
|
+
Hebrew calendar adapter for `@timestamp-js/core`.
|
|
4
|
+
|
|
5
|
+
The adapter is `hebrewCalendar`, with `jewishCalendar` as a convenience alias. It models the
|
|
6
|
+
deterministic arithmetic Hebrew calendar and uses civil/CLDR month numbering for model dates:
|
|
7
|
+
Tishrei is month `1`, Shevat is month `5`, Adar is month `6` in common years, and leap years insert
|
|
8
|
+
Adar II as month `7` before Nisan.
|
|
9
|
+
|
|
10
|
+
```ts
|
|
11
|
+
import {
|
|
12
|
+
createCalendarDayList,
|
|
13
|
+
getCalendarEndOfMonth,
|
|
14
|
+
getCalendarEndOfWeek,
|
|
15
|
+
getCalendarStartOfMonth,
|
|
16
|
+
getCalendarStartOfWeek,
|
|
17
|
+
gregorianCalendar,
|
|
18
|
+
parseCalendarTimestamp,
|
|
19
|
+
} from '@timestamp-js/core'
|
|
20
|
+
import { hebrewCalendar } from '@timestamp-js/calendar-hebrew'
|
|
21
|
+
|
|
22
|
+
const roshHashanah = { year: 5785, month: 1, day: 1 }
|
|
23
|
+
const gregorian = gregorianCalendar.fromEpochDay(hebrewCalendar.toEpochDay(roshHashanah))
|
|
24
|
+
|
|
25
|
+
gregorian // { year: 2024, month: 10, day: 3 }
|
|
26
|
+
|
|
27
|
+
const visible = parseCalendarTimestamp('5785-01-15', hebrewCalendar)!
|
|
28
|
+
const weekdays = [0, 1, 2, 3, 4, 5, 6]
|
|
29
|
+
|
|
30
|
+
const weekStart = getCalendarStartOfWeek(visible, weekdays, hebrewCalendar)
|
|
31
|
+
const weekEnd = getCalendarEndOfWeek(visible, weekdays, hebrewCalendar)
|
|
32
|
+
const weekDays = createCalendarDayList(weekStart, weekEnd, visible, hebrewCalendar)
|
|
33
|
+
|
|
34
|
+
weekStart.date // '5785-01-11'
|
|
35
|
+
weekEnd.date // '5785-01-17'
|
|
36
|
+
weekDays.length // 7
|
|
37
|
+
|
|
38
|
+
const monthStart = getCalendarStartOfMonth(visible, hebrewCalendar)
|
|
39
|
+
const monthEnd = getCalendarEndOfMonth(visible, hebrewCalendar)
|
|
40
|
+
const monthDays = createCalendarDayList(monthStart, monthEnd, visible, hebrewCalendar)
|
|
41
|
+
|
|
42
|
+
monthStart.date // '5785-01-01'
|
|
43
|
+
monthEnd.date // '5785-01-30'
|
|
44
|
+
monthDays.length // 30
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Browser Globals
|
|
48
|
+
|
|
49
|
+
For CDN or CodePen usage, load `@timestamp-js/core` before the adapter package:
|
|
50
|
+
|
|
51
|
+
```html
|
|
52
|
+
<script src="https://cdn.jsdelivr.net/npm/@timestamp-js/core@0.1.0-rc.4/dist/index.global.min.js"></script>
|
|
53
|
+
<script src="https://cdn.jsdelivr.net/npm/@timestamp-js/calendar-hebrew@0.1.0-rc.4/dist/index.global.min.js"></script>
|
|
54
|
+
<script>
|
|
55
|
+
const visible = TimestampJsCore.parseCalendarTimestamp(
|
|
56
|
+
'5785-01-15',
|
|
57
|
+
TimestampJsCalendarHebrew.hebrewCalendar,
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
console.log(visible?.calendarId)
|
|
61
|
+
</script>
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
This package is early calendar-adapter work. Treat the adapter contract as release-candidate API
|
|
65
|
+
until `@timestamp-js/core` reaches a stable `1.0.0`.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { CalendarSystem } from '@timestamp-js/core';
|
|
2
|
+
/**
|
|
3
|
+
* Returns true when a Hebrew year contains Adar I and Adar II.
|
|
4
|
+
*
|
|
5
|
+
* @param year Hebrew year number.
|
|
6
|
+
* @returns True when the year has 13 months.
|
|
7
|
+
* @category calendar
|
|
8
|
+
*/
|
|
9
|
+
export declare function isHebrewLeapYear(year: number): boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Returns days in a Hebrew civil month.
|
|
12
|
+
*
|
|
13
|
+
* Timestamp uses civil/CLDR month numbering for Hebrew model dates: Tishrei is
|
|
14
|
+
* month `1`, Shevat is month `5`, Adar is month `6` in common years, and leap
|
|
15
|
+
* years insert Adar II as month `7` before Nisan.
|
|
16
|
+
*
|
|
17
|
+
* @param year Hebrew year number.
|
|
18
|
+
* @param month Hebrew civil month number.
|
|
19
|
+
* @returns Number of days in the month, or `0` for an invalid month number.
|
|
20
|
+
* @category calendar
|
|
21
|
+
*/
|
|
22
|
+
export declare function hebrewDaysInMonth(year: number, month: number): number;
|
|
23
|
+
/**
|
|
24
|
+
* Returns the number of months in a Hebrew year.
|
|
25
|
+
*
|
|
26
|
+
* @param year Hebrew year number.
|
|
27
|
+
* @returns `13` for leap years, otherwise `12`.
|
|
28
|
+
* @category calendar
|
|
29
|
+
*/
|
|
30
|
+
export declare function hebrewMonthsInYear(year: number): number;
|
|
31
|
+
/**
|
|
32
|
+
* Deterministic arithmetic Hebrew calendar adapter.
|
|
33
|
+
*
|
|
34
|
+
* Model dates use civil/CLDR month numbering, where Tishrei is month `1`.
|
|
35
|
+
* Biblical/festival numbering that starts with Nisan is a naming convention,
|
|
36
|
+
* not the native model numbering used by this adapter.
|
|
37
|
+
*/
|
|
38
|
+
export declare const hebrewCalendar: CalendarSystem;
|
|
39
|
+
/**
|
|
40
|
+
* Alias for the default Hebrew calendar adapter exported by this package.
|
|
41
|
+
*/
|
|
42
|
+
export declare const jewishCalendar: CalendarSystem;
|
|
43
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAqB,cAAc,EAAE,MAAM,oBAAoB,CAAA;AA2G3E;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAGtD;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAQrE;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEvD;AAED;;;;;;GAMG;AACH,eAAO,MAAM,cAAc,EAAE,cAwK3B,CAAA;AAEF;;GAEG;AACH,eAAO,MAAM,cAAc,gBAAiB,CAAA"}
|
|
@@ -0,0 +1,358 @@
|
|
|
1
|
+
var TimestampJsCalendarHebrew = (function(exports) {
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
+
|
|
5
|
+
const MILLISECONDS_IN_DAY$1 = 864e5;
|
|
6
|
+
const GREGORIAN_DAYS_IN_MONTH = [
|
|
7
|
+
0,
|
|
8
|
+
31,
|
|
9
|
+
28,
|
|
10
|
+
31,
|
|
11
|
+
30,
|
|
12
|
+
31,
|
|
13
|
+
30,
|
|
14
|
+
31,
|
|
15
|
+
31,
|
|
16
|
+
30,
|
|
17
|
+
31,
|
|
18
|
+
30,
|
|
19
|
+
31
|
|
20
|
+
];
|
|
21
|
+
const GREGORIAN_DAYS_IN_MONTH_LEAP = [
|
|
22
|
+
0,
|
|
23
|
+
31,
|
|
24
|
+
29,
|
|
25
|
+
31,
|
|
26
|
+
30,
|
|
27
|
+
31,
|
|
28
|
+
30,
|
|
29
|
+
31,
|
|
30
|
+
31,
|
|
31
|
+
30,
|
|
32
|
+
31,
|
|
33
|
+
30,
|
|
34
|
+
31
|
|
35
|
+
];
|
|
36
|
+
function fromUtcDate(date) {
|
|
37
|
+
return {
|
|
38
|
+
year: date.getUTCFullYear(),
|
|
39
|
+
month: date.getUTCMonth() + 1,
|
|
40
|
+
day: date.getUTCDate()
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
function toGregorianUtcDate(date) {
|
|
44
|
+
return new Date(Date.UTC(date.year, date.month - 1, date.day));
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const gregorianCalendar = Object.freeze({
|
|
48
|
+
id: "gregorian",
|
|
49
|
+
intlCalendar: "gregory",
|
|
50
|
+
label: "Gregorian",
|
|
51
|
+
defaultLocale: "en-US",
|
|
52
|
+
defaultDirection: "ltr",
|
|
53
|
+
defaultWeekdays: Object.freeze([
|
|
54
|
+
0,
|
|
55
|
+
1,
|
|
56
|
+
2,
|
|
57
|
+
3,
|
|
58
|
+
4,
|
|
59
|
+
5,
|
|
60
|
+
6
|
|
61
|
+
]),
|
|
62
|
+
monthsInYear() {
|
|
63
|
+
return 12;
|
|
64
|
+
},
|
|
65
|
+
isLeapYear(year) {
|
|
66
|
+
return year % 4 === 0 && year % 100 !== 0 || year % 400 === 0;
|
|
67
|
+
},
|
|
68
|
+
daysInMonth(year, month) {
|
|
69
|
+
return this.isLeapYear(year) ? GREGORIAN_DAYS_IN_MONTH_LEAP[month] : GREGORIAN_DAYS_IN_MONTH[month];
|
|
70
|
+
},
|
|
71
|
+
toEpochDay(date) {
|
|
72
|
+
return Math.floor(Date.UTC(date.year, date.month - 1, date.day) / MILLISECONDS_IN_DAY$1);
|
|
73
|
+
},
|
|
74
|
+
fromEpochDay(epochDay) {
|
|
75
|
+
return fromUtcDate(/* @__PURE__ */ new Date(epochDay * MILLISECONDS_IN_DAY$1));
|
|
76
|
+
},
|
|
77
|
+
addDays(date, amount) {
|
|
78
|
+
return this.fromEpochDay(this.toEpochDay(date) + amount);
|
|
79
|
+
},
|
|
80
|
+
nextDay(date) {
|
|
81
|
+
return this.addDays(date, 1);
|
|
82
|
+
},
|
|
83
|
+
prevDay(date) {
|
|
84
|
+
return this.addDays(date, -1);
|
|
85
|
+
},
|
|
86
|
+
getDayOfYear(date) {
|
|
87
|
+
const yearStart = this.toEpochDay({
|
|
88
|
+
year: date.year,
|
|
89
|
+
month: 1,
|
|
90
|
+
day: 1
|
|
91
|
+
});
|
|
92
|
+
return this.toEpochDay(date) - yearStart + 1;
|
|
93
|
+
},
|
|
94
|
+
getWeekday(date) {
|
|
95
|
+
return toGregorianUtcDate(date).getUTCDay();
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
const TIME_CONSTANTS = {
|
|
101
|
+
MILLISECONDS_IN: {
|
|
102
|
+
SECOND: 1e3,
|
|
103
|
+
MINUTE: 6e4,
|
|
104
|
+
HOUR: 36e5,
|
|
105
|
+
DAY: 864e5,
|
|
106
|
+
WEEK: 6048e5
|
|
107
|
+
},
|
|
108
|
+
SECONDS_IN: {
|
|
109
|
+
MINUTE: 60,
|
|
110
|
+
HOUR: 3600,
|
|
111
|
+
DAY: 86400,
|
|
112
|
+
WEEK: 604800
|
|
113
|
+
},
|
|
114
|
+
MINUTES_IN: {
|
|
115
|
+
MINUTE: 1,
|
|
116
|
+
HOUR: 60,
|
|
117
|
+
DAY: 1440,
|
|
118
|
+
WEEK: 10080
|
|
119
|
+
},
|
|
120
|
+
HOURS_IN: {
|
|
121
|
+
DAY: 24,
|
|
122
|
+
WEEK: 168
|
|
123
|
+
},
|
|
124
|
+
DAYS_IN: { WEEK: 7 }
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
const DAYS_IN_WEEK = TIME_CONSTANTS.DAYS_IN.WEEK;
|
|
128
|
+
|
|
129
|
+
const MINUTES_IN_HOUR = TIME_CONSTANTS.MINUTES_IN.HOUR;
|
|
130
|
+
|
|
131
|
+
const HOURS_IN_DAY$1 = TIME_CONSTANTS.HOURS_IN.DAY;
|
|
132
|
+
|
|
133
|
+
const MILLISECONDS_IN_MINUTE = TIME_CONSTANTS.MILLISECONDS_IN.MINUTE;
|
|
134
|
+
|
|
135
|
+
const MILLISECONDS_IN_SECOND = TIME_CONSTANTS.MILLISECONDS_IN.SECOND;
|
|
136
|
+
|
|
137
|
+
const MILLISECONDS_IN_HOUR = TIME_CONSTANTS.MILLISECONDS_IN.HOUR;
|
|
138
|
+
|
|
139
|
+
const MILLISECONDS_IN_DAY = TIME_CONSTANTS.MILLISECONDS_IN.DAY;
|
|
140
|
+
|
|
141
|
+
const MILLISECONDS_IN_WEEK = TIME_CONSTANTS.MILLISECONDS_IN.WEEK;
|
|
142
|
+
|
|
143
|
+
const SECONDS_IN_MINUTE = TIME_CONSTANTS.SECONDS_IN.MINUTE;
|
|
144
|
+
|
|
145
|
+
const SECONDS_IN_HOUR = TIME_CONSTANTS.SECONDS_IN.HOUR;
|
|
146
|
+
|
|
147
|
+
const SECONDS_IN_DAY = TIME_CONSTANTS.SECONDS_IN.DAY;
|
|
148
|
+
|
|
149
|
+
const Timestamp = freezeTimestamp({
|
|
150
|
+
date: "",
|
|
151
|
+
hasDay: false,
|
|
152
|
+
year: 0,
|
|
153
|
+
month: 0,
|
|
154
|
+
day: 0,
|
|
155
|
+
hasTime: false,
|
|
156
|
+
hour: 0,
|
|
157
|
+
minute: 0,
|
|
158
|
+
weekday: 0,
|
|
159
|
+
doy: 0,
|
|
160
|
+
workweek: 0,
|
|
161
|
+
past: false,
|
|
162
|
+
current: false,
|
|
163
|
+
future: false,
|
|
164
|
+
disabled: false
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
const TimeObject = Object.freeze({
|
|
168
|
+
hour: 0,
|
|
169
|
+
minute: 0
|
|
170
|
+
});
|
|
171
|
+
function freezeTimestamp(timestamp) {
|
|
172
|
+
return Object.freeze({ ...timestamp });
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
const PARTS_IN_HOUR = 1080;
|
|
176
|
+
const HOURS_IN_DAY = 24;
|
|
177
|
+
const MONTHS_IN_COMMON_YEAR = 12;
|
|
178
|
+
const MONTHS_IN_LEAP_YEAR = 13;
|
|
179
|
+
const CIVIL_TO_NISAN_BASED_COMMON = Object.freeze([
|
|
180
|
+
0,
|
|
181
|
+
7,
|
|
182
|
+
8,
|
|
183
|
+
9,
|
|
184
|
+
10,
|
|
185
|
+
11,
|
|
186
|
+
12,
|
|
187
|
+
1,
|
|
188
|
+
2,
|
|
189
|
+
3,
|
|
190
|
+
4,
|
|
191
|
+
5,
|
|
192
|
+
6
|
|
193
|
+
]);
|
|
194
|
+
const CIVIL_TO_NISAN_BASED_LEAP = Object.freeze([
|
|
195
|
+
0,
|
|
196
|
+
7,
|
|
197
|
+
8,
|
|
198
|
+
9,
|
|
199
|
+
10,
|
|
200
|
+
11,
|
|
201
|
+
12,
|
|
202
|
+
13,
|
|
203
|
+
1,
|
|
204
|
+
2,
|
|
205
|
+
3,
|
|
206
|
+
4,
|
|
207
|
+
5,
|
|
208
|
+
6
|
|
209
|
+
]);
|
|
210
|
+
const HEBREW_EPOCH_DAY = -2092591;
|
|
211
|
+
function assertPositiveYear(year) {
|
|
212
|
+
if (year < 1) throw new RangeError("Hebrew calendar years start at 1 AM.");
|
|
213
|
+
}
|
|
214
|
+
function getHebrewCalendarElapsedDays(year) {
|
|
215
|
+
assertPositiveYear(year);
|
|
216
|
+
const cycleYear = (year - 1) % 19;
|
|
217
|
+
const monthsElapsed = 235 * Math.floor((year - 1) / 19) + 12 * cycleYear + Math.floor((7 * cycleYear + 1) / 19);
|
|
218
|
+
const partsElapsed = 204 + 793 * (monthsElapsed % PARTS_IN_HOUR);
|
|
219
|
+
const hoursElapsed = 5 + 12 * monthsElapsed + 793 * Math.floor(monthsElapsed / PARTS_IN_HOUR) + Math.floor(partsElapsed / PARTS_IN_HOUR);
|
|
220
|
+
let day = 1 + 29 * monthsElapsed + Math.floor(hoursElapsed / HOURS_IN_DAY);
|
|
221
|
+
const parts = PARTS_IN_HOUR * (hoursElapsed % HOURS_IN_DAY) + partsElapsed % PARTS_IN_HOUR;
|
|
222
|
+
if (parts >= 18 * PARTS_IN_HOUR || day % 7 === 2 && parts >= 9924 && isHebrewLeapYear(year) !== true || year > 1 && day % 7 === 1 && parts >= 16789 && isHebrewLeapYear(year - 1) === true) day += 1;
|
|
223
|
+
if (day % 7 === 0 || day % 7 === 3 || day % 7 === 5) day += 1;
|
|
224
|
+
return day;
|
|
225
|
+
}
|
|
226
|
+
function getYearStartEpochDay(year) {
|
|
227
|
+
return HEBREW_EPOCH_DAY + getHebrewCalendarElapsedDays(year);
|
|
228
|
+
}
|
|
229
|
+
function getDaysInHebrewYear(year) {
|
|
230
|
+
return getYearStartEpochDay(year + 1) - getYearStartEpochDay(year);
|
|
231
|
+
}
|
|
232
|
+
function isLongHeshvan(year) {
|
|
233
|
+
return getDaysInHebrewYear(year) % 10 === 5;
|
|
234
|
+
}
|
|
235
|
+
function isShortKislev(year) {
|
|
236
|
+
return getDaysInHebrewYear(year) % 10 === 3;
|
|
237
|
+
}
|
|
238
|
+
function getNisanBasedMonth(year, civilMonth) {
|
|
239
|
+
return isHebrewLeapYear(year) === true ? CIVIL_TO_NISAN_BASED_LEAP[civilMonth] : CIVIL_TO_NISAN_BASED_COMMON[civilMonth];
|
|
240
|
+
}
|
|
241
|
+
function getDaysInNisanBasedMonth(year, month) {
|
|
242
|
+
if (month < 1 || month > MONTHS_IN_LEAP_YEAR) return 0;
|
|
243
|
+
if (month === 2 || month === 4 || month === 6 || month === 10 || month === 13 || month === 12 && isHebrewLeapYear(year) !== true || month === 8 && isLongHeshvan(year) !== true || month === 9 && isShortKislev(year) === true) return 29;
|
|
244
|
+
return 30;
|
|
245
|
+
}
|
|
246
|
+
function getDaysBeforeCivilMonth(year, month) {
|
|
247
|
+
let days = 0;
|
|
248
|
+
for (let currentMonth = 1; currentMonth < month; currentMonth += 1) days += hebrewDaysInMonth(year, currentMonth);
|
|
249
|
+
return days;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
function isHebrewLeapYear(year) {
|
|
253
|
+
assertPositiveYear(year);
|
|
254
|
+
return (7 * year + 1) % 19 < 7;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
function hebrewDaysInMonth(year, month) {
|
|
258
|
+
assertPositiveYear(year);
|
|
259
|
+
if (month < 1 || month > hebrewMonthsInYear(year)) return 0;
|
|
260
|
+
return getDaysInNisanBasedMonth(year, getNisanBasedMonth(year, month));
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
function hebrewMonthsInYear(year) {
|
|
264
|
+
return isHebrewLeapYear(year) === true ? MONTHS_IN_LEAP_YEAR : MONTHS_IN_COMMON_YEAR;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
const hebrewCalendar = Object.freeze({
|
|
268
|
+
|
|
269
|
+
id: "hebrew",
|
|
270
|
+
|
|
271
|
+
intlCalendar: "hebrew",
|
|
272
|
+
|
|
273
|
+
label: "Hebrew",
|
|
274
|
+
|
|
275
|
+
defaultLocale: "he-IL",
|
|
276
|
+
|
|
277
|
+
defaultDirection: "rtl",
|
|
278
|
+
|
|
279
|
+
defaultWeekdays: Object.freeze([
|
|
280
|
+
0,
|
|
281
|
+
1,
|
|
282
|
+
2,
|
|
283
|
+
3,
|
|
284
|
+
4,
|
|
285
|
+
5,
|
|
286
|
+
6
|
|
287
|
+
]),
|
|
288
|
+
|
|
289
|
+
monthsInYear(year) {
|
|
290
|
+
return hebrewMonthsInYear(year);
|
|
291
|
+
},
|
|
292
|
+
|
|
293
|
+
isLeapYear(year) {
|
|
294
|
+
return isHebrewLeapYear(year);
|
|
295
|
+
},
|
|
296
|
+
|
|
297
|
+
daysInMonth(year, month) {
|
|
298
|
+
return hebrewDaysInMonth(year, month);
|
|
299
|
+
},
|
|
300
|
+
|
|
301
|
+
toEpochDay(date) {
|
|
302
|
+
assertPositiveYear(date.year);
|
|
303
|
+
return getYearStartEpochDay(date.year) + getDaysBeforeCivilMonth(date.year, date.month) + date.day - 1;
|
|
304
|
+
},
|
|
305
|
+
|
|
306
|
+
fromEpochDay(epochDay) {
|
|
307
|
+
let year = gregorianCalendar.fromEpochDay(epochDay).year + 3761;
|
|
308
|
+
while (getYearStartEpochDay(year + 1) <= epochDay) year += 1;
|
|
309
|
+
while (getYearStartEpochDay(year) > epochDay) year -= 1;
|
|
310
|
+
let dayOfYear = epochDay - getYearStartEpochDay(year);
|
|
311
|
+
let month = 1;
|
|
312
|
+
while (month < this.monthsInYear(year)) {
|
|
313
|
+
const daysInCurrentMonth = this.daysInMonth(year, month);
|
|
314
|
+
if (dayOfYear < daysInCurrentMonth) break;
|
|
315
|
+
dayOfYear -= daysInCurrentMonth;
|
|
316
|
+
month += 1;
|
|
317
|
+
}
|
|
318
|
+
return {
|
|
319
|
+
year,
|
|
320
|
+
month,
|
|
321
|
+
day: dayOfYear + 1
|
|
322
|
+
};
|
|
323
|
+
},
|
|
324
|
+
|
|
325
|
+
addDays(date, amount) {
|
|
326
|
+
return this.fromEpochDay(this.toEpochDay(date) + amount);
|
|
327
|
+
},
|
|
328
|
+
|
|
329
|
+
nextDay(date) {
|
|
330
|
+
return this.addDays(date, 1);
|
|
331
|
+
},
|
|
332
|
+
|
|
333
|
+
prevDay(date) {
|
|
334
|
+
return this.addDays(date, -1);
|
|
335
|
+
},
|
|
336
|
+
|
|
337
|
+
getDayOfYear(date) {
|
|
338
|
+
return this.toEpochDay(date) - this.toEpochDay({
|
|
339
|
+
year: date.year,
|
|
340
|
+
month: 1,
|
|
341
|
+
day: 1
|
|
342
|
+
}) + 1;
|
|
343
|
+
},
|
|
344
|
+
|
|
345
|
+
getWeekday(date) {
|
|
346
|
+
return gregorianCalendar.getWeekday(gregorianCalendar.fromEpochDay(this.toEpochDay(date)));
|
|
347
|
+
}
|
|
348
|
+
});
|
|
349
|
+
|
|
350
|
+
const jewishCalendar = hebrewCalendar;
|
|
351
|
+
|
|
352
|
+
exports.hebrewCalendar = hebrewCalendar;
|
|
353
|
+
exports.hebrewDaysInMonth = hebrewDaysInMonth;
|
|
354
|
+
exports.hebrewMonthsInYear = hebrewMonthsInYear;
|
|
355
|
+
exports.isHebrewLeapYear = isHebrewLeapYear;
|
|
356
|
+
exports.jewishCalendar = jewishCalendar;
|
|
357
|
+
return exports;
|
|
358
|
+
})({});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var TimestampJsCalendarHebrew=(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});let t=864e5,n=[0,31,28,31,30,31,30,31,31,30,31,30,31],r=[0,31,29,31,30,31,30,31,31,30,31,30,31];function i(e){return{year:e.getUTCFullYear(),month:e.getUTCMonth()+1,day:e.getUTCDate()}}function a(e){return new Date(Date.UTC(e.year,e.month-1,e.day))}let o=Object.freeze({id:`gregorian`,intlCalendar:`gregory`,label:`Gregorian`,defaultLocale:`en-US`,defaultDirection:`ltr`,defaultWeekdays:Object.freeze([0,1,2,3,4,5,6]),monthsInYear(){return 12},isLeapYear(e){return e%4==0&&e%100!=0||e%400==0},daysInMonth(e,t){return this.isLeapYear(e)?r[t]:n[t]},toEpochDay(e){return Math.floor(Date.UTC(e.year,e.month-1,e.day)/t)},fromEpochDay(e){return i(new Date(e*t))},addDays(e,t){return this.fromEpochDay(this.toEpochDay(e)+t)},nextDay(e){return this.addDays(e,1)},prevDay(e){return this.addDays(e,-1)},getDayOfYear(e){let t=this.toEpochDay({year:e.year,month:1,day:1});return this.toEpochDay(e)-t+1},getWeekday(e){return a(e).getUTCDay()}}),s={MILLISECONDS_IN:{SECOND:1e3,MINUTE:6e4,HOUR:36e5,DAY:864e5,WEEK:6048e5},SECONDS_IN:{MINUTE:60,HOUR:3600,DAY:86400,WEEK:604800},MINUTES_IN:{MINUTE:1,HOUR:60,DAY:1440,WEEK:10080},HOURS_IN:{DAY:24,WEEK:168},DAYS_IN:{WEEK:7}};s.DAYS_IN.WEEK,s.MINUTES_IN.HOUR,s.HOURS_IN.DAY,s.MILLISECONDS_IN.MINUTE,s.MILLISECONDS_IN.SECOND,s.MILLISECONDS_IN.HOUR,s.MILLISECONDS_IN.DAY,s.MILLISECONDS_IN.WEEK,s.SECONDS_IN.MINUTE,s.SECONDS_IN.HOUR,s.SECONDS_IN.DAY,c({date:``,hasDay:!1,year:0,month:0,day:0,hasTime:!1,hour:0,minute:0,weekday:0,doy:0,workweek:0,past:!1,current:!1,future:!1,disabled:!1}),Object.freeze({hour:0,minute:0});function c(e){return Object.freeze({...e})}let l=1080,u=Object.freeze([0,7,8,9,10,11,12,1,2,3,4,5,6]),d=Object.freeze([0,7,8,9,10,11,12,13,1,2,3,4,5,6]);function f(e){if(e<1)throw RangeError(`Hebrew calendar years start at 1 AM.`)}function p(e){f(e);let t=(e-1)%19,n=235*Math.floor((e-1)/19)+12*t+Math.floor((7*t+1)/19),r=204+n%l*793,i=5+12*n+793*Math.floor(n/l)+Math.floor(r/l),a=1+29*n+Math.floor(i/24),o=i%24*l+r%l;return(o>=18*l||a%7==2&&o>=9924&&x(e)!==!0||e>1&&a%7==1&&o>=16789&&x(e-1)===!0)&&(a+=1),(a%7==0||a%7==3||a%7==5)&&(a+=1),a}function m(e){return-2092591+p(e)}function h(e){return m(e+1)-m(e)}function g(e){return h(e)%10==5}function _(e){return h(e)%10==3}function v(e,t){return x(e)===!0?d[t]:u[t]}function y(e,t){return t<1||t>13?0:t===2||t===4||t===6||t===10||t===13||t===12&&x(e)!==!0||t===8&&g(e)!==!0||t===9&&_(e)===!0?29:30}function b(e,t){let n=0;for(let r=1;r<t;r+=1)n+=S(e,r);return n}function x(e){return f(e),(7*e+1)%19<7}function S(e,t){return f(e),t<1||t>C(e)?0:y(e,v(e,t))}function C(e){return x(e)===!0?13:12}let w=Object.freeze({id:`hebrew`,intlCalendar:`hebrew`,label:`Hebrew`,defaultLocale:`he-IL`,defaultDirection:`rtl`,defaultWeekdays:Object.freeze([0,1,2,3,4,5,6]),monthsInYear(e){return C(e)},isLeapYear(e){return x(e)},daysInMonth(e,t){return S(e,t)},toEpochDay(e){return f(e.year),m(e.year)+b(e.year,e.month)+e.day-1},fromEpochDay(e){let t=o.fromEpochDay(e).year+3761;for(;m(t+1)<=e;)t+=1;for(;m(t)>e;)--t;let n=e-m(t),r=1;for(;r<this.monthsInYear(t);){let e=this.daysInMonth(t,r);if(n<e)break;n-=e,r+=1}return{year:t,month:r,day:n+1}},addDays(e,t){return this.fromEpochDay(this.toEpochDay(e)+t)},nextDay(e){return this.addDays(e,1)},prevDay(e){return this.addDays(e,-1)},getDayOfYear(e){return this.toEpochDay(e)-this.toEpochDay({year:e.year,month:1,day:1})+1},getWeekday(e){return o.getWeekday(o.fromEpochDay(this.toEpochDay(e)))}}),T=w;return e.hebrewCalendar=w,e.hebrewDaysInMonth=S,e.hebrewMonthsInYear=C,e.isHebrewLeapYear=x,e.jewishCalendar=T,e})({});
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
import { gregorianCalendar } from '@timestamp-js/core';
|
|
2
|
+
const PARTS_IN_HOUR = 1080;
|
|
3
|
+
const HOURS_IN_DAY = 24;
|
|
4
|
+
const MONTHS_IN_COMMON_YEAR = 12;
|
|
5
|
+
const MONTHS_IN_LEAP_YEAR = 13;
|
|
6
|
+
const CIVIL_TO_NISAN_BASED_COMMON = Object.freeze([0, 7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5, 6]);
|
|
7
|
+
const CIVIL_TO_NISAN_BASED_LEAP = Object.freeze([0, 7, 8, 9, 10, 11, 12, 13, 1, 2, 3, 4, 5, 6]);
|
|
8
|
+
// Hebrew calendar epoch relative to Timestamp epoch days, where 1970-01-01 Gregorian is 0.
|
|
9
|
+
const HEBREW_EPOCH_DAY = -2092591;
|
|
10
|
+
function assertPositiveYear(year) {
|
|
11
|
+
if (year < 1) {
|
|
12
|
+
throw new RangeError('Hebrew calendar years start at 1 AM.');
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
function getHebrewCalendarElapsedDays(year) {
|
|
16
|
+
assertPositiveYear(year);
|
|
17
|
+
const cycleYear = (year - 1) % 19;
|
|
18
|
+
const cycles = Math.floor((year - 1) / 19);
|
|
19
|
+
const monthsElapsed = 235 * cycles + 12 * cycleYear + Math.floor((7 * cycleYear + 1) / 19);
|
|
20
|
+
const partsElapsed = 204 + 793 * (monthsElapsed % PARTS_IN_HOUR);
|
|
21
|
+
const hoursElapsed = 5 +
|
|
22
|
+
12 * monthsElapsed +
|
|
23
|
+
793 * Math.floor(monthsElapsed / PARTS_IN_HOUR) +
|
|
24
|
+
Math.floor(partsElapsed / PARTS_IN_HOUR);
|
|
25
|
+
let day = 1 + 29 * monthsElapsed + Math.floor(hoursElapsed / HOURS_IN_DAY);
|
|
26
|
+
const parts = PARTS_IN_HOUR * (hoursElapsed % HOURS_IN_DAY) + (partsElapsed % PARTS_IN_HOUR);
|
|
27
|
+
if (parts >= 18 * PARTS_IN_HOUR ||
|
|
28
|
+
(day % 7 === 2 && parts >= 9 * PARTS_IN_HOUR + 204 && isHebrewLeapYear(year) !== true) ||
|
|
29
|
+
(year > 1 &&
|
|
30
|
+
day % 7 === 1 &&
|
|
31
|
+
parts >= 15 * PARTS_IN_HOUR + 589 &&
|
|
32
|
+
isHebrewLeapYear(year - 1) === true)) {
|
|
33
|
+
day += 1;
|
|
34
|
+
}
|
|
35
|
+
if (day % 7 === 0 || day % 7 === 3 || day % 7 === 5) {
|
|
36
|
+
day += 1;
|
|
37
|
+
}
|
|
38
|
+
return day;
|
|
39
|
+
}
|
|
40
|
+
function getYearStartEpochDay(year) {
|
|
41
|
+
return HEBREW_EPOCH_DAY + getHebrewCalendarElapsedDays(year);
|
|
42
|
+
}
|
|
43
|
+
function getDaysInHebrewYear(year) {
|
|
44
|
+
return getYearStartEpochDay(year + 1) - getYearStartEpochDay(year);
|
|
45
|
+
}
|
|
46
|
+
function isLongHeshvan(year) {
|
|
47
|
+
return getDaysInHebrewYear(year) % 10 === 5;
|
|
48
|
+
}
|
|
49
|
+
function isShortKislev(year) {
|
|
50
|
+
return getDaysInHebrewYear(year) % 10 === 3;
|
|
51
|
+
}
|
|
52
|
+
function getNisanBasedMonth(year, civilMonth) {
|
|
53
|
+
return (isHebrewLeapYear(year) === true
|
|
54
|
+
? CIVIL_TO_NISAN_BASED_LEAP[civilMonth]
|
|
55
|
+
: CIVIL_TO_NISAN_BASED_COMMON[civilMonth]);
|
|
56
|
+
}
|
|
57
|
+
function getDaysInNisanBasedMonth(year, month) {
|
|
58
|
+
if (month < 1 || month > MONTHS_IN_LEAP_YEAR) {
|
|
59
|
+
return 0;
|
|
60
|
+
}
|
|
61
|
+
if (month === 2 ||
|
|
62
|
+
month === 4 ||
|
|
63
|
+
month === 6 ||
|
|
64
|
+
month === 10 ||
|
|
65
|
+
month === 13 ||
|
|
66
|
+
(month === 12 && isHebrewLeapYear(year) !== true) ||
|
|
67
|
+
(month === 8 && isLongHeshvan(year) !== true) ||
|
|
68
|
+
(month === 9 && isShortKislev(year) === true)) {
|
|
69
|
+
return 29;
|
|
70
|
+
}
|
|
71
|
+
return 30;
|
|
72
|
+
}
|
|
73
|
+
function getDaysBeforeCivilMonth(year, month) {
|
|
74
|
+
let days = 0;
|
|
75
|
+
for (let currentMonth = 1; currentMonth < month; currentMonth += 1) {
|
|
76
|
+
days += hebrewDaysInMonth(year, currentMonth);
|
|
77
|
+
}
|
|
78
|
+
return days;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Returns true when a Hebrew year contains Adar I and Adar II.
|
|
82
|
+
*
|
|
83
|
+
* @param year Hebrew year number.
|
|
84
|
+
* @returns True when the year has 13 months.
|
|
85
|
+
* @category calendar
|
|
86
|
+
*/
|
|
87
|
+
export function isHebrewLeapYear(year) {
|
|
88
|
+
assertPositiveYear(year);
|
|
89
|
+
return (7 * year + 1) % 19 < 7;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Returns days in a Hebrew civil month.
|
|
93
|
+
*
|
|
94
|
+
* Timestamp uses civil/CLDR month numbering for Hebrew model dates: Tishrei is
|
|
95
|
+
* month `1`, Shevat is month `5`, Adar is month `6` in common years, and leap
|
|
96
|
+
* years insert Adar II as month `7` before Nisan.
|
|
97
|
+
*
|
|
98
|
+
* @param year Hebrew year number.
|
|
99
|
+
* @param month Hebrew civil month number.
|
|
100
|
+
* @returns Number of days in the month, or `0` for an invalid month number.
|
|
101
|
+
* @category calendar
|
|
102
|
+
*/
|
|
103
|
+
export function hebrewDaysInMonth(year, month) {
|
|
104
|
+
assertPositiveYear(year);
|
|
105
|
+
if (month < 1 || month > hebrewMonthsInYear(year)) {
|
|
106
|
+
return 0;
|
|
107
|
+
}
|
|
108
|
+
return getDaysInNisanBasedMonth(year, getNisanBasedMonth(year, month));
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Returns the number of months in a Hebrew year.
|
|
112
|
+
*
|
|
113
|
+
* @param year Hebrew year number.
|
|
114
|
+
* @returns `13` for leap years, otherwise `12`.
|
|
115
|
+
* @category calendar
|
|
116
|
+
*/
|
|
117
|
+
export function hebrewMonthsInYear(year) {
|
|
118
|
+
return isHebrewLeapYear(year) === true ? MONTHS_IN_LEAP_YEAR : MONTHS_IN_COMMON_YEAR;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Deterministic arithmetic Hebrew calendar adapter.
|
|
122
|
+
*
|
|
123
|
+
* Model dates use civil/CLDR month numbering, where Tishrei is month `1`.
|
|
124
|
+
* Biblical/festival numbering that starts with Nisan is a naming convention,
|
|
125
|
+
* not the native model numbering used by this adapter.
|
|
126
|
+
*/
|
|
127
|
+
export const hebrewCalendar = Object.freeze({
|
|
128
|
+
/**
|
|
129
|
+
* Package-facing id for the Hebrew calendar adapter.
|
|
130
|
+
*/
|
|
131
|
+
id: 'hebrew',
|
|
132
|
+
/**
|
|
133
|
+
* Intl calendar id for Hebrew calendar formatting.
|
|
134
|
+
*/
|
|
135
|
+
intlCalendar: 'hebrew',
|
|
136
|
+
/**
|
|
137
|
+
* Human-readable adapter name.
|
|
138
|
+
*/
|
|
139
|
+
label: 'Hebrew',
|
|
140
|
+
/**
|
|
141
|
+
* Default locale used for Hebrew calendar presentation.
|
|
142
|
+
*/
|
|
143
|
+
defaultLocale: 'he-IL',
|
|
144
|
+
/**
|
|
145
|
+
* Default text direction for Hebrew calendar presentation.
|
|
146
|
+
*/
|
|
147
|
+
defaultDirection: 'rtl',
|
|
148
|
+
/**
|
|
149
|
+
* Default visible week order for Hebrew calendar presentation: Sunday through Saturday.
|
|
150
|
+
*
|
|
151
|
+
* Weekdays use JavaScript numbering, where Sunday is `0` and Saturday is `6`.
|
|
152
|
+
*/
|
|
153
|
+
defaultWeekdays: Object.freeze([0, 1, 2, 3, 4, 5, 6]),
|
|
154
|
+
/**
|
|
155
|
+
* Returns the number of months in a Hebrew year.
|
|
156
|
+
*
|
|
157
|
+
* @param year Hebrew year number.
|
|
158
|
+
* @returns Number of months in the year.
|
|
159
|
+
*/
|
|
160
|
+
monthsInYear(year) {
|
|
161
|
+
return hebrewMonthsInYear(year);
|
|
162
|
+
},
|
|
163
|
+
/**
|
|
164
|
+
* Returns true when the Hebrew year contains Adar I and Adar II.
|
|
165
|
+
*
|
|
166
|
+
* @param year Hebrew year number.
|
|
167
|
+
* @returns True when the year has 13 months.
|
|
168
|
+
*/
|
|
169
|
+
isLeapYear(year) {
|
|
170
|
+
return isHebrewLeapYear(year);
|
|
171
|
+
},
|
|
172
|
+
/**
|
|
173
|
+
* Returns the number of days in a Hebrew civil month.
|
|
174
|
+
*
|
|
175
|
+
* @param year Hebrew year number.
|
|
176
|
+
* @param month Hebrew civil month number, where Tishrei is `1`.
|
|
177
|
+
* @returns Number of days in the month, or `0` for an invalid month number.
|
|
178
|
+
*/
|
|
179
|
+
daysInMonth(year, month) {
|
|
180
|
+
return hebrewDaysInMonth(year, month);
|
|
181
|
+
},
|
|
182
|
+
/**
|
|
183
|
+
* Converts a Hebrew civil date into the equivalent epoch day.
|
|
184
|
+
*
|
|
185
|
+
* @param date Hebrew civil date fields.
|
|
186
|
+
* @returns Epoch day for the equivalent civil instant.
|
|
187
|
+
*/
|
|
188
|
+
toEpochDay(date) {
|
|
189
|
+
assertPositiveYear(date.year);
|
|
190
|
+
return (getYearStartEpochDay(date.year) +
|
|
191
|
+
getDaysBeforeCivilMonth(date.year, date.month) +
|
|
192
|
+
date.day -
|
|
193
|
+
1);
|
|
194
|
+
},
|
|
195
|
+
/**
|
|
196
|
+
* Converts an epoch day into Hebrew civil date fields.
|
|
197
|
+
*
|
|
198
|
+
* @param epochDay Epoch day to convert.
|
|
199
|
+
* @returns Hebrew civil date fields.
|
|
200
|
+
*/
|
|
201
|
+
fromEpochDay(epochDay) {
|
|
202
|
+
const gregorianDate = gregorianCalendar.fromEpochDay(epochDay);
|
|
203
|
+
let year = gregorianDate.year + 3761;
|
|
204
|
+
while (getYearStartEpochDay(year + 1) <= epochDay) {
|
|
205
|
+
year += 1;
|
|
206
|
+
}
|
|
207
|
+
while (getYearStartEpochDay(year) > epochDay) {
|
|
208
|
+
year -= 1;
|
|
209
|
+
}
|
|
210
|
+
const yearStart = getYearStartEpochDay(year);
|
|
211
|
+
let dayOfYear = epochDay - yearStart;
|
|
212
|
+
let month = 1;
|
|
213
|
+
while (month < this.monthsInYear(year)) {
|
|
214
|
+
const daysInCurrentMonth = this.daysInMonth(year, month);
|
|
215
|
+
if (dayOfYear < daysInCurrentMonth) {
|
|
216
|
+
break;
|
|
217
|
+
}
|
|
218
|
+
dayOfYear -= daysInCurrentMonth;
|
|
219
|
+
month += 1;
|
|
220
|
+
}
|
|
221
|
+
return {
|
|
222
|
+
year,
|
|
223
|
+
month,
|
|
224
|
+
day: dayOfYear + 1,
|
|
225
|
+
};
|
|
226
|
+
},
|
|
227
|
+
/**
|
|
228
|
+
* Moves a Hebrew civil date by a whole number of days.
|
|
229
|
+
*
|
|
230
|
+
* @param date Hebrew civil date fields.
|
|
231
|
+
* @param amount Number of days to add. Negative values move backward.
|
|
232
|
+
* @returns Shifted Hebrew civil date fields.
|
|
233
|
+
*/
|
|
234
|
+
addDays(date, amount) {
|
|
235
|
+
return this.fromEpochDay(this.toEpochDay(date) + amount);
|
|
236
|
+
},
|
|
237
|
+
/**
|
|
238
|
+
* Returns the next Hebrew civil date.
|
|
239
|
+
*
|
|
240
|
+
* @param date Hebrew civil date fields.
|
|
241
|
+
* @returns Date fields for the following day.
|
|
242
|
+
*/
|
|
243
|
+
nextDay(date) {
|
|
244
|
+
return this.addDays(date, 1);
|
|
245
|
+
},
|
|
246
|
+
/**
|
|
247
|
+
* Returns the previous Hebrew civil date.
|
|
248
|
+
*
|
|
249
|
+
* @param date Hebrew civil date fields.
|
|
250
|
+
* @returns Date fields for the previous day.
|
|
251
|
+
*/
|
|
252
|
+
prevDay(date) {
|
|
253
|
+
return this.addDays(date, -1);
|
|
254
|
+
},
|
|
255
|
+
/**
|
|
256
|
+
* Returns the one-based day-of-year for a Hebrew civil date.
|
|
257
|
+
*
|
|
258
|
+
* @param date Hebrew civil date fields.
|
|
259
|
+
* @returns One-based day-of-year.
|
|
260
|
+
*/
|
|
261
|
+
getDayOfYear(date) {
|
|
262
|
+
return this.toEpochDay(date) - this.toEpochDay({ year: date.year, month: 1, day: 1 }) + 1;
|
|
263
|
+
},
|
|
264
|
+
/**
|
|
265
|
+
* Returns the weekday for a Hebrew civil date using JavaScript weekday numbering.
|
|
266
|
+
*
|
|
267
|
+
* @param date Hebrew civil date fields.
|
|
268
|
+
* @returns Weekday number where Sunday is `0` and Saturday is `6`.
|
|
269
|
+
*/
|
|
270
|
+
getWeekday(date) {
|
|
271
|
+
return gregorianCalendar.getWeekday(gregorianCalendar.fromEpochDay(this.toEpochDay(date)));
|
|
272
|
+
},
|
|
273
|
+
});
|
|
274
|
+
/**
|
|
275
|
+
* Alias for the default Hebrew calendar adapter exported by this package.
|
|
276
|
+
*/
|
|
277
|
+
export const jewishCalendar = hebrewCalendar;
|
|
278
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAA;AAGtD,MAAM,aAAa,GAAG,IAAI,CAAA;AAC1B,MAAM,YAAY,GAAG,EAAE,CAAA;AACvB,MAAM,qBAAqB,GAAG,EAAE,CAAA;AAChC,MAAM,mBAAmB,GAAG,EAAE,CAAA;AAE9B,MAAM,2BAA2B,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,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"keywords": [
|
|
6
|
+
"calendar",
|
|
7
|
+
"date",
|
|
8
|
+
"hebrew",
|
|
9
|
+
"jewish",
|
|
10
|
+
"timestamp",
|
|
11
|
+
"typescript"
|
|
12
|
+
],
|
|
13
|
+
"homepage": "https://github.com/hawkeye64/timestamp#readme",
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://github.com/hawkeye64/timestamp/issues"
|
|
16
|
+
},
|
|
17
|
+
"license": "MIT",
|
|
18
|
+
"author": "Jeff <galbraith64@gmail.com>",
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "git+https://github.com/hawkeye64/timestamp.git"
|
|
22
|
+
},
|
|
23
|
+
"files": [
|
|
24
|
+
"dist",
|
|
25
|
+
"README.md",
|
|
26
|
+
"LICENSE"
|
|
27
|
+
],
|
|
28
|
+
"type": "module",
|
|
29
|
+
"sideEffects": false,
|
|
30
|
+
"main": "./dist/index.js",
|
|
31
|
+
"types": "./dist/index.d.ts",
|
|
32
|
+
"unpkg": "./dist/index.global.min.js",
|
|
33
|
+
"jsdelivr": "./dist/index.global.min.js",
|
|
34
|
+
"exports": {
|
|
35
|
+
".": {
|
|
36
|
+
"types": "./dist/index.d.ts",
|
|
37
|
+
"import": "./dist/index.js"
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
"publishConfig": {
|
|
41
|
+
"access": "public"
|
|
42
|
+
},
|
|
43
|
+
"dependencies": {
|
|
44
|
+
"@timestamp-js/core": "0.1.0-rc.4"
|
|
45
|
+
},
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"@types/node": "26.0.1",
|
|
48
|
+
"oxfmt": "0.57.0",
|
|
49
|
+
"oxlint": "1.72.0",
|
|
50
|
+
"typescript": "6.0.3",
|
|
51
|
+
"vitest": "4.1.9"
|
|
52
|
+
},
|
|
53
|
+
"engines": {
|
|
54
|
+
"node": ">=22.13",
|
|
55
|
+
"pnpm": ">=11.5.0"
|
|
56
|
+
},
|
|
57
|
+
"scripts": {
|
|
58
|
+
"clean": "rm -rf dist node_modules",
|
|
59
|
+
"prebuild": "pnpm --filter @timestamp-js/core build",
|
|
60
|
+
"build": "node ../../scripts/build-browser-globals.mjs @timestamp-js/calendar-hebrew && tsc -p tsconfig.build.json",
|
|
61
|
+
"format": "oxfmt",
|
|
62
|
+
"format:check": "oxfmt --check",
|
|
63
|
+
"lint": "oxlint",
|
|
64
|
+
"lint:fix": "oxlint --fix",
|
|
65
|
+
"pretest": "pnpm --filter @timestamp-js/core build",
|
|
66
|
+
"test": "vitest run",
|
|
67
|
+
"pretypecheck": "pnpm --filter @timestamp-js/core build",
|
|
68
|
+
"typecheck": "tsc -p tsconfig.build.json --noEmit",
|
|
69
|
+
"verify": "pnpm format:check && pnpm lint && pnpm typecheck && pnpm test && pnpm build"
|
|
70
|
+
}
|
|
71
|
+
}
|