@hebcal/core 6.9.1 → 6.9.2

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.
Files changed (48) hide show
  1. package/dist/bundle.js +128 -68
  2. package/dist/bundle.js.map +1 -1
  3. package/dist/bundle.min.js +8 -8
  4. package/dist/bundle.min.js.map +1 -1
  5. package/dist/esm/DailyLearning.js +1 -1
  6. package/dist/esm/HebrewDateEvent.js +1 -1
  7. package/dist/esm/HolidayEvent.js +1 -1
  8. package/dist/esm/MevarchimChodeshEvent.js +1 -1
  9. package/dist/esm/ParshaEvent.js +1 -1
  10. package/dist/esm/TimedEvent.js +1 -1
  11. package/dist/esm/YomKippurKatanEvent.js +1 -1
  12. package/dist/esm/ashkenazi.po.js +1 -1
  13. package/dist/esm/calendar.js +1 -1
  14. package/dist/esm/candles.js +1 -1
  15. package/dist/esm/cities.json.js +1 -1
  16. package/dist/esm/event.js +1 -1
  17. package/dist/esm/getStartAndEnd.js +1 -1
  18. package/dist/esm/hallel.js +1 -1
  19. package/dist/esm/he-x-NoNikud.po.js +1 -1
  20. package/dist/esm/he.po.js +1 -1
  21. package/dist/esm/hebcal.js +1 -1
  22. package/dist/esm/holidays.js +1 -1
  23. package/dist/esm/index.js +1 -1
  24. package/dist/esm/isAssurBemlacha.js +1 -1
  25. package/dist/esm/isAveilut.js +1 -1
  26. package/dist/esm/isFastDay.js +1 -1
  27. package/dist/esm/locale.js +1 -1
  28. package/dist/esm/location.js +1 -1
  29. package/dist/esm/modern.js +1 -1
  30. package/dist/esm/molad.js +1 -1
  31. package/dist/esm/moladBase.js +1 -1
  32. package/dist/esm/moladDate.js +1 -1
  33. package/dist/esm/omer.js +1 -1
  34. package/dist/esm/parshaName.js +1 -1
  35. package/dist/esm/parshaYear.js +1 -1
  36. package/dist/esm/pkgVersion.d.ts +1 -1
  37. package/dist/esm/pkgVersion.js +2 -2
  38. package/dist/esm/pkgVersion.js.map +1 -1
  39. package/dist/esm/reformatTimeStr.js +1 -1
  40. package/dist/esm/sedra.js +1 -1
  41. package/dist/esm/sefira.json.js +1 -1
  42. package/dist/esm/staticHolidays.js +1 -1
  43. package/dist/esm/string.js +1 -1
  44. package/dist/esm/tachanun.js +1 -1
  45. package/dist/esm/zmanim.d.ts +18 -1
  46. package/dist/esm/zmanim.js +86 -55
  47. package/dist/esm/zmanim.js.map +1 -1
  48. package/package.json +8 -7
package/dist/bundle.js CHANGED
@@ -1,9 +1,9 @@
1
- /*! @hebcal/core v6.9.1, distributed under GPLv2 https://www.gnu.org/licenses/gpl-2.0.txt */
1
+ /*! @hebcal/core v6.9.2, distributed under GPLv2 https://www.gnu.org/licenses/gpl-2.0.txt */
2
2
  var hebcal = (function (exports) {
3
3
  'use strict';
4
4
 
5
5
  /** DO NOT EDIT THIS AUTO-GENERATED FILE! */
6
- const version = '6.9.1';
6
+ const version = '6.9.2';
7
7
 
8
8
  /*! @hebcal/hdate v0.22.7, distributed under GPLv2 https://www.gnu.org/licenses/gpl-2.0.txt */
9
9
  /** @private */
@@ -8057,12 +8057,36 @@ class NOAACalculator {
8057
8057
  * @return {Temporal.ZonedDateTime | null} The Date.
8058
8058
  */
8059
8059
  getDateFromTime(time, isSunrise) {
8060
- if (isNaN(time)) {
8060
+ const epochMillis = this.getEpochMillisFromTime(time, isSunrise);
8061
+ if (isNaN(epochMillis)) {
8061
8062
  return null;
8062
8063
  }
8064
+ return Temporal.Instant.fromEpochMilliseconds(epochMillis).toZonedDateTimeISO(this.geoLocation.getTimeZone());
8065
+ }
8066
+ /**
8067
+ * The instant that {@link getDateFromTime} describes, as milliseconds since
8068
+ * the epoch, without building a `Temporal.ZonedDateTime`.
8069
+ *
8070
+ * Constructing a `ZonedDateTime` costs roughly 750ns because the IANA zone
8071
+ * has to be resolved, and that dominates this calculation. Callers that only
8072
+ * want an instant — a `Date`, or the difference between two times — can skip
8073
+ * it. Deriving the instant arithmetically also avoids a `PlainTime`
8074
+ * allocation and turns the day rollover into a subtraction rather than a
8075
+ * ~610ns `PlainDate.add({days})`.
8076
+ *
8077
+ * @param {number} time
8078
+ * The time in the format 18.75 for 6:45:00 PM, as returned by
8079
+ * {@link getUTCSunrise} / {@link getUTCSunset}, i.e. already
8080
+ * normalized to `[0, 24)`.
8081
+ * @param {boolean} isSunrise true if the time is sunrise, and false if it is sunset
8082
+ * @return {number} milliseconds since the epoch, or `NaN` if `time` is `NaN`
8083
+ */
8084
+ getEpochMillisFromTime(time, isSunrise) {
8085
+ if (isNaN(time)) {
8086
+ return NaN;
8087
+ }
8063
8088
  let calculatedTime = time;
8064
- let cal = this.getAdjustedDate();
8065
- // let cal = new Temporal.PlainDate(adj.year, adj.month, adj.day);
8089
+ const cal = this.getAdjustedDate();
8066
8090
  const hours = Math.trunc(calculatedTime); // retain only the hours
8067
8091
  calculatedTime -= hours;
8068
8092
  const minutes = Math.trunc((calculatedTime *= 60)); // retain only the minutes
@@ -8072,19 +8096,24 @@ class NOAACalculator {
8072
8096
  // Check if a date transition has occurred, or is about to occur - this indicates the date of the event is
8073
8097
  // actually not the target date, but the day prior or after
8074
8098
  const localTimeHours = Math.trunc(this.geoLocation.getLongitude() / 15);
8099
+ let dayOffset = 0;
8075
8100
  if (isSunrise && localTimeHours + hours > 18) {
8076
- cal = cal.add({ days: -1 });
8077
- // cal = cal.minus({days: 1});
8101
+ dayOffset = -1;
8078
8102
  }
8079
8103
  else if (!isSunrise && localTimeHours + hours < 6) {
8080
- cal = cal.add({ days: 1 });
8104
+ dayOffset = 1;
8105
+ }
8106
+ const year = cal.year;
8107
+ let millis = Date.UTC(year, cal.month - 1, cal.day, hours, minutes, seconds, Math.trunc(calculatedTime * 1000));
8108
+ if (year >= 0 && year < 100) {
8109
+ // Date.UTC() maps years 0-99 onto 1900-1999; setUTCFullYear() does not.
8110
+ // Worth the branch (about 3ns): @hebcal/core computes candle-lighting
8111
+ // times for early historical years rather than suppressing them.
8112
+ const d = new Date(millis);
8113
+ d.setUTCFullYear(year);
8114
+ millis = d.getTime();
8081
8115
  }
8082
- return cal
8083
- .toZonedDateTime({
8084
- timeZone: 'UTC',
8085
- plainTime: new Temporal.PlainTime(hours, minutes, seconds, Math.trunc(calculatedTime * 1000)),
8086
- })
8087
- .withTimeZone(this.geoLocation.getTimeZone());
8116
+ return millis + dayOffset * 86400000;
8088
8117
  }
8089
8118
  /**
8090
8119
  * Return the <a href="http://en.wikipedia.org/wiki/Julian_day">Julian day</a> from a Java Calendar
@@ -9724,13 +9753,17 @@ class MoladEvent extends Event {
9724
9753
  }
9725
9754
 
9726
9755
  /**
9756
+ * Converts an instant to a `Date`, discarding milliseconds.
9757
+ *
9758
+ * Zmanim are read out to the minute, and every accessor here reduces to an
9759
+ * instant, so we ask `@hebcal/noaa` for epoch milliseconds rather than a
9760
+ * `Temporal.ZonedDateTime`. Resolving the IANA zone to build a
9761
+ * `ZonedDateTime` costs roughly 750ns and nothing downstream uses it, which
9762
+ * made it the single most expensive step in a sunrise/sunset calculation.
9727
9763
  * @private
9728
9764
  */
9729
- function zdtToDate(zdt) {
9730
- if (zdt === null) {
9731
- return new Date(NaN);
9732
- }
9733
- const res = new Date(zdt.epochMilliseconds);
9765
+ function millisToDate(millis) {
9766
+ const res = new Date(millis);
9734
9767
  res.setMilliseconds(0);
9735
9768
  return res;
9736
9769
  }
@@ -9747,6 +9780,20 @@ const GEOMETRIC_ZENITH = 90;
9747
9780
  * @see Zmanim.sunsetBaalHatanya
9748
9781
  */
9749
9782
  const ZENITH_1_POINT_583 = GEOMETRIC_ZENITH + 1.583;
9783
+ /**
9784
+ * The zenith of civil twilight; the sun is 6° below the horizon.
9785
+ * Matches `NOAACalculator.CIVIL_ZENITH`.
9786
+ */
9787
+ const CIVIL_ZENITH = GEOMETRIC_ZENITH + 6;
9788
+ /**
9789
+ * Length of one temporal (halachic) hour in milliseconds, i.e. one twelfth of
9790
+ * the day. Mirrors `NOAACalculator.getTemporalHour()`, including its floor, so
9791
+ * that results stay identical to the `ZonedDateTime` code path.
9792
+ * @private
9793
+ */
9794
+ function temporalHourMillis(startOfDay, endOfDay) {
9795
+ return Math.floor((endOfDay - startOfDay) / 12);
9796
+ }
9750
9797
  /**
9751
9798
  * Calculate halachic times (zmanim / זְמַנִּים) for a given day and location.
9752
9799
  * Calculations are available for tzeit / tzais (nightfall),
@@ -9789,11 +9836,10 @@ class Zmanim {
9789
9836
  constructor(gloc, date, useElevation) {
9790
9837
  this.hdate = new HDate(date);
9791
9838
  const dt = isDate(date) ? date : this.hdate.greg();
9792
- this.plainDate = Temporal.PlainDate.from({
9793
- year: dt.getFullYear(),
9794
- month: dt.getMonth() + 1,
9795
- day: dt.getDate(),
9796
- });
9839
+ // The constructor is ~1.8x cheaper than PlainDate.from(), which has to
9840
+ // walk a property bag and apply overflow handling. The fields come from a
9841
+ // real Date, so they are always in range and never need constraining.
9842
+ this.plainDate = new Temporal.PlainDate(dt.getFullYear(), dt.getMonth() + 1, dt.getDate());
9797
9843
  this.gloc = gloc;
9798
9844
  this.noaa = new NOAACalculator(gloc, this.plainDate);
9799
9845
  this.useElevation = Boolean(useElevation);
@@ -9827,46 +9873,64 @@ class Zmanim {
9827
9873
  */
9828
9874
  timeAtAngle(angle, rising) {
9829
9875
  const offsetZenith = GEOMETRIC_ZENITH + angle;
9830
- const zdt = rising
9831
- ? this.noaa.getSunriseOffsetByDegrees(offsetZenith)
9832
- : this.noaa.getSunsetOffsetByDegrees(offsetZenith);
9833
- return zdtToDate(zdt);
9876
+ return millisToDate(rising
9877
+ ? this.sunriseMillis(offsetZenith, true)
9878
+ : this.sunsetMillis(offsetZenith, true));
9879
+ }
9880
+ /**
9881
+ * Sunrise for a given zenith as epoch milliseconds, mirroring what
9882
+ * `NOAACalculator.getSunrise()` / `getSeaLevelSunrise()` /
9883
+ * `getSunriseOffsetByDegrees()` compute, minus the `ZonedDateTime`.
9884
+ *
9885
+ * Note that noaa's degree-based accessors pass `adjustForElevation = true`
9886
+ * as well; the adjustment is a no-op unless the zenith is exactly
9887
+ * {@link GEOMETRIC_ZENITH}, which is why degree-based zmanim are unaffected
9888
+ * by elevation.
9889
+ * @private
9890
+ */
9891
+ sunriseMillis(zenith, useElevation) {
9892
+ const utc = useElevation
9893
+ ? this.noaa.getUTCSunrise0(zenith)
9894
+ : this.noaa.getUTCSeaLevelSunrise(zenith);
9895
+ return this.noaa.getEpochMillisFromTime(utc, true);
9896
+ }
9897
+ /**
9898
+ * Sunset counterpart of {@link sunriseMillis}.
9899
+ * @private
9900
+ */
9901
+ sunsetMillis(zenith, useElevation) {
9902
+ const utc = useElevation
9903
+ ? this.noaa.getUTCSunset0(zenith)
9904
+ : this.noaa.getUTCSeaLevelSunset(zenith);
9905
+ return this.noaa.getEpochMillisFromTime(utc, false);
9834
9906
  }
9835
9907
  /**
9836
9908
  * Upper edge of the Sun appears over the eastern horizon in the morning (0.833° above horizon)
9837
9909
  * If elevation is enabled, this function will include elevation in the calculation.
9838
9910
  */
9839
9911
  sunrise() {
9840
- const zdt = this.useElevation
9841
- ? this.noaa.getSunrise()
9842
- : this.noaa.getSeaLevelSunrise();
9843
- return zdtToDate(zdt);
9912
+ return millisToDate(this.sunriseMillis(GEOMETRIC_ZENITH, this.useElevation));
9844
9913
  }
9845
9914
  /**
9846
9915
  * Upper edge of the Sun appears over the eastern horizon in the morning (0.833° above horizon).
9847
9916
  * This function does not support elevation adjustment.
9848
9917
  */
9849
9918
  seaLevelSunrise() {
9850
- const zdt = this.noaa.getSeaLevelSunrise();
9851
- return zdtToDate(zdt);
9919
+ return millisToDate(this.sunriseMillis(GEOMETRIC_ZENITH, false));
9852
9920
  }
9853
9921
  /**
9854
9922
  * When the upper edge of the Sun disappears below the horizon (0.833° below horizon).
9855
9923
  * If elevation is enabled, this function will include elevation in the calculation.
9856
9924
  */
9857
9925
  sunset() {
9858
- const zdt = this.useElevation
9859
- ? this.noaa.getSunset()
9860
- : this.noaa.getSeaLevelSunset();
9861
- return zdtToDate(zdt);
9926
+ return millisToDate(this.sunsetMillis(GEOMETRIC_ZENITH, this.useElevation));
9862
9927
  }
9863
9928
  /**
9864
9929
  * When the upper edge of the Sun disappears below the horizon (0.833° below horizon).
9865
9930
  * This function does not support elevation adjustment.
9866
9931
  */
9867
9932
  seaLevelSunset() {
9868
- const zdt = this.noaa.getSeaLevelSunset();
9869
- return zdtToDate(zdt);
9933
+ return millisToDate(this.sunsetMillis(GEOMETRIC_ZENITH, false));
9870
9934
  }
9871
9935
  /**
9872
9936
  * Civil dawn; Sun is 6° below the horizon in the morning.
@@ -9874,8 +9938,7 @@ class Zmanim {
9874
9938
  * the result is not impacted by elevation.
9875
9939
  */
9876
9940
  dawn() {
9877
- const zdt = this.noaa.getBeginCivilTwilight();
9878
- return zdtToDate(zdt);
9941
+ return millisToDate(this.sunriseMillis(CIVIL_ZENITH, true));
9879
9942
  }
9880
9943
  /**
9881
9944
  * Civil dusk; Sun is 6° below the horizon in the evening.
@@ -9883,8 +9946,7 @@ class Zmanim {
9883
9946
  * the result is not impacted by elevation.
9884
9947
  */
9885
9948
  dusk() {
9886
- const zdt = this.noaa.getEndCivilTwilight();
9887
- return zdtToDate(zdt);
9949
+ return millisToDate(this.sunsetMillis(CIVIL_ZENITH, true));
9888
9950
  }
9889
9951
  /**
9890
9952
  * Returns sunset for the previous day.
@@ -9912,10 +9974,10 @@ class Zmanim {
9912
9974
  * `useElevation` setting.
9913
9975
  */
9914
9976
  chatzot() {
9915
- const startOfDay = this.noaa.getSeaLevelSunrise();
9916
- const endOfDay = this.noaa.getSeaLevelSunset();
9917
- const zdt = this.noaa.getSunTransit(startOfDay, endOfDay);
9918
- return zdtToDate(zdt);
9977
+ const startOfDay = this.sunriseMillis(GEOMETRIC_ZENITH, false);
9978
+ const endOfDay = this.sunsetMillis(GEOMETRIC_ZENITH, false);
9979
+ // NOAACalculator.getSunTransit(): sunrise plus 6 temporal hours
9980
+ return millisToDate(startOfDay + temporalHourMillis(startOfDay, endOfDay) * 6);
9919
9981
  }
9920
9982
  /**
9921
9983
  * Midnight – Chatzot; Sunset plus 6 halachic hours.
@@ -9969,25 +10031,18 @@ class Zmanim {
9969
10031
  misheyakirMachmir() {
9970
10032
  return this.timeAtAngle(10.2, true);
9971
10033
  }
9972
- getShaahZmanisBasedZmanZdt(startOfDay, endOfDay, hours) {
9973
- const temporalHour = this.noaa.getTemporalHour(startOfDay, endOfDay);
9974
- const offset = Math.trunc(temporalHour * hours);
9975
- const zdt = NOAACalculator.getTimeOffset(startOfDay, offset);
9976
- return zdt;
10034
+ getShaahZmanisBasedZmanMillis(startOfDay, endOfDay, hours) {
10035
+ const offset = Math.trunc(temporalHourMillis(startOfDay, endOfDay) * hours);
10036
+ return startOfDay + offset;
9977
10037
  }
9978
10038
  /**
9979
10039
  * Utility method for using elevation-aware sunrise/sunset
9980
10040
  * @param hours number of _shaos zmaniyos_ (solar hours) after sunrise
9981
10041
  */
9982
10042
  getShaahZmanisBasedZman(hours) {
9983
- const startOfDay = this.useElevation
9984
- ? this.noaa.getSunrise()
9985
- : this.noaa.getSeaLevelSunrise();
9986
- const endOfDay = this.useElevation
9987
- ? this.noaa.getSunset()
9988
- : this.noaa.getSeaLevelSunset();
9989
- const zdt = this.getShaahZmanisBasedZmanZdt(startOfDay, endOfDay, hours);
9990
- return zdtToDate(zdt);
10043
+ const startOfDay = this.sunriseMillis(GEOMETRIC_ZENITH, this.useElevation);
10044
+ const endOfDay = this.sunsetMillis(GEOMETRIC_ZENITH, this.useElevation);
10045
+ return millisToDate(this.getShaahZmanisBasedZmanMillis(startOfDay, endOfDay, hours));
9991
10046
  }
9992
10047
  /**
9993
10048
  * Latest Shema (Gra); Sunrise plus 3 halachic hours, according to the Gra.
@@ -10485,7 +10540,7 @@ class Zmanim {
10485
10540
  * where it does not set, `null` will be returned.
10486
10541
  */
10487
10542
  getSunriseBaalHatanya() {
10488
- return this.noaa.getSunriseOffsetByDegrees(ZENITH_1_POINT_583);
10543
+ return this.sunriseMillis(ZENITH_1_POINT_583, true);
10489
10544
  }
10490
10545
  /**
10491
10546
  * A method that returns the [Baal Hatanya](https://en.wikipedia.org/wiki/Shneur_Zalman_of_Liadi)'s
@@ -10508,7 +10563,7 @@ class Zmanim {
10508
10563
  * rise, and one where it does not set, `null` will be returned.
10509
10564
  */
10510
10565
  getSunsetBaalHatanya() {
10511
- return this.noaa.getSunsetOffsetByDegrees(ZENITH_1_POINT_583);
10566
+ return this.sunsetMillis(ZENITH_1_POINT_583, true);
10512
10567
  }
10513
10568
  /**
10514
10569
  * Returns the [Baal Hatanya](https://en.wikipedia.org/wiki/Shneur_Zalman_of_Liadi)'s _alos_
@@ -10530,8 +10585,7 @@ class Zmanim {
10530
10585
  return this.timeAtAngle(16.9, true);
10531
10586
  }
10532
10587
  getShaahZmanisBaalHatanya(hours) {
10533
- const zdt = this.getShaahZmanisBasedZmanZdt(this.getSunriseBaalHatanya(), this.getSunsetBaalHatanya(), hours);
10534
- return zdtToDate(zdt);
10588
+ return millisToDate(this.getShaahZmanisBasedZmanMillis(this.getSunriseBaalHatanya(), this.getSunsetBaalHatanya(), hours));
10535
10589
  }
10536
10590
  /**
10537
10591
  * This method returns the latest _zman krias shema_ (time to recite Shema in the morning). This time is 3
@@ -10624,9 +10678,15 @@ class Zmanim {
10624
10678
  return 'XX:XX'; // Invalid Date
10625
10679
  }
10626
10680
  const time = timeFormat.format(dt);
10627
- const hm = time.split(':');
10628
- if (hm[0] === '24') {
10629
- return '00:' + hm[1];
10681
+ // Rewrite the h24 midnight ("24:15") that some locales produce. Checking
10682
+ // the two leading characters avoids the throwaway array that split(':')
10683
+ // allocated on every event; this runs once per timed event, and the
10684
+ // Intl.format() call above is already the expensive part.
10685
+ if (time.charCodeAt(0) === 0x32 && // '2'
10686
+ time.charCodeAt(1) === 0x34 && // '4'
10687
+ time.charCodeAt(2) === 0x3a // ':'
10688
+ ) {
10689
+ return '00' + time.substring(2);
10630
10690
  }
10631
10691
  return time;
10632
10692
  }