jcal-zmanim 1.5.5 → 1.5.8

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/index.cjs CHANGED
@@ -3016,7 +3016,9 @@ var yearTypeList = [
3016
3016
  0,
3017
3017
  7
3018
3018
  ];
3019
+ var elapsedDaysCache = /* @__PURE__ */ new Map();
3019
3020
  var getElapsedDays = function(year) {
3021
+ if (elapsedDaysCache.has(year)) return elapsedDaysCache.get(year);
3020
3022
  var daysCounter = 0;
3021
3023
  var months = Utils.toInt(235 * Utils.toInt((year - 1) / 19) + // Leap months this cycle
3022
3024
  12 * ((year - 1) % 19) + // Regular months in this cycle.
@@ -3029,6 +3031,7 @@ var getElapsedDays = function(year) {
3029
3031
  if (Utils.has(daysCounter % 7, 0, 3, 5)) {
3030
3032
  daysCounter += 1;
3031
3033
  }
3034
+ elapsedDaysCache.set(year, daysCounter);
3032
3035
  return daysCounter;
3033
3036
  };
3034
3037
  var _jDate = /*#__PURE__*/ function() {
@@ -3686,7 +3689,7 @@ var _jDate = /*#__PURE__*/ function() {
3686
3689
  _jDate.getElapsedDays = getElapsedDays;
3687
3690
  var jDate = _jDate;
3688
3691
  // src/JCal/Zmanim.ts
3689
- var Zmanim = /*#__PURE__*/ function() {
3692
+ var _Zmanim = /*#__PURE__*/ function() {
3690
3693
  function _Zmanim() {
3691
3694
  _class_call_check(this, _Zmanim);
3692
3695
  }
@@ -3703,13 +3706,22 @@ var Zmanim = /*#__PURE__*/ function() {
3703
3706
  * @param {Boolean} considerElevation
3704
3707
  */ function getSunTimes(date, location) {
3705
3708
  var considerElevation = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : true;
3709
+ var absDate;
3706
3710
  if (_instanceof(date, jDate)) {
3711
+ absDate = date.Abs;
3707
3712
  date = date.getDate();
3708
- } else if (_instanceof(date, String)) {
3709
- date = new Date(date);
3713
+ } else {
3714
+ if (typeof date === "string" || _instanceof(date, String)) {
3715
+ date = new Date(date);
3716
+ }
3717
+ if (!Utils.isValidDate(date)) {
3718
+ throw "Zmanim.getSunTimes: supplied date parameter cannot be converted to a Date";
3719
+ }
3720
+ absDate = jDate.absSd(date);
3710
3721
  }
3711
- if (!Utils.isValidDate(date)) {
3712
- throw "Zmanim.getSunTimes: supplied date parameter cannot be converted to a Date";
3722
+ var cacheKey = "".concat(absDate, "|").concat(location.Name, "|").concat(location.Latitude, "|").concat(location.Longitude, "|").concat(location.Elevation, "|").concat(considerElevation);
3723
+ if (_Zmanim._sunTimesCache.has(cacheKey)) {
3724
+ return _Zmanim._sunTimesCache.get(cacheKey);
3713
3725
  }
3714
3726
  var sunrise, sunset, zenithDeg = 90, zenithMin = 50, lonHour = 0, longitude = 0, latitude = 0, cosLat = 0, sinLat = 0, cosZen = 0, sinDec = 0, cosDec = 0, xmRise = 0, xmSet = 0, xlRise = 0, xlSet = 0, aRise = 0, aSet = 0, ahrRise = 0, ahrSet = 0, hRise = 0, hSet = 0, tRise = 0, tSet = 0, utRise = 0, utSet = 0;
3715
3727
  var day = _Zmanim.dayOfYear(date), earthRadius = 6356900, zenithAtElevation = _Zmanim.degToDec(zenithDeg, zenithMin) + _Zmanim.radToDeg(Math.acos(earthRadius / (earthRadius + (considerElevation ? location.Elevation : 0))));
@@ -3765,10 +3777,13 @@ var Zmanim = /*#__PURE__*/ function() {
3765
3777
  sunset.hour += 12;
3766
3778
  }
3767
3779
  }
3768
- return {
3780
+ var result = {
3769
3781
  sunrise: sunrise,
3770
3782
  sunset: sunset
3771
3783
  };
3784
+ _Zmanim._sunTimesCache.set(cacheKey, result);
3785
+ if (_Zmanim._sunTimesCache.size > 2e3) _Zmanim._sunTimesCache.clear();
3786
+ return result;
3772
3787
  }
3773
3788
  },
3774
3789
  {
@@ -3958,6 +3973,8 @@ var Zmanim = /*#__PURE__*/ function() {
3958
3973
  ]);
3959
3974
  return _Zmanim;
3960
3975
  }();
3976
+ _Zmanim._sunTimesCache = /* @__PURE__ */ new Map();
3977
+ var Zmanim = _Zmanim;
3961
3978
  // src/Utils.ts
3962
3979
  var __DEV__ = process.env.NODE_ENV === "development";
3963
3980
  var DaysOfWeek = Object.freeze({
@@ -13194,8 +13211,9 @@ var Molad = /*#__PURE__*/ function() {
13194
13211
  partsElapsed = 204 + 793 * (totalMonths % 1080);
13195
13212
  hoursElapsed = 5 + 12 * totalMonths + 793 * Utils.toInt(totalMonths / 1080) + Utils.toInt(partsElapsed / 1080) - 6;
13196
13213
  parts = Utils.toInt(partsElapsed % 1080 + 1080 * (hoursElapsed % 24));
13214
+ var absoluteDays = 1 + 29 * Utils.toInt(totalMonths) + Utils.toInt(hoursElapsed / 24) - 1373429;
13197
13215
  return {
13198
- jDate: new jDate(1 + 29 * Utils.toInt(totalMonths) + Utils.toInt(hoursElapsed / 24)),
13216
+ jDate: new jDate(Math.floor(absoluteDays)),
13199
13217
  time: {
13200
13218
  hour: Utils.toInt(hoursElapsed) % 24,
13201
13219
  minute: Utils.toInt(parts % 1080 / 18),