@hebcal/core 4.5.0 → 5.0.0-rc1
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 +1109 -457
- package/dist/bundle.js +5124 -1331
- package/dist/bundle.min.js +2 -2
- package/dist/index.js +2216 -1525
- package/dist/index.mjs +2215 -1524
- package/hebcal.d.ts +59 -146
- package/package.json +10 -8
- package/dist/greg0.mjs +0 -159
- package/dist/hdate-bundle.js +0 -1864
- package/dist/hdate-bundle.min.js +0 -2
- package/dist/hdate.js +0 -1853
- package/dist/hdate.mjs +0 -1909
- package/dist/hdate0-bundle.js +0 -444
- package/dist/hdate0-bundle.min.js +0 -2
- package/dist/hdate0.mjs +0 -465
package/hebcal.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import { GeoLocation } from '@hebcal/noaa';
|
|
2
2
|
|
|
3
3
|
declare module '@hebcal/core' {
|
|
4
4
|
export const version: string;
|
|
@@ -16,8 +16,6 @@ declare module '@hebcal/core' {
|
|
|
16
16
|
*/
|
|
17
17
|
constructor(date: HDate, desc: string, mask?: number, attrs?: any);
|
|
18
18
|
getFlags(): number;
|
|
19
|
-
/** @deprecated */
|
|
20
|
-
getAttrs(): any;
|
|
21
19
|
getDesc(): string;
|
|
22
20
|
basename(): string;
|
|
23
21
|
url(): string;
|
|
@@ -41,31 +39,58 @@ declare module '@hebcal/core' {
|
|
|
41
39
|
* Holiday flags for Event
|
|
42
40
|
*/
|
|
43
41
|
export const enum flags {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
42
|
+
/** Chag, yontiff, yom tov */
|
|
43
|
+
CHAG = 0x000001,
|
|
44
|
+
/** Light candles 18 minutes before sundown */
|
|
45
|
+
LIGHT_CANDLES = 0x000002,
|
|
46
|
+
/** End of holiday (end of Yom Tov) */
|
|
47
|
+
YOM_TOV_ENDS = 0x000004,
|
|
48
|
+
/** Observed only in the Diaspora (chutz l'aretz) */
|
|
49
|
+
CHUL_ONLY = 0x000008,
|
|
50
|
+
/** Observed only in Israel */
|
|
51
|
+
IL_ONLY = 0x000010,
|
|
52
|
+
/** Light candles in the evening at Tzeit time (3 small stars) */
|
|
53
|
+
LIGHT_CANDLES_TZEIS = 0x000020,
|
|
54
|
+
/** Candle-lighting for Chanukah */
|
|
55
|
+
CHANUKAH_CANDLES = 0x000040,
|
|
56
|
+
/** Rosh Chodesh, beginning of a new Hebrew month */
|
|
57
|
+
ROSH_CHODESH = 0x000080,
|
|
58
|
+
/** Minor fasts like Tzom Tammuz, Ta'anit Esther, ... */
|
|
59
|
+
MINOR_FAST = 0x000100,
|
|
60
|
+
/** Shabbat Shekalim, Zachor, ... */
|
|
61
|
+
SPECIAL_SHABBAT = 0x000200,
|
|
62
|
+
/** Weekly sedrot on Saturdays */
|
|
63
|
+
PARSHA_HASHAVUA = 0x000400,
|
|
64
|
+
/** Daily page of Talmud (Bavli) */
|
|
65
|
+
DAF_YOMI = 0x000800,
|
|
66
|
+
/** Days of the Omer */
|
|
67
|
+
OMER_COUNT = 0x001000,
|
|
68
|
+
/** Yom HaShoah, Yom HaAtzma'ut, ... */
|
|
69
|
+
MODERN_HOLIDAY = 0x002000,
|
|
70
|
+
/** Yom Kippur and Tish'a B'Av */
|
|
71
|
+
MAJOR_FAST = 0x004000,
|
|
72
|
+
/** On the Saturday before Rosh Chodesh */
|
|
73
|
+
SHABBAT_MEVARCHIM = 0x008000,
|
|
74
|
+
/** Molad */
|
|
75
|
+
MOLAD = 0x010000,
|
|
76
|
+
/** Yahrzeit or Hebrew Anniversary */
|
|
77
|
+
USER_EVENT = 0x020000,
|
|
78
|
+
/** Daily Hebrew date ("11th of Sivan, 5780") */
|
|
79
|
+
HEBREW_DATE = 0x040000,
|
|
80
|
+
/** A holiday that's not major, modern, rosh chodesh, or a fast day */
|
|
81
|
+
MINOR_HOLIDAY = 0x080000,
|
|
82
|
+
/** Evening before a major or minor holiday */
|
|
83
|
+
EREV = 0x100000,
|
|
84
|
+
/** Chol haMoed, intermediate days of Pesach or Sukkot */
|
|
85
|
+
CHOL_HAMOED = 0x200000,
|
|
86
|
+
/** Mishna Yomi */
|
|
87
|
+
MISHNA_YOMI = 0x400000,
|
|
88
|
+
/** Yom Kippur Katan, minor day of atonement on the day preceeding each Rosh Chodesh */
|
|
89
|
+
YOM_KIPPUR_KATAN = 0x800000,
|
|
90
|
+
/** Daily page of Jerusalem Talmud (Yerushalmi) */
|
|
91
|
+
YERUSHALMI_YOMI = 0x1000000,
|
|
92
|
+
/** Nach Yomi */
|
|
93
|
+
NACH_YOMI = 0x2000000,
|
|
69
94
|
}
|
|
70
95
|
|
|
71
96
|
export type UnitTypeShort = 'd' | 'w' | 'M' | 'y';
|
|
@@ -256,7 +281,7 @@ declare module '@hebcal/core' {
|
|
|
256
281
|
/**
|
|
257
282
|
* A Hebcal location is used for Zmanim and a latitude, longitude, timezone, and more
|
|
258
283
|
*/
|
|
259
|
-
export class Location {
|
|
284
|
+
export class Location extends GeoLocation {
|
|
260
285
|
/**
|
|
261
286
|
* Initialize a Location instance
|
|
262
287
|
* @param latitude - Latitude as a decimal, valid range -90 thru +90 (e.g. 41.85003)
|
|
@@ -265,9 +290,10 @@ declare module '@hebcal/core' {
|
|
|
265
290
|
* @param tzid - Olson timezone ID, e.g. "America/Chicago"
|
|
266
291
|
* @param cityName - optional descriptive city name
|
|
267
292
|
* @param countryCode - ISO 3166 alpha-2 country code (e.g. "FR")
|
|
268
|
-
* @param geoid - optional string or numeric geographic ID
|
|
293
|
+
* @param [geoid] - optional string or numeric geographic ID
|
|
294
|
+
* @param [elevation] - in meters (default `0`)
|
|
269
295
|
*/
|
|
270
|
-
constructor(latitude: number, longitude: number, il: boolean, tzid: string, cityName?: string, countryCode?: string, geoid?: string);
|
|
296
|
+
constructor(latitude: number, longitude: number, il: boolean, tzid: string, cityName?: string, countryCode?: string, geoid?: string, elevation?: number);
|
|
271
297
|
/**
|
|
272
298
|
* Creates a location object from one of 60 "classic" Hebcal city names.
|
|
273
299
|
* The following city names are supported:
|
|
@@ -301,22 +327,6 @@ declare module '@hebcal/core' {
|
|
|
301
327
|
* Gets a 24-hour time formatter (e.g. 07:41 or 20:03) for this location
|
|
302
328
|
*/
|
|
303
329
|
getTimeFormatter(): Intl.DateTimeFormat;
|
|
304
|
-
/** @deprecated */
|
|
305
|
-
sunset(hdate: Date | HDate): Date;
|
|
306
|
-
/**
|
|
307
|
-
* @deprecated
|
|
308
|
-
* @param [angle=8.5] optional time for solar depression.
|
|
309
|
-
* Default is 8.5 degrees for 3 small stars, use 7.083 degrees for 3 medium-sized stars.
|
|
310
|
-
*/
|
|
311
|
-
tzeit(hdate: Date | HDate, angle?: number): Date;
|
|
312
|
-
/**
|
|
313
|
-
* Builds a city description from geonameid string components
|
|
314
|
-
* @deprecated
|
|
315
|
-
* @param cityName e.g. 'Tel Aviv' or 'Chicago'
|
|
316
|
-
* @param admin1 e.g. 'England' or 'Massachusetts'
|
|
317
|
-
* @param countryName full country name, e.g. 'Israel' or 'United States'
|
|
318
|
-
*/
|
|
319
|
-
static geonameCityDescr(cityName: string, admin1: string, countryName: string): string;
|
|
320
330
|
/**
|
|
321
331
|
* Converts timezone info from Zip-Codes.com to a standard Olson tzid.
|
|
322
332
|
* @example
|
|
@@ -340,26 +350,6 @@ declare module '@hebcal/core' {
|
|
|
340
350
|
static addLocation(cityName: string, location: Location): boolean;
|
|
341
351
|
}
|
|
342
352
|
|
|
343
|
-
export interface ZmanimTimesResult {
|
|
344
|
-
dawn: Date;
|
|
345
|
-
dusk: Date;
|
|
346
|
-
goldenHour: Date;
|
|
347
|
-
goldenHourEnd: Date;
|
|
348
|
-
nauticalDawn: Date;
|
|
349
|
-
nauticalDusk: Date;
|
|
350
|
-
night: Date;
|
|
351
|
-
nightEnd: Date;
|
|
352
|
-
solarNoon: Date;
|
|
353
|
-
sunrise: Date;
|
|
354
|
-
sunriseEnd: Date;
|
|
355
|
-
sunset: Date;
|
|
356
|
-
sunsetStart: Date;
|
|
357
|
-
alotHaShachar: Date;
|
|
358
|
-
misheyakir: Date;
|
|
359
|
-
misheyakirMachmir: Date;
|
|
360
|
-
tzeit: Date;
|
|
361
|
-
}
|
|
362
|
-
|
|
363
353
|
/**
|
|
364
354
|
* Calculate halachic times (zmanim / זְמַנִּים) for a given day and location.
|
|
365
355
|
* Calculations are available for tzeit / tzais (nightfall),
|
|
@@ -372,12 +362,11 @@ declare module '@hebcal/core' {
|
|
|
372
362
|
export class Zmanim {
|
|
373
363
|
/**
|
|
374
364
|
* Initialize a Zmanim instance
|
|
365
|
+
* @param gloc GeoLocation including latitude, longitude, and timezone
|
|
375
366
|
* @param date Regular or Hebrew Date. If `date` is a regular `Date`,
|
|
376
367
|
* hours, minutes, seconds and milliseconds are ignored
|
|
377
|
-
* @param latitude
|
|
378
|
-
* @param longitude
|
|
379
368
|
*/
|
|
380
|
-
constructor(date: Date | HDate
|
|
369
|
+
constructor(gloc: GeoLocation, date: Date | HDate);
|
|
381
370
|
|
|
382
371
|
/**
|
|
383
372
|
* Returns a string like "2022-04-01T13:06:00-11:00"
|
|
@@ -402,8 +391,6 @@ declare module '@hebcal/core' {
|
|
|
402
391
|
*/
|
|
403
392
|
timeAtAngle(angle: number, rising: boolean): Date;
|
|
404
393
|
|
|
405
|
-
/** @deprecated */
|
|
406
|
-
suntime(): ZmanimTimesResult;
|
|
407
394
|
/** Upper edge of the Sun appears over the eastern horizon in the morning (0.833° above horizon) */
|
|
408
395
|
sunrise(): Date;
|
|
409
396
|
/** When the upper edge of the Sun disappears below the horizon (0.833° below horizon) */
|
|
@@ -412,12 +399,7 @@ declare module '@hebcal/core' {
|
|
|
412
399
|
dawn(): Date;
|
|
413
400
|
/** Civil dusk; Sun is 6° below the horizon in the evening */
|
|
414
401
|
dusk(): Date;
|
|
415
|
-
hour(): number;
|
|
416
|
-
hourMins(): number;
|
|
417
402
|
gregEve(): Date;
|
|
418
|
-
nightHour(): number;
|
|
419
|
-
nightHourMins(): number;
|
|
420
|
-
hourOffset(hours: number): Date;
|
|
421
403
|
/** Midday – Chatzot; Sunrise plus 6 halachic hours */
|
|
422
404
|
chatzot(): Date;
|
|
423
405
|
/** Midnight – Chatzot; Sunset plus 6 halachic hours */
|
|
@@ -463,18 +445,6 @@ declare module '@hebcal/core' {
|
|
|
463
445
|
* @param roundMinute round time to nearest minute (default true)
|
|
464
446
|
*/
|
|
465
447
|
sunsetOffset(offset: number, roundMinute?: boolean): Date;
|
|
466
|
-
/**
|
|
467
|
-
* Returns an array with sunset + offset Date object, and a 24-hour string formatted time.
|
|
468
|
-
* @deprecated
|
|
469
|
-
*/
|
|
470
|
-
sunsetOffsetTime(offset: number, timeFormat: Intl.DateTimeFormat): any[];
|
|
471
|
-
/**
|
|
472
|
-
* Returns an array with tzeit Date object and a 24-hour string formatted time.
|
|
473
|
-
* @deprecated
|
|
474
|
-
* @param angle optional time for solar depression.
|
|
475
|
-
* Default is 8.5 degrees for 3 small stars, use 7.083 degrees for 3 medium-sized stars.
|
|
476
|
-
*/
|
|
477
|
-
tzeitTime(angle: number, timeFormat: Intl.DateTimeFormat): any[];
|
|
478
448
|
}
|
|
479
449
|
|
|
480
450
|
export interface Headers {
|
|
@@ -548,18 +518,6 @@ declare module '@hebcal/core' {
|
|
|
548
518
|
static hebrewStripNikkud(str: string): string;
|
|
549
519
|
}
|
|
550
520
|
|
|
551
|
-
/**
|
|
552
|
-
* A simple Hebrew date
|
|
553
|
-
*/
|
|
554
|
-
export type SimpleHebrewDate = {
|
|
555
|
-
/** Hebrew year */
|
|
556
|
-
yy: number;
|
|
557
|
-
/** Hebrew month of year (1=NISAN, 7=TISHREI) */
|
|
558
|
-
mm: number;
|
|
559
|
-
/** Day of month (1-30) */
|
|
560
|
-
dd: number;
|
|
561
|
-
};
|
|
562
|
-
|
|
563
521
|
export interface DailyLearningOptions {
|
|
564
522
|
[key: string]: any;
|
|
565
523
|
}
|
|
@@ -848,51 +806,6 @@ declare module '@hebcal/core' {
|
|
|
848
806
|
getChalakim(): number;
|
|
849
807
|
}
|
|
850
808
|
|
|
851
|
-
/**
|
|
852
|
-
* Gregorian date helper functions.
|
|
853
|
-
*/
|
|
854
|
-
export class greg {
|
|
855
|
-
/**
|
|
856
|
-
* Long names of the Gregorian months (1='January', 12='December')
|
|
857
|
-
*/
|
|
858
|
-
static monthNames: string[];
|
|
859
|
-
/**
|
|
860
|
-
* Returns true if the object is a Javascript Date
|
|
861
|
-
*/
|
|
862
|
-
static isDate(obj: any): boolean;
|
|
863
|
-
/**
|
|
864
|
-
* Returns true if the Gregorian year is a leap year
|
|
865
|
-
* @param year - Gregorian year
|
|
866
|
-
*/
|
|
867
|
-
static isLeapYear(year: number): boolean;
|
|
868
|
-
/**
|
|
869
|
-
* Number of days in the Gregorian month for given year
|
|
870
|
-
* @param month - Gregorian month (1=January, 12=December)
|
|
871
|
-
* @param year - Gregorian year
|
|
872
|
-
*/
|
|
873
|
-
static daysInMonth(month: number, year: number): number;
|
|
874
|
-
/**
|
|
875
|
-
* Returns number of days since January 1 of that year
|
|
876
|
-
* @deprecated
|
|
877
|
-
* @param date - Gregorian date
|
|
878
|
-
*/
|
|
879
|
-
static dayOfYear(date: Date): number;
|
|
880
|
-
/**
|
|
881
|
-
* Converts Gregorian date to absolute R.D. (Rata Die) days
|
|
882
|
-
* @param date - Gregorian date
|
|
883
|
-
*/
|
|
884
|
-
static greg2abs(date: Date): number;
|
|
885
|
-
/**
|
|
886
|
-
* Converts from Rata Die (R.D. number) to Gregorian date.
|
|
887
|
-
* See the footnote on page 384 of ``Calendrical Calculations, Part II:
|
|
888
|
-
* Three Historical Calendars'' by E. M. Reingold, N. Dershowitz, and S. M.
|
|
889
|
-
* Clamen, Software--Practice and Experience, Volume 23, Number 4
|
|
890
|
-
* (April, 1993), pages 383-404 for an explanation.
|
|
891
|
-
* @param theDate - R.D. number of days
|
|
892
|
-
*/
|
|
893
|
-
static abs2greg(theDate: number): Date;
|
|
894
|
-
}
|
|
895
|
-
|
|
896
809
|
/**
|
|
897
810
|
* Hebrew months of the year (NISAN=1, TISHREI=7)
|
|
898
811
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hebcal/core",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.0-rc1",
|
|
4
4
|
"author": "Michael J. Radwin (https://github.com/mjradwin)",
|
|
5
5
|
"contributors": [
|
|
6
6
|
"Eyal Schachter (https://github.com/Scimonster)",
|
|
@@ -60,23 +60,25 @@
|
|
|
60
60
|
"verbose": true
|
|
61
61
|
},
|
|
62
62
|
"devDependencies": {
|
|
63
|
-
"@babel/core": "^7.23.
|
|
64
|
-
"@babel/preset-env": "^7.23.
|
|
63
|
+
"@babel/core": "^7.23.3",
|
|
64
|
+
"@babel/preset-env": "^7.23.3",
|
|
65
65
|
"@babel/register": "^7.22.15",
|
|
66
|
-
"@hebcal/
|
|
66
|
+
"@hebcal/hdate": "^0.8.1",
|
|
67
|
+
"@hebcal/noaa": "^0.8.6",
|
|
67
68
|
"@rollup/plugin-babel": "^6.0.4",
|
|
68
69
|
"@rollup/plugin-commonjs": "^25.0.7",
|
|
69
70
|
"@rollup/plugin-json": "^6.0.1",
|
|
70
71
|
"@rollup/plugin-node-resolve": "^15.2.3",
|
|
71
72
|
"@rollup/plugin-terser": "^0.4.4",
|
|
72
73
|
"ava": "^5.3.1",
|
|
73
|
-
"core-js": "^3.33.
|
|
74
|
-
"eslint": "^8.
|
|
74
|
+
"core-js": "^3.33.3",
|
|
75
|
+
"eslint": "^8.54.0",
|
|
75
76
|
"eslint-config-google": "^0.14.0",
|
|
76
77
|
"jsdoc": "^4.0.2",
|
|
77
78
|
"jsdoc-to-markdown": "^8.0.0",
|
|
78
79
|
"nyc": "^15.1.0",
|
|
79
|
-
"rollup": "^4.
|
|
80
|
-
"
|
|
80
|
+
"rollup": "^4.5.1",
|
|
81
|
+
"temporal-polyfill": "^0.1.1",
|
|
82
|
+
"ttag-cli": "^1.10.9"
|
|
81
83
|
}
|
|
82
84
|
}
|
package/dist/greg0.mjs
DELETED
|
@@ -1,159 +0,0 @@
|
|
|
1
|
-
/*! @hebcal/core v4.5.0 */
|
|
2
|
-
/*
|
|
3
|
-
* More minimal greg routines
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
/** @private */
|
|
7
|
-
const lengths = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
|
|
8
|
-
/** @private */
|
|
9
|
-
const monthLengths = [
|
|
10
|
-
lengths,
|
|
11
|
-
lengths.slice(),
|
|
12
|
-
];
|
|
13
|
-
monthLengths[1][2] = 29;
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* @private
|
|
17
|
-
* @param {number} x
|
|
18
|
-
* @param {number} y
|
|
19
|
-
* @return {number}
|
|
20
|
-
*/
|
|
21
|
-
function mod(x, y) {
|
|
22
|
-
return x - y * Math.floor(x / y);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* @private
|
|
27
|
-
* @param {number} x
|
|
28
|
-
* @param {number} y
|
|
29
|
-
* @return {number}
|
|
30
|
-
*/
|
|
31
|
-
function quotient(x, y) {
|
|
32
|
-
return Math.floor(x / y);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Returns true if the Gregorian year is a leap year
|
|
37
|
-
* @private
|
|
38
|
-
* @param {number} year Gregorian year
|
|
39
|
-
* @return {boolean}
|
|
40
|
-
*/
|
|
41
|
-
function isLeapYear(year) {
|
|
42
|
-
return !(year % 4) && (!!(year % 100) || !(year % 400));
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Number of days in the Gregorian month for given year
|
|
47
|
-
* @private
|
|
48
|
-
* @param {number} month Gregorian month (1=January, 12=December)
|
|
49
|
-
* @param {number} year Gregorian year
|
|
50
|
-
* @return {number}
|
|
51
|
-
*/
|
|
52
|
-
function daysInMonth(month, year) {
|
|
53
|
-
// 1 based months
|
|
54
|
-
return monthLengths[+isLeapYear(year)][month];
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Returns true if the object is a Javascript Date
|
|
59
|
-
* @private
|
|
60
|
-
* @param {Object} obj
|
|
61
|
-
* @return {boolean}
|
|
62
|
-
*/
|
|
63
|
-
function isDate(obj) {
|
|
64
|
-
return typeof obj === 'object' && Date.prototype === obj.__proto__;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/*
|
|
68
|
-
const ABS_14SEP1752 = 639797;
|
|
69
|
-
const ABS_2SEP1752 = 639785;
|
|
70
|
-
*/
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Converts Gregorian date to absolute R.D. (Rata Die) days
|
|
74
|
-
* @private
|
|
75
|
-
* @param {Date} date Gregorian date
|
|
76
|
-
* @return {number}
|
|
77
|
-
*/
|
|
78
|
-
function greg2abs(date) {
|
|
79
|
-
if (!isDate(date)) {
|
|
80
|
-
throw new TypeError(`Argument not a Date: ${date}`);
|
|
81
|
-
}
|
|
82
|
-
const abs = toFixed(date.getFullYear(), date.getMonth() + 1, date.getDate());
|
|
83
|
-
/*
|
|
84
|
-
if (abs < ABS_14SEP1752 && abs > ABS_2SEP1752) {
|
|
85
|
-
throw new RangeError(`Invalid Date: ${date}`);
|
|
86
|
-
}
|
|
87
|
-
*/
|
|
88
|
-
return abs;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* @private
|
|
93
|
-
* @param {number} abs - R.D. number of days
|
|
94
|
-
* @return {number}
|
|
95
|
-
*/
|
|
96
|
-
function yearFromFixed(abs) {
|
|
97
|
-
const l0 = abs - 1;
|
|
98
|
-
const n400 = quotient(l0, 146097);
|
|
99
|
-
const d1 = mod(l0, 146097);
|
|
100
|
-
const n100 = quotient(d1, 36524);
|
|
101
|
-
const d2 = mod(d1, 36524);
|
|
102
|
-
const n4 = quotient(d2, 1461);
|
|
103
|
-
const d3 = mod(d2, 1461);
|
|
104
|
-
const n1 = quotient(d3, 365);
|
|
105
|
-
const year = 400 * n400 + 100 * n100 + 4 * n4 + n1;
|
|
106
|
-
return n100 != 4 && n1 != 4 ? year + 1 : year;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* @private
|
|
111
|
-
* @param {number} year
|
|
112
|
-
* @param {number} month (1-12)
|
|
113
|
-
* @param {number} day (1-31)
|
|
114
|
-
* @return {number}
|
|
115
|
-
*/
|
|
116
|
-
function toFixed(year, month, day) {
|
|
117
|
-
const py = year - 1;
|
|
118
|
-
return 365 * py +
|
|
119
|
-
quotient(py, 4) -
|
|
120
|
-
quotient(py, 100) +
|
|
121
|
-
quotient(py, 400) +
|
|
122
|
-
quotient((367 * month - 362), 12) +
|
|
123
|
-
(month <= 2 ? 0 : (isLeapYear(year) ? -1 : -2)) +
|
|
124
|
-
day;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* Converts from Rata Die (R.D. number) to Gregorian date.
|
|
129
|
-
* See the footnote on page 384 of ``Calendrical Calculations, Part II:
|
|
130
|
-
* Three Historical Calendars'' by E. M. Reingold, N. Dershowitz, and S. M.
|
|
131
|
-
* Clamen, Software--Practice and Experience, Volume 23, Number 4
|
|
132
|
-
* (April, 1993), pages 383-404 for an explanation.
|
|
133
|
-
* @private
|
|
134
|
-
* @param {number} abs - R.D. number of days
|
|
135
|
-
* @return {Date}
|
|
136
|
-
*/
|
|
137
|
-
function abs2greg(abs) {
|
|
138
|
-
if (typeof abs !== 'number') {
|
|
139
|
-
throw new TypeError(`Argument not a Number: ${abs}`);
|
|
140
|
-
}
|
|
141
|
-
abs = Math.trunc(abs);
|
|
142
|
-
/*
|
|
143
|
-
if (abs < ABS_14SEP1752 && abs > ABS_2SEP1752) {
|
|
144
|
-
throw new RangeError(`Invalid Date: ${abs}`);
|
|
145
|
-
}
|
|
146
|
-
*/
|
|
147
|
-
const year = yearFromFixed(abs);
|
|
148
|
-
const priorDays = abs - toFixed(year, 1, 1);
|
|
149
|
-
const correction = abs < toFixed(year, 3, 1) ? 0 : (isLeapYear(year) ? 1 : 2);
|
|
150
|
-
const month = quotient((12 * (priorDays + correction) + 373), 367);
|
|
151
|
-
const day = abs - toFixed(year, month, 1) + 1;
|
|
152
|
-
const dt = new Date(year, month - 1, day);
|
|
153
|
-
if (year < 100 && year >= 0) {
|
|
154
|
-
dt.setFullYear(year);
|
|
155
|
-
}
|
|
156
|
-
return dt;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
export { abs2greg, daysInMonth, greg2abs, isDate, isLeapYear, mod };
|