@hebcal/core 3.41.2 → 3.42.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/hdate0.mjs CHANGED
@@ -1,4 +1,4 @@
1
- /*! @hebcal/core v3.41.2 */
1
+ /*! @hebcal/core v3.42.0 */
2
2
  /*
3
3
  * More minimal greg routines
4
4
  */
@@ -52,27 +52,10 @@ function isDate(obj) {
52
52
  return typeof obj === 'object' && Date.prototype === obj.__proto__;
53
53
  }
54
54
 
55
- /**
56
- * Returns number of days since January 1 of that year
57
- * @private
58
- * @param {Date} date Gregorian date
59
- * @return {number}
60
- */
61
- function dayOfYear(date) {
62
- if (!isDate(date)) {
63
- throw new TypeError(`Argument not a Date: ${date}`);
64
- }
65
- const month = date.getMonth();
66
- let doy = date.getDate() + 31 * month;
67
- if (month > 1) {
68
- // FEB
69
- doy -= Math.floor((4 * (month + 1) + 23) / 10);
70
- if (isLeapYear$1(date.getFullYear())) {
71
- doy++;
72
- }
73
- }
74
- return doy;
75
- }
55
+ /*
56
+ const ABS_14SEP1752 = 639797;
57
+ const ABS_2SEP1752 = 639785;
58
+ */
76
59
 
77
60
  /**
78
61
  * Converts Gregorian date to absolute R.D. (Rata Die) days
@@ -84,14 +67,13 @@ function greg2abs(date) {
84
67
  if (!isDate(date)) {
85
68
  throw new TypeError(`Argument not a Date: ${date}`);
86
69
  }
87
- const year = date.getFullYear() - 1;
88
- return (
89
- dayOfYear(date) + // days this year
90
- 365 * year + // + days in prior years
91
- (Math.floor(year / 4) - // + Julian Leap years
92
- Math.floor(year / 100) + // - century years
93
- Math.floor(year / 400))
94
- ); // + Gregorian leap years
70
+ const abs = toFixed(date.getFullYear(), date.getMonth() + 1, date.getDate());
71
+ /*
72
+ if (abs < ABS_14SEP1752 && abs > ABS_2SEP1752) {
73
+ throw new RangeError(`Invalid Date: ${date}`);
74
+ }
75
+ */
76
+ return abs;
95
77
  }
96
78
 
97
79
  /**
@@ -115,8 +97,8 @@ function yearFromFixed(abs) {
115
97
  /**
116
98
  * @private
117
99
  * @param {number} year
118
- * @param {number} month
119
- * @param {number} day
100
+ * @param {number} month (1-12)
101
+ * @param {number} day (1-31)
120
102
  * @return {number}
121
103
  */
122
104
  function toFixed(year, month, day) {
@@ -145,6 +127,11 @@ function abs2greg(abs) {
145
127
  throw new TypeError(`Argument not a Number: ${abs}`);
146
128
  }
147
129
  abs = Math.trunc(abs);
130
+ /*
131
+ if (abs < ABS_14SEP1752 && abs > ABS_2SEP1752) {
132
+ throw new RangeError(`Invalid Date: ${abs}`);
133
+ }
134
+ */
148
135
  const year = yearFromFixed(abs);
149
136
  const priorDays = abs - toFixed(year, 1, 1);
150
137
  const correction = abs < toFixed(year, 3, 1) ? 0 : (isLeapYear$1(year) ? 1 : 2);