@timestamp-js/calendar-islamic 0.1.0-rc.1 → 0.1.0-rc.3
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/README.md +17 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.global.js +307 -0
- package/dist/index.global.min.js +1 -0
- package/dist/index.js +84 -0
- package/dist/index.js.map +1 -1
- package/package.json +7 -5
package/README.md
CHANGED
|
@@ -42,5 +42,22 @@ monthEnd.date // '1445-09-30'
|
|
|
42
42
|
monthDays.length // 30
|
|
43
43
|
```
|
|
44
44
|
|
|
45
|
+
## Browser Globals
|
|
46
|
+
|
|
47
|
+
For CDN or CodePen usage, load `@timestamp-js/core` before the adapter package:
|
|
48
|
+
|
|
49
|
+
```html
|
|
50
|
+
<script src="https://cdn.jsdelivr.net/npm/@timestamp-js/core@0.1.0-rc.3/dist/index.global.min.js"></script>
|
|
51
|
+
<script src="https://cdn.jsdelivr.net/npm/@timestamp-js/calendar-islamic@0.1.0-rc.3/dist/index.global.min.js"></script>
|
|
52
|
+
<script>
|
|
53
|
+
const visible = TimestampJsCore.parseCalendarTimestamp(
|
|
54
|
+
'1445-09-15',
|
|
55
|
+
TimestampJsCalendarIslamic.islamicCivilCalendar,
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
console.log(visible?.calendarId)
|
|
59
|
+
</script>
|
|
60
|
+
```
|
|
61
|
+
|
|
45
62
|
This package is early calendar-adapter work. Treat the adapter contract as release-candidate API
|
|
46
63
|
until `@timestamp-js/core` reaches a stable `1.0.0`.
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAqB,cAAc,EAAE,MAAM,oBAAoB,CAAA;AAoB3E;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAG5D;AAED;;;;;;;GAOG;AACH,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAY3E;AAED;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAqB,cAAc,EAAE,MAAM,oBAAoB,CAAA;AAoB3E;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAG5D;AAED;;;;;;;GAOG;AACH,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAY3E;AAED;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,EAAE,cAmKjC,CAAA;AAEF;;GAEG;AACH,eAAO,MAAM,eAAe,gBAAuB,CAAA"}
|
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
var TimestampJsCalendarIslamic = (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 = 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 ISLAMIC_EPOCH_DAY = gregorianCalendar.toEpochDay({
|
|
176
|
+
year: 622,
|
|
177
|
+
month: 7,
|
|
178
|
+
day: 19
|
|
179
|
+
});
|
|
180
|
+
const MONTHS_IN_YEAR = 12;
|
|
181
|
+
function assertPositiveYear(year) {
|
|
182
|
+
if (year < 1) throw new RangeError("Islamic calendar years start at 1 AH.");
|
|
183
|
+
}
|
|
184
|
+
function daysBeforeYear(year) {
|
|
185
|
+
assertPositiveYear(year);
|
|
186
|
+
return (year - 1) * 354 + Math.floor((3 + 11 * year) / 30);
|
|
187
|
+
}
|
|
188
|
+
function daysBeforeMonth(month) {
|
|
189
|
+
return Math.ceil(29.5 * (month - 1));
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
function isIslamicCivilLeapYear(year) {
|
|
193
|
+
assertPositiveYear(year);
|
|
194
|
+
return (11 * year + 14) % 30 < 11;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
function islamicCivilDaysInMonth(year, month) {
|
|
198
|
+
assertPositiveYear(year);
|
|
199
|
+
if (month < 1 || month > MONTHS_IN_YEAR) return 0;
|
|
200
|
+
if (month === 12 && isIslamicCivilLeapYear(year) === true) return 30;
|
|
201
|
+
return month % 2 === 1 ? 30 : 29;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
const islamicCivilCalendar = Object.freeze({
|
|
205
|
+
|
|
206
|
+
id: "islamic-civil",
|
|
207
|
+
|
|
208
|
+
intlCalendar: "islamic-civil",
|
|
209
|
+
|
|
210
|
+
label: "Islamic Civil",
|
|
211
|
+
|
|
212
|
+
defaultLocale: "ar",
|
|
213
|
+
|
|
214
|
+
defaultDirection: "rtl",
|
|
215
|
+
|
|
216
|
+
defaultWeekdays: Object.freeze([
|
|
217
|
+
6,
|
|
218
|
+
0,
|
|
219
|
+
1,
|
|
220
|
+
2,
|
|
221
|
+
3,
|
|
222
|
+
4,
|
|
223
|
+
5
|
|
224
|
+
]),
|
|
225
|
+
|
|
226
|
+
monthsInYear() {
|
|
227
|
+
return MONTHS_IN_YEAR;
|
|
228
|
+
},
|
|
229
|
+
|
|
230
|
+
isLeapYear(year) {
|
|
231
|
+
return isIslamicCivilLeapYear(year);
|
|
232
|
+
},
|
|
233
|
+
|
|
234
|
+
daysInMonth(year, month) {
|
|
235
|
+
return islamicCivilDaysInMonth(year, month);
|
|
236
|
+
},
|
|
237
|
+
|
|
238
|
+
toEpochDay(date) {
|
|
239
|
+
assertPositiveYear(date.year);
|
|
240
|
+
return ISLAMIC_EPOCH_DAY + daysBeforeYear(date.year) + daysBeforeMonth(date.month) + date.day - 1;
|
|
241
|
+
},
|
|
242
|
+
|
|
243
|
+
fromEpochDay(epochDay) {
|
|
244
|
+
const days = epochDay - ISLAMIC_EPOCH_DAY;
|
|
245
|
+
let year = Math.floor((30 * days + 10646) / 10631);
|
|
246
|
+
while (year > 1 && this.toEpochDay({
|
|
247
|
+
year,
|
|
248
|
+
month: 1,
|
|
249
|
+
day: 1
|
|
250
|
+
}) > epochDay) year -= 1;
|
|
251
|
+
while (this.toEpochDay({
|
|
252
|
+
year: year + 1,
|
|
253
|
+
month: 1,
|
|
254
|
+
day: 1
|
|
255
|
+
}) <= epochDay) year += 1;
|
|
256
|
+
let dayOfYear = epochDay - this.toEpochDay({
|
|
257
|
+
year,
|
|
258
|
+
month: 1,
|
|
259
|
+
day: 1
|
|
260
|
+
});
|
|
261
|
+
let month = 1;
|
|
262
|
+
while (month < MONTHS_IN_YEAR) {
|
|
263
|
+
const daysInCurrentMonth = this.daysInMonth(year, month);
|
|
264
|
+
if (dayOfYear < daysInCurrentMonth) break;
|
|
265
|
+
dayOfYear -= daysInCurrentMonth;
|
|
266
|
+
month += 1;
|
|
267
|
+
}
|
|
268
|
+
return {
|
|
269
|
+
year,
|
|
270
|
+
month,
|
|
271
|
+
day: dayOfYear + 1
|
|
272
|
+
};
|
|
273
|
+
},
|
|
274
|
+
|
|
275
|
+
addDays(date, amount) {
|
|
276
|
+
return this.fromEpochDay(this.toEpochDay(date) + amount);
|
|
277
|
+
},
|
|
278
|
+
|
|
279
|
+
nextDay(date) {
|
|
280
|
+
return this.addDays(date, 1);
|
|
281
|
+
},
|
|
282
|
+
|
|
283
|
+
prevDay(date) {
|
|
284
|
+
return this.addDays(date, -1);
|
|
285
|
+
},
|
|
286
|
+
|
|
287
|
+
getDayOfYear(date) {
|
|
288
|
+
return this.toEpochDay(date) - this.toEpochDay({
|
|
289
|
+
year: date.year,
|
|
290
|
+
month: 1,
|
|
291
|
+
day: 1
|
|
292
|
+
}) + 1;
|
|
293
|
+
},
|
|
294
|
+
|
|
295
|
+
getWeekday(date) {
|
|
296
|
+
return gregorianCalendar.getWeekday(gregorianCalendar.fromEpochDay(this.toEpochDay(date)));
|
|
297
|
+
}
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
const islamicCalendar = islamicCivilCalendar;
|
|
301
|
+
|
|
302
|
+
exports.isIslamicCivilLeapYear = isIslamicCivilLeapYear;
|
|
303
|
+
exports.islamicCalendar = islamicCalendar;
|
|
304
|
+
exports.islamicCivilCalendar = islamicCivilCalendar;
|
|
305
|
+
exports.islamicCivilDaysInMonth = islamicCivilDaysInMonth;
|
|
306
|
+
return exports;
|
|
307
|
+
})({});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var TimestampJsCalendarIslamic=(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=o.toEpochDay({year:622,month:7,day:19});function u(e){if(e<1)throw RangeError(`Islamic calendar years start at 1 AH.`)}function d(e){return u(e),(e-1)*354+Math.floor((3+11*e)/30)}function f(e){return Math.ceil(29.5*(e-1))}function p(e){return u(e),(11*e+14)%30<11}function m(e,t){return u(e),t<1||t>12?0:t===12&&p(e)===!0||t%2==1?30:29}let h=Object.freeze({id:`islamic-civil`,intlCalendar:`islamic-civil`,label:`Islamic Civil`,defaultLocale:`ar`,defaultDirection:`rtl`,defaultWeekdays:Object.freeze([6,0,1,2,3,4,5]),monthsInYear(){return 12},isLeapYear(e){return p(e)},daysInMonth(e,t){return m(e,t)},toEpochDay(e){return u(e.year),l+d(e.year)+f(e.month)+e.day-1},fromEpochDay(e){let t=e-l,n=Math.floor((30*t+10646)/10631);for(;n>1&&this.toEpochDay({year:n,month:1,day:1})>e;)--n;for(;this.toEpochDay({year:n+1,month:1,day:1})<=e;)n+=1;let r=e-this.toEpochDay({year:n,month:1,day:1}),i=1;for(;i<12;){let e=this.daysInMonth(n,i);if(r<e)break;r-=e,i+=1}return{year:n,month:i,day:r+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)))}}),g=h;return e.isIslamicCivilLeapYear=p,e.islamicCalendar=g,e.islamicCivilCalendar=h,e.islamicCivilDaysInMonth=m,e})({});
|
package/dist/index.js
CHANGED
|
@@ -49,22 +49,75 @@ export function islamicCivilDaysInMonth(year, month) {
|
|
|
49
49
|
* does not model observational calendars or Umm al-Qura adjustments.
|
|
50
50
|
*/
|
|
51
51
|
export const islamicCivilCalendar = Object.freeze({
|
|
52
|
+
/**
|
|
53
|
+
* Package-facing id for the Islamic civil adapter.
|
|
54
|
+
*/
|
|
52
55
|
id: 'islamic-civil',
|
|
56
|
+
/**
|
|
57
|
+
* Intl calendar id for the arithmetic Islamic civil calendar.
|
|
58
|
+
*/
|
|
53
59
|
intlCalendar: 'islamic-civil',
|
|
60
|
+
/**
|
|
61
|
+
* Human-readable adapter name.
|
|
62
|
+
*/
|
|
54
63
|
label: 'Islamic Civil',
|
|
64
|
+
/**
|
|
65
|
+
* Default locale used for Islamic civil presentation.
|
|
66
|
+
*/
|
|
67
|
+
defaultLocale: 'ar',
|
|
68
|
+
/**
|
|
69
|
+
* Default text direction for Arabic Hijri presentation.
|
|
70
|
+
*/
|
|
71
|
+
defaultDirection: 'rtl',
|
|
72
|
+
/**
|
|
73
|
+
* Default visible week order for Hijri presentation: Saturday through Friday.
|
|
74
|
+
*
|
|
75
|
+
* Weekdays use JavaScript numbering, where Sunday is `0` and Saturday is `6`.
|
|
76
|
+
*/
|
|
77
|
+
defaultWeekdays: Object.freeze([6, 0, 1, 2, 3, 4, 5]),
|
|
78
|
+
/**
|
|
79
|
+
* Returns the number of months in an Islamic civil year.
|
|
80
|
+
*
|
|
81
|
+
* @returns Number of months in the year.
|
|
82
|
+
*/
|
|
55
83
|
monthsInYear() {
|
|
56
84
|
return MONTHS_IN_YEAR;
|
|
57
85
|
},
|
|
86
|
+
/**
|
|
87
|
+
* Returns true when the Islamic civil year contains a leap day.
|
|
88
|
+
*
|
|
89
|
+
* @param year Islamic civil year number.
|
|
90
|
+
* @returns True when the year contains a leap day in Dhu al-Hijjah.
|
|
91
|
+
*/
|
|
58
92
|
isLeapYear(year) {
|
|
59
93
|
return isIslamicCivilLeapYear(year);
|
|
60
94
|
},
|
|
95
|
+
/**
|
|
96
|
+
* Returns the number of days in an Islamic civil month.
|
|
97
|
+
*
|
|
98
|
+
* @param year Islamic civil year number.
|
|
99
|
+
* @param month Islamic civil month number, where Muharram is `1`.
|
|
100
|
+
* @returns Number of days in the month, or `0` for an invalid month number.
|
|
101
|
+
*/
|
|
61
102
|
daysInMonth(year, month) {
|
|
62
103
|
return islamicCivilDaysInMonth(year, month);
|
|
63
104
|
},
|
|
105
|
+
/**
|
|
106
|
+
* Converts an Islamic civil date into the equivalent epoch day.
|
|
107
|
+
*
|
|
108
|
+
* @param date Islamic civil date fields.
|
|
109
|
+
* @returns Epoch day for the equivalent civil instant.
|
|
110
|
+
*/
|
|
64
111
|
toEpochDay(date) {
|
|
65
112
|
assertPositiveYear(date.year);
|
|
66
113
|
return (ISLAMIC_EPOCH_DAY + daysBeforeYear(date.year) + daysBeforeMonth(date.month) + date.day - 1);
|
|
67
114
|
},
|
|
115
|
+
/**
|
|
116
|
+
* Converts an epoch day into Islamic civil date fields.
|
|
117
|
+
*
|
|
118
|
+
* @param epochDay Epoch day to convert.
|
|
119
|
+
* @returns Islamic civil date fields.
|
|
120
|
+
*/
|
|
68
121
|
fromEpochDay(epochDay) {
|
|
69
122
|
const days = epochDay - ISLAMIC_EPOCH_DAY;
|
|
70
123
|
let year = Math.floor((30 * days + 10646) / 10631);
|
|
@@ -90,18 +143,49 @@ export const islamicCivilCalendar = Object.freeze({
|
|
|
90
143
|
day: dayOfYear + 1,
|
|
91
144
|
};
|
|
92
145
|
},
|
|
146
|
+
/**
|
|
147
|
+
* Moves an Islamic civil date by a whole number of days.
|
|
148
|
+
*
|
|
149
|
+
* @param date Islamic civil date fields.
|
|
150
|
+
* @param amount Number of days to add. Negative values move backward.
|
|
151
|
+
* @returns Shifted Islamic civil date fields.
|
|
152
|
+
*/
|
|
93
153
|
addDays(date, amount) {
|
|
94
154
|
return this.fromEpochDay(this.toEpochDay(date) + amount);
|
|
95
155
|
},
|
|
156
|
+
/**
|
|
157
|
+
* Returns the next Islamic civil date.
|
|
158
|
+
*
|
|
159
|
+
* @param date Islamic civil date fields.
|
|
160
|
+
* @returns Date fields for the following day.
|
|
161
|
+
*/
|
|
96
162
|
nextDay(date) {
|
|
97
163
|
return this.addDays(date, 1);
|
|
98
164
|
},
|
|
165
|
+
/**
|
|
166
|
+
* Returns the previous Islamic civil date.
|
|
167
|
+
*
|
|
168
|
+
* @param date Islamic civil date fields.
|
|
169
|
+
* @returns Date fields for the previous day.
|
|
170
|
+
*/
|
|
99
171
|
prevDay(date) {
|
|
100
172
|
return this.addDays(date, -1);
|
|
101
173
|
},
|
|
174
|
+
/**
|
|
175
|
+
* Returns the one-based day-of-year for an Islamic civil date.
|
|
176
|
+
*
|
|
177
|
+
* @param date Islamic civil date fields.
|
|
178
|
+
* @returns One-based day-of-year.
|
|
179
|
+
*/
|
|
102
180
|
getDayOfYear(date) {
|
|
103
181
|
return this.toEpochDay(date) - this.toEpochDay({ year: date.year, month: 1, day: 1 }) + 1;
|
|
104
182
|
},
|
|
183
|
+
/**
|
|
184
|
+
* Returns the weekday for an Islamic civil date using JavaScript weekday numbering.
|
|
185
|
+
*
|
|
186
|
+
* @param date Islamic civil date fields.
|
|
187
|
+
* @returns Weekday number where Sunday is `0` and Saturday is `6`.
|
|
188
|
+
*/
|
|
105
189
|
getWeekday(date) {
|
|
106
190
|
return gregorianCalendar.getWeekday(gregorianCalendar.fromEpochDay(this.toEpochDay(date)));
|
|
107
191
|
},
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAA;AAGtD,MAAM,iBAAiB,GAAG,iBAAiB,CAAC,UAAU,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC,CAAA;AACxF,MAAM,cAAc,GAAG,EAAE,CAAA;AAEzB,SAAS,kBAAkB,CAAC,IAAY;IACtC,IAAI,IAAI,GAAG,CAAC,EAAE,CAAC;QACb,MAAM,IAAI,UAAU,CAAC,uCAAuC,CAAC,CAAA;IAC/D,CAAC;AACH,CAAC;AAED,SAAS,cAAc,CAAC,IAAY;IAClC,kBAAkB,CAAC,IAAI,CAAC,CAAA;IACxB,OAAO,CAAC,IAAI,GAAG,CAAC,CAAC,GAAG,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC,CAAA;AAC5D,CAAC;AAED,SAAS,eAAe,CAAC,KAAa;IACpC,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,CAAA;AACtC,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,sBAAsB,CAAC,IAAY;IACjD,kBAAkB,CAAC,IAAI,CAAC,CAAA;I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IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;IAC5F,CAAC;CACF,CAAC,CAAA;AAEF;;GAEG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,oBAAoB,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@timestamp-js/calendar-islamic",
|
|
3
|
-
"version": "0.1.0-rc.
|
|
3
|
+
"version": "0.1.0-rc.3",
|
|
4
4
|
"description": "Islamic/Hijri calendar adapters for Timestamp.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"calendar",
|
|
@@ -29,6 +29,8 @@
|
|
|
29
29
|
"sideEffects": false,
|
|
30
30
|
"main": "./dist/index.js",
|
|
31
31
|
"types": "./dist/index.d.ts",
|
|
32
|
+
"unpkg": "./dist/index.global.min.js",
|
|
33
|
+
"jsdelivr": "./dist/index.global.min.js",
|
|
32
34
|
"exports": {
|
|
33
35
|
".": {
|
|
34
36
|
"types": "./dist/index.d.ts",
|
|
@@ -39,12 +41,12 @@
|
|
|
39
41
|
"access": "public"
|
|
40
42
|
},
|
|
41
43
|
"dependencies": {
|
|
42
|
-
"@timestamp-js/core": "0.1.0-rc.
|
|
44
|
+
"@timestamp-js/core": "0.1.0-rc.3"
|
|
43
45
|
},
|
|
44
46
|
"devDependencies": {
|
|
45
47
|
"@types/node": "26.0.1",
|
|
46
|
-
"oxfmt": "0.
|
|
47
|
-
"oxlint": "1.
|
|
48
|
+
"oxfmt": "0.57.0",
|
|
49
|
+
"oxlint": "1.72.0",
|
|
48
50
|
"typescript": "6.0.3",
|
|
49
51
|
"vitest": "4.1.9"
|
|
50
52
|
},
|
|
@@ -55,7 +57,7 @@
|
|
|
55
57
|
"scripts": {
|
|
56
58
|
"clean": "rm -rf dist node_modules",
|
|
57
59
|
"prebuild": "pnpm --filter @timestamp-js/core build",
|
|
58
|
-
"build": "tsc -p tsconfig.build.json",
|
|
60
|
+
"build": "node ../../scripts/build-browser-globals.mjs @timestamp-js/calendar-islamic && tsc -p tsconfig.build.json",
|
|
59
61
|
"format": "oxfmt",
|
|
60
62
|
"format:check": "oxfmt --check",
|
|
61
63
|
"lint": "oxlint",
|