@hebcal/core 6.16.0 → 6.16.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.
Files changed (68) hide show
  1. package/README.md +2 -2
  2. package/dist/bundle.js +480 -382
  3. package/dist/bundle.js.map +1 -1
  4. package/dist/bundle.min.js +5 -5
  5. package/dist/bundle.min.js.map +1 -1
  6. package/dist/esm/DailyLearning.js +1 -1
  7. package/dist/esm/HebrewDateEvent.js +1 -1
  8. package/dist/esm/HolidayEvent.js +1 -1
  9. package/dist/esm/KiddushLevanaEvent.js +3 -4
  10. package/dist/esm/KiddushLevanaEvent.js.map +1 -1
  11. package/dist/esm/MevarchimChodeshEvent.js +1 -1
  12. package/dist/esm/ParshaEvent.js +1 -1
  13. package/dist/esm/TimedEvent.js +1 -1
  14. package/dist/esm/YomKippurKatanEvent.js +1 -1
  15. package/dist/esm/ashkenazi.po.js +1 -1
  16. package/dist/esm/calendar.js +4 -4
  17. package/dist/esm/calendar.js.map +1 -1
  18. package/dist/esm/candles.js +11 -3
  19. package/dist/esm/candles.js.map +1 -1
  20. package/dist/esm/cities.json.js +1 -1
  21. package/dist/esm/event.js +1 -1
  22. package/dist/esm/getStartAndEnd.js +2 -2
  23. package/dist/esm/getStartAndEnd.js.map +1 -1
  24. package/dist/esm/hallel.js +1 -1
  25. package/dist/esm/he-x-NoNikud.po.js +1 -1
  26. package/dist/esm/he.po.js +1 -1
  27. package/dist/esm/hebcal.js +3 -6
  28. package/dist/esm/hebcal.js.map +1 -1
  29. package/dist/esm/holidays.d.ts +17 -0
  30. package/dist/esm/holidays.js +78 -21
  31. package/dist/esm/holidays.js.map +1 -1
  32. package/dist/esm/horizon.js +1 -1
  33. package/dist/esm/index.d.ts +1 -0
  34. package/dist/esm/index.js +2 -1
  35. package/dist/esm/index.js.map +1 -1
  36. package/dist/esm/isAssurBemlacha.js +7 -23
  37. package/dist/esm/isAssurBemlacha.js.map +1 -1
  38. package/dist/esm/isAveilut.js +1 -1
  39. package/dist/esm/isFastDay.js +1 -1
  40. package/dist/esm/isYomTov.d.ts +21 -0
  41. package/dist/esm/isYomTov.js +46 -0
  42. package/dist/esm/isYomTov.js.map +1 -0
  43. package/dist/esm/locale.js +1 -1
  44. package/dist/esm/location.js +3 -3
  45. package/dist/esm/location.js.map +1 -1
  46. package/dist/esm/modern.js +1 -1
  47. package/dist/esm/molad.js +1 -1
  48. package/dist/esm/moladBase.js +1 -1
  49. package/dist/esm/moladDate.js +1 -1
  50. package/dist/esm/omer.js +2 -11
  51. package/dist/esm/omer.js.map +1 -1
  52. package/dist/esm/parshaName.js +1 -1
  53. package/dist/esm/parshaYear.js +1 -1
  54. package/dist/esm/pkgVersion.d.ts +1 -1
  55. package/dist/esm/pkgVersion.js +2 -2
  56. package/dist/esm/pkgVersion.js.map +1 -1
  57. package/dist/esm/reformatTimeStr.js +2 -2
  58. package/dist/esm/reformatTimeStr.js.map +1 -1
  59. package/dist/esm/sedra.js +2 -2
  60. package/dist/esm/sedra.js.map +1 -1
  61. package/dist/esm/sefira.json.js +1 -1
  62. package/dist/esm/staticHolidays.js +1 -1
  63. package/dist/esm/string.js +1 -1
  64. package/dist/esm/tachanun.js +1 -1
  65. package/dist/esm/zenith.js +1 -1
  66. package/dist/esm/zmanim.js +4 -4
  67. package/dist/esm/zmanim.js.map +1 -1
  68. package/package.json +10 -10
package/dist/bundle.js CHANGED
@@ -1,9 +1,9 @@
1
- /*! @hebcal/core v6.16.0, distributed under GPLv2 or later https://www.gnu.org/licenses/gpl-2.0.txt */
1
+ /*! @hebcal/core v6.16.3, distributed under GPLv2 or later 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.16.0';
6
+ const version = '6.16.3';
7
7
 
8
8
  /*! @hebcal/hdate v0.23.1, distributed under GPLv2 or later https://www.gnu.org/licenses/gpl-2.0.txt */
9
9
  /**
@@ -8708,8 +8708,25 @@ var citiesJson = [
8708
8708
  "Worcester|US|42.26259|-71.80229|America/New_York|164"
8709
8709
  ];
8710
8710
 
8711
+ // `maxSize` is a count, so a fraction is never meaningful. `Infinity` is allowed as an unbounded cache.
8712
+ // A `maxSize` past `Number.MAX_SAFE_INTEGER` is a count the cache can never reach. It is accepted today, so the check stays `Number.isInteger` instead of narrowing the values `maxSize` accepts.
8713
+ const isValidMaxSize = value => typeof value === 'number'
8714
+ && value > 0
8715
+ // eslint-disable-next-line unicorn/prefer-number-is-safe-integer
8716
+ && (Number.isInteger(value) || value === Infinity);
8717
+
8718
+ // A per-item `maxAge` of `NaN` stores a `NaN` expiry, which means no expiry. Zero is a real expiry, so this must not be a truthiness check.
8719
+ const hasExpiry = item => item.expiry !== undefined && !Number.isNaN(item.expiry);
8720
+
8721
+ // Modes for `#walk()`, by what it yields: a key, a value, a `[key, value]` pair, or the `[key, item]` pair that `evict()` and `resize()` need to act on the captured item.
8722
+ const MODE_KEYS = 0;
8723
+ const MODE_VALUES = 1;
8724
+ const MODE_ENTRIES = 2;
8725
+ const MODE_ITEMS = 3;
8726
+
8727
+ const INVALID_MAX_SIZE_MESSAGE = '`maxSize` must be a whole number greater than 0 or `Infinity`';
8728
+
8711
8729
  class QuickLRU extends Map {
8712
- #size = 0;
8713
8730
  #cache = new Map();
8714
8731
  #oldCache = new Map();
8715
8732
  #maxSize;
@@ -8719,72 +8736,62 @@ class QuickLRU extends Map {
8719
8736
  constructor(options = {}) {
8720
8737
  super();
8721
8738
 
8722
- if (!(options.maxSize && options.maxSize > 0)) {
8723
- throw new TypeError('`maxSize` must be a number greater than 0');
8739
+ if (!isValidMaxSize(options.maxSize)) {
8740
+ throw new TypeError(INVALID_MAX_SIZE_MESSAGE);
8724
8741
  }
8725
8742
 
8726
- if (typeof options.maxAge === 'number' && options.maxAge === 0) {
8743
+ if (typeof options.maxAge === 'number' && !(options.maxAge > 0)) {
8727
8744
  throw new TypeError('`maxAge` must be a number greater than 0');
8728
8745
  }
8729
8746
 
8730
8747
  this.#maxSize = options.maxSize;
8731
- this.#maxAge = options.maxAge || Number.POSITIVE_INFINITY;
8748
+ this.#maxAge = typeof options.maxAge === 'number' ? options.maxAge : Infinity;
8732
8749
  this.#onEviction = options.onEviction;
8733
8750
  }
8734
8751
 
8735
- // For tests.
8736
- get __oldCache() {
8737
- return this.#oldCache;
8738
- }
8739
-
8740
8752
  #emitEvictions(cache) {
8741
8753
  if (typeof this.#onEviction !== 'function') {
8742
8754
  return;
8743
8755
  }
8744
8756
 
8745
- for (const [key, item] of cache) {
8757
+ // A stale copy of a key that was written again is not an eviction, since the key is still in the cache. Filter before notifying, since a callback read can expire the current copy.
8758
+ const evictions = [...cache].filter(([key]) => !this.#cache.has(key) && !this.#oldCache.has(key));
8759
+ for (const [key, item] of evictions) {
8746
8760
  this.#onEviction(key, item.value);
8747
8761
  }
8748
8762
  }
8749
8763
 
8750
8764
  #deleteIfExpired(key, item) {
8751
- if (typeof item.expiry === 'number' && item.expiry <= Date.now()) {
8752
- if (typeof this.#onEviction === 'function') {
8765
+ if (hasExpiry(item) && item.expiry <= Date.now()) {
8766
+ // Remove before notifying, so a callback that reads the cache does not see the expired item.
8767
+ const deleted = this.delete(key);
8768
+ if (deleted && typeof this.#onEviction === 'function') {
8753
8769
  this.#onEviction(key, item.value);
8754
8770
  }
8755
8771
 
8756
- return this.delete(key);
8772
+ return deleted;
8757
8773
  }
8758
8774
 
8759
8775
  return false;
8760
8776
  }
8761
8777
 
8762
- #getOrDeleteIfExpired(key, item) {
8763
- const deleted = this.#deleteIfExpired(key, item);
8764
- if (deleted === false) {
8765
- return item.value;
8766
- }
8767
- }
8768
-
8778
+ // Returns the value, or `undefined` once the item has been removed as expired.
8769
8779
  #getItemValue(key, item) {
8770
- return item.expiry ? this.#getOrDeleteIfExpired(key, item) : item.value;
8780
+ return this.#deleteIfExpired(key, item) === false ? item.value : undefined;
8771
8781
  }
8772
8782
 
8773
- #peek(key, cache) {
8774
- const item = cache.get(key);
8775
- return this.#getItemValue(key, item);
8776
- }
8777
-
8778
- #set(key, value) {
8779
- this.#cache.set(key, value);
8780
- this.#size++;
8783
+ #set(key, item) {
8784
+ this.#cache.set(key, item);
8781
8785
 
8782
- if (this.#size >= this.#maxSize) {
8783
- this.#size = 0;
8784
- this.#emitEvictions(this.#oldCache);
8785
- this.#oldCache = this.#cache;
8786
- this.#cache = new Map();
8786
+ if (this.#cache.size < this.#maxSize) {
8787
+ return;
8787
8788
  }
8789
+
8790
+ const oldCache = this.#oldCache;
8791
+ this.#oldCache = this.#cache;
8792
+ this.#cache = new Map();
8793
+ // Emit after the swap, so a throwing callback cannot leave the caches out of sync.
8794
+ this.#emitEvictions(oldCache);
8788
8795
  }
8789
8796
 
8790
8797
  #moveToRecent(key, item) {
@@ -8792,124 +8799,164 @@ class QuickLRU extends Map {
8792
8799
  this.#set(key, item);
8793
8800
  }
8794
8801
 
8795
- * #entriesAscending() {
8796
- for (const item of this.#oldCache) {
8797
- const [key, value] = item;
8802
+ // The current item for `key`, or `undefined` if it is gone or has expired. The recent cache wins, since an old cache copy of a key that is in both is stale. Not a generator, since this runs once per item during iteration.
8803
+ #liveItem(key) {
8804
+ const item = this.#cache.get(key) ?? this.#oldCache.get(key);
8805
+ if (item !== undefined && this.#deleteIfExpired(key, item) === false) {
8806
+ return item;
8807
+ }
8808
+ }
8809
+
8810
+ // The current item for `key`, promoted to the recent cache when it was in the old one, or `undefined` when the key is missing or has expired. Only for the methods that refresh recency, since promoting is what separates them from `peek()`. One lookup per cache, since where the item is found decides the promotion. Not a generator, since this runs once per lookup.
8811
+ #getLiveItem(key) {
8812
+ let item = this.#cache.get(key);
8813
+ if (item === undefined) {
8814
+ item = this.#oldCache.get(key);
8815
+ if (item === undefined || this.#deleteIfExpired(key, item)) {
8816
+ return;
8817
+ }
8818
+
8819
+ this.#moveToRecent(key, item);
8820
+ } else if (this.#deleteIfExpired(key, item)) {
8821
+ return;
8822
+ }
8823
+
8824
+ return item;
8825
+ }
8826
+
8827
+ // The old cache keys that are not also in the recent cache, since an old copy of such a key is stale. A plain loop, since this runs once per item during iteration.
8828
+ #olderKeys() {
8829
+ const keys = [];
8830
+ for (const key of this.#oldCache.keys()) {
8798
8831
  if (!this.#cache.has(key)) {
8799
- const deleted = this.#deleteIfExpired(key, value);
8800
- if (deleted === false) {
8801
- yield item;
8802
- }
8832
+ keys.push(key);
8803
8833
  }
8804
8834
  }
8805
8835
 
8806
- for (const item of this.#cache) {
8807
- const [key, value] = item;
8808
- const deleted = this.#deleteIfExpired(key, value);
8809
- if (deleted === false) {
8810
- yield item;
8836
+ return keys;
8837
+ }
8838
+
8839
+ * #walk(mode, descending) {
8840
+ // Snapshot the keys, so writes during the walk cannot make it visit a key twice or loop forever. The old keys not also in the recent cache come first, then the recent cache, which ascends in recency. Reversing that list is the descending order, so both directions share this loop.
8841
+ const keys = [...this.#olderKeys(), ...this.#cache.keys()];
8842
+ if (descending) {
8843
+ keys.reverse();
8844
+ }
8845
+
8846
+ for (const key of keys) {
8847
+ const item = this.#liveItem(key);
8848
+ if (item === undefined) {
8849
+ continue;
8850
+ }
8851
+
8852
+ // The dispatch is an else-if chain because a `switch` would need a `break` per case inside the walk's loop, which lint flags.
8853
+ // eslint-disable-next-line unicorn/prefer-switch
8854
+ if (mode === MODE_KEYS) {
8855
+ yield key;
8856
+ } else if (mode === MODE_VALUES) {
8857
+ yield item.value;
8858
+ } else if (mode === MODE_ITEMS) {
8859
+ yield [key, item];
8860
+ } else {
8861
+ // MODE_ENTRIES.
8862
+ yield [key, item.value];
8811
8863
  }
8812
8864
  }
8813
8865
  }
8814
8866
 
8867
+ // For tests. Public on purpose, so the test suite can see where an item lives.
8868
+ // eslint-disable-next-line unicorn/prefer-private-class-fields
8869
+ get __oldCache() {
8870
+ return this.#oldCache;
8871
+ }
8872
+
8815
8873
  get(key) {
8816
- if (this.#cache.has(key)) {
8817
- const item = this.#cache.get(key);
8818
- return this.#getItemValue(key, item);
8874
+ const item = this.#getLiveItem(key);
8875
+ return item === undefined ? undefined : item.value;
8876
+ }
8877
+
8878
+ getOrInsert(key, value) {
8879
+ // One lookup, so a stored `undefined` does not pay for a second round, and an item that expires during the call is treated as missing.
8880
+ const item = this.#getLiveItem(key);
8881
+ if (item === undefined) {
8882
+ this.set(key, value);
8883
+ return value;
8819
8884
  }
8820
8885
 
8821
- if (this.#oldCache.has(key)) {
8822
- const item = this.#oldCache.get(key);
8823
- if (this.#deleteIfExpired(key, item) === false) {
8824
- this.#moveToRecent(key, item);
8825
- return item.value;
8826
- }
8886
+ return item.value;
8887
+ }
8888
+
8889
+ getOrInsertComputed(key, callback) {
8890
+ const item = this.#getLiveItem(key);
8891
+ if (item === undefined) {
8892
+ // Only called for a missing key, matching `Map`.
8893
+ const value = callback(key);
8894
+ this.set(key, value);
8895
+ return value;
8827
8896
  }
8897
+
8898
+ return item.value;
8828
8899
  }
8829
8900
 
8830
8901
  set(key, value, {maxAge = this.#maxAge} = {}) {
8831
- const expiry = typeof maxAge === 'number' && maxAge !== Number.POSITIVE_INFINITY
8902
+ const expiry = typeof maxAge === 'number' && maxAge !== Infinity
8832
8903
  ? (Date.now() + maxAge)
8833
8904
  : undefined;
8834
8905
 
8835
- if (this.#cache.has(key)) {
8836
- this.#cache.set(key, {
8837
- value,
8838
- expiry,
8839
- });
8840
- } else {
8841
- this.#set(key, {value, expiry});
8842
- }
8906
+ // No lookup is spent telling an existing key from a new one: `#set()` updates a hit in place, since a hit cannot fill the cache, and only an insert can grow it into a rotation. An old cache copy of a re-set key is left in place, stale, and the next rotation drops it.
8907
+ this.#set(key, {value, expiry});
8843
8908
 
8844
8909
  return this;
8845
8910
  }
8846
8911
 
8847
8912
  has(key) {
8848
- if (this.#cache.has(key)) {
8849
- return !this.#deleteIfExpired(key, this.#cache.get(key));
8850
- }
8851
-
8852
- if (this.#oldCache.has(key)) {
8853
- return !this.#deleteIfExpired(key, this.#oldCache.get(key));
8854
- }
8855
-
8856
- return false;
8913
+ const item = this.#cache.get(key) ?? this.#oldCache.get(key);
8914
+ return item !== undefined && !this.#deleteIfExpired(key, item);
8857
8915
  }
8858
8916
 
8859
8917
  peek(key) {
8860
- if (this.#cache.has(key)) {
8861
- return this.#peek(key, this.#cache);
8862
- }
8863
-
8864
- if (this.#oldCache.has(key)) {
8865
- return this.#peek(key, this.#oldCache);
8866
- }
8918
+ const item = this.#cache.get(key) ?? this.#oldCache.get(key);
8919
+ return item === undefined ? undefined : this.#getItemValue(key, item);
8867
8920
  }
8868
8921
 
8869
8922
  expiresIn(key) {
8870
8923
  const item = this.#cache.get(key) ?? this.#oldCache.get(key);
8871
8924
  if (item) {
8872
- return item.expiry ? item.expiry - Date.now() : Number.POSITIVE_INFINITY;
8925
+ return hasExpiry(item) ? item.expiry - Date.now() : Infinity;
8873
8926
  }
8874
8927
  }
8875
8928
 
8876
8929
  delete(key) {
8877
8930
  const deleted = this.#cache.delete(key);
8878
- if (deleted) {
8879
- this.#size--;
8880
- }
8881
-
8882
8931
  return this.#oldCache.delete(key) || deleted;
8883
8932
  }
8884
8933
 
8885
8934
  clear() {
8886
8935
  this.#cache.clear();
8887
8936
  this.#oldCache.clear();
8888
- this.#size = 0;
8889
8937
  }
8890
8938
 
8891
8939
  resize(newSize) {
8892
- if (!(newSize && newSize > 0)) {
8893
- throw new TypeError('`maxSize` must be a number greater than 0');
8940
+ if (!isValidMaxSize(newSize)) {
8941
+ throw new TypeError(INVALID_MAX_SIZE_MESSAGE);
8894
8942
  }
8895
8943
 
8896
- const items = [...this.#entriesAscending()];
8944
+ const items = [...this.#walk(MODE_ITEMS)];
8897
8945
  const removeCount = items.length - newSize;
8898
8946
  if (removeCount < 0) {
8899
8947
  this.#cache = new Map(items);
8900
8948
  this.#oldCache = new Map();
8901
- this.#size = items.length;
8902
8949
  } else {
8903
- if (removeCount > 0) {
8904
- this.#emitEvictions(items.slice(0, removeCount));
8905
- }
8906
-
8907
8950
  this.#oldCache = new Map(items.slice(removeCount));
8908
8951
  this.#cache = new Map();
8909
- this.#size = 0;
8910
8952
  }
8911
8953
 
8912
8954
  this.#maxSize = newSize;
8955
+
8956
+ if (removeCount > 0) {
8957
+ // Emit after the rebuild, so a callback that throws or writes cannot undo it.
8958
+ this.#emitEvictions(items.slice(0, removeCount));
8959
+ }
8913
8960
  }
8914
8961
 
8915
8962
  evict(count = 1) {
@@ -8918,93 +8965,67 @@ class QuickLRU extends Map {
8918
8965
  return;
8919
8966
  }
8920
8967
 
8921
- const items = [...this.#entriesAscending()];
8922
- const evictCount = Math.trunc(Math.min(requested, Math.max(items.length - 1, 0)));
8923
- if (evictCount <= 0) {
8924
- return;
8968
+ // Delete the oldest items where they live. Rebuilding the caches would empty the recent cache, which counts toward the rotation, and repeated calls would then keep deferring the rotation, so the cache would grow without limit.
8969
+ const live = [...this.#walk(MODE_ITEMS)];
8970
+
8971
+ const evictCount = Math.min(Math.trunc(requested), Math.max(live.length - 1, 0));
8972
+ const evicted = [];
8973
+ for (const [key] of live.slice(0, evictCount)) {
8974
+ // A callback during the walk can change the cache, so report the current item, and only if it is still there.
8975
+ const item = this.#cache.get(key) ?? this.#oldCache.get(key);
8976
+ if (item !== undefined && this.delete(key)) {
8977
+ evicted.push([key, item]);
8978
+ }
8925
8979
  }
8926
8980
 
8927
- this.#emitEvictions(items.slice(0, evictCount));
8928
- this.#oldCache = new Map(items.slice(evictCount));
8929
- this.#cache = new Map();
8930
- this.#size = 0;
8981
+ // Emit after the removals, so a callback that throws or writes cannot undo them.
8982
+ this.#emitEvictions(evicted);
8931
8983
  }
8932
8984
 
8933
- * keys() {
8934
- for (const [key] of this) {
8935
- yield key;
8936
- }
8985
+ keys() {
8986
+ return this.#walk(MODE_KEYS);
8937
8987
  }
8938
8988
 
8939
- * values() {
8940
- for (const [, value] of this) {
8941
- yield value;
8942
- }
8989
+ values() {
8990
+ return this.#walk(MODE_VALUES);
8943
8991
  }
8944
8992
 
8945
- * [Symbol.iterator]() {
8946
- for (const item of this.#cache) {
8947
- const [key, value] = item;
8948
- const deleted = this.#deleteIfExpired(key, value);
8949
- if (deleted === false) {
8950
- yield [key, value.value];
8951
- }
8952
- }
8953
-
8954
- for (const item of this.#oldCache) {
8955
- const [key, value] = item;
8956
- if (!this.#cache.has(key)) {
8957
- const deleted = this.#deleteIfExpired(key, value);
8958
- if (deleted === false) {
8959
- yield [key, value.value];
8960
- }
8961
- }
8962
- }
8993
+ [Symbol.iterator]() {
8994
+ // `Map` requires the iterator, `keys()`, `values()` and `entries()` to agree on the order.
8995
+ return this.entriesAscending();
8963
8996
  }
8964
8997
 
8965
- * entriesDescending() {
8966
- let items = [...this.#cache];
8967
- for (let i = items.length - 1; i >= 0; --i) {
8968
- const item = items[i];
8969
- const [key, value] = item;
8970
- const deleted = this.#deleteIfExpired(key, value);
8971
- if (deleted === false) {
8972
- yield [key, value.value];
8973
- }
8974
- }
8975
-
8976
- items = [...this.#oldCache];
8977
- for (let i = items.length - 1; i >= 0; --i) {
8978
- const item = items[i];
8979
- const [key, value] = item;
8980
- if (!this.#cache.has(key)) {
8981
- const deleted = this.#deleteIfExpired(key, value);
8982
- if (deleted === false) {
8983
- yield [key, value.value];
8984
- }
8985
- }
8986
- }
8998
+ entriesDescending() {
8999
+ return this.#walk(MODE_ENTRIES, true);
8987
9000
  }
8988
9001
 
8989
- * entriesAscending() {
8990
- for (const [key, value] of this.#entriesAscending()) {
8991
- yield [key, value.value];
8992
- }
9002
+ entriesAscending() {
9003
+ return this.#walk(MODE_ENTRIES);
8993
9004
  }
8994
9005
 
8995
9006
  get size() {
8996
- if (!this.#size) {
8997
- return this.#oldCache.size;
9007
+ // A key that `set()` wrote again can be in both caches, so count it once. Either cache can be walked for that, so walk the smaller one, and skip the walk entirely while one is still empty.
9008
+ const recentSize = this.#cache.size;
9009
+ const olderSize = this.#oldCache.size;
9010
+ if (recentSize === 0 || olderSize === 0) {
9011
+ return Math.min(recentSize + olderSize, this.#maxSize);
8998
9012
  }
8999
9013
 
9000
- let oldCacheSize = 0;
9001
- for (const key of this.#oldCache.keys()) {
9002
- if (!this.#cache.has(key)) {
9003
- oldCacheSize++;
9014
+ let walked = this.#cache;
9015
+ let checked = this.#oldCache;
9016
+ if (olderSize < recentSize) {
9017
+ walked = this.#oldCache;
9018
+ checked = this.#cache;
9019
+ }
9020
+
9021
+ let duplicates = 0;
9022
+ for (const key of walked.keys()) {
9023
+ if (checked.has(key)) {
9024
+ duplicates++;
9004
9025
  }
9005
9026
  }
9006
9027
 
9007
- return Math.min(this.#size + oldCacheSize, this.#maxSize);
9028
+ return Math.min(recentSize + olderSize - duplicates, this.#maxSize);
9008
9029
  }
9009
9030
 
9010
9031
  get maxSize() {
@@ -9140,11 +9161,11 @@ class Location extends GeoLocation {
9140
9161
  * @param [elevation] - in meters (default `0`)
9141
9162
  */
9142
9163
  constructor(latitude, longitude, il, tzid, cityName, countryCode, geoid, elevation) {
9143
- const lat = typeof latitude === 'number' ? latitude : parseFloat(latitude);
9164
+ const lat = typeof latitude === 'number' ? latitude : Number.parseFloat(latitude);
9144
9165
  if (Number.isNaN(lat) || lat < -90 || lat > 90) {
9145
9166
  throw new RangeError(`Latitude ${latitude} out of range [-90,90]`);
9146
9167
  }
9147
- const long = typeof longitude === 'number' ? longitude : parseFloat(longitude);
9168
+ const long = typeof longitude === 'number' ? longitude : Number.parseFloat(longitude);
9148
9169
  if (Number.isNaN(long) || long < -180 || long > 180) {
9149
9170
  throw new RangeError(`Longitude ${longitude} out of range [-180,180]`);
9150
9171
  }
@@ -9418,7 +9439,7 @@ function reformatTimeStr(timeStr, suffix, options) {
9418
9439
  return timeStr;
9419
9440
  }
9420
9441
  const hm = timeStr.split(':');
9421
- let hour = parseInt(hm[0], 10);
9442
+ let hour = Number.parseInt(hm[0], 10);
9422
9443
  if (hour < 12 && suffix) {
9423
9444
  suffix = suffix.replace('p', 'a').replace('P', 'A');
9424
9445
  if (hour === 0) {
@@ -10727,7 +10748,7 @@ class Zmanim {
10727
10748
  // Evaluate the low end first so polar day/night (NaN time) is caught at once.
10728
10749
  const tLo = timeAt(aLo);
10729
10750
  if (Number.isNaN(tLo)) {
10730
- return millisToDate(NaN);
10751
+ return millisToDate(Number.NaN);
10731
10752
  }
10732
10753
  if (g(aLo) >= 0) {
10733
10754
  return millisToDate(tLo);
@@ -10735,7 +10756,7 @@ class Zmanim {
10735
10756
  let prevA = aLo;
10736
10757
  for (let a = aLo + step; a <= aHi + 1e-9; a += step) {
10737
10758
  if (Number.isNaN(timeAt(a))) {
10738
- return millisToDate(NaN);
10759
+ return millisToDate(Number.NaN);
10739
10760
  }
10740
10761
  if (g(a) >= 0) {
10741
10762
  // Crossing in (prevA, a): bisect the altitude bracket to 0.0005°.
@@ -10754,7 +10775,7 @@ class Zmanim {
10754
10775
  }
10755
10776
  prevA = a;
10756
10777
  }
10757
- return millisToDate(NaN);
10778
+ return millisToDate(Number.NaN);
10758
10779
  }
10759
10780
  /**
10760
10781
  * Rabbeinu Tam holds that bein hashmashos is a specific time
@@ -11297,7 +11318,153 @@ class Zmanim {
11297
11318
  }
11298
11319
  }
11299
11320
 
11300
- const { NISAN: NISAN$4, IYYAR: IYYAR$2, SIVAN: SIVAN$2, AV: AV$2, ELUL: ELUL$1, TISHREI: TISHREI$2, SHVAT, ADAR_II: ADAR_II$1 } = months;
11321
+ /**
11322
+ * Returns `true` if the given Hebrew date is a _Yom Tov_ with a _melacha_
11323
+ * (work) prohibition: Rosh Hashana, Yom Kippur, the first and last days of
11324
+ * Sukkot/Pesach, Shmini Atzeret, Simchat Torah (Diaspora) and Shavuot.
11325
+ *
11326
+ * These are exactly the days that carry the `CHAG` flag. Shabbat is not
11327
+ * considered, and neither is Chol HaMoed.
11328
+ *
11329
+ * The result is computed directly from the Hebrew month and day,
11330
+ * without generating holiday events.
11331
+ * @example
11332
+ * import {isYomTov, HDate, months} from '@hebcal/core';
11333
+ * isYomTov(new HDate(10, months.TISHREI, 5785), false); // true (Yom Kippur)
11334
+ * isYomTov(new HDate(16, months.NISAN, 5784), false); // true (Pesach II)
11335
+ * isYomTov(new HDate(16, months.NISAN, 5784), true); // false (Chol HaMoed)
11336
+ * isYomTov(new HDate(25, months.KISLEV, 5784), false); // false (Chanukah)
11337
+ * @param hdate Hebrew date to test
11338
+ * @param il use the Israeli holiday schedule
11339
+ */
11340
+ function isYomTov(hdate, il) {
11341
+ const dd = hdate.getDate();
11342
+ switch (hdate.getMonth()) {
11343
+ case months.TISHREI:
11344
+ return (dd === 1 || // Rosh Hashana I
11345
+ dd === 2 || // Rosh Hashana II
11346
+ dd === 10 || // Yom Kippur
11347
+ dd === 15 || // Sukkot I
11348
+ dd === 22 || // Shmini Atzeret
11349
+ (!il && (dd === 16 || dd === 23)) // Sukkot II, Simchat Torah
11350
+ );
11351
+ case months.NISAN:
11352
+ // Pesach I and VII, plus Pesach II and VIII in the Diaspora
11353
+ return dd === 15 || dd === 21 || (!il && (dd === 16 || dd === 22));
11354
+ case months.SIVAN:
11355
+ // Shavuot, plus a second day in the Diaspora
11356
+ return dd === 6 || (!il && dd === 7);
11357
+ default:
11358
+ return false;
11359
+ }
11360
+ }
11361
+
11362
+ /**
11363
+ * Returns `true` if the given moment (date + time) falls within a period
11364
+ * when *melacha* (work) is prohibited — i.e. Shabbat or a Yom Tov.
11365
+ *
11366
+ * The Shabbat/Yom Tov window is taken to begin at sunset (shkiah) on the
11367
+ * preceding day (Erev Shabbat / Erev Yom Tov / Yom Tov sheni) and to end
11368
+ * at *tzais* (nightfall) on the day itself. *Tzais* is calculated using a
11369
+ * solar depression of 8.5° for simplicity; consult a halachic authority
11370
+ * for more stringent opinions.
11371
+ *
11372
+ * `useElevation` controls whether the location's elevation is taken into
11373
+ * account when computing sunset (it has no effect on the degree-based
11374
+ * tzais calculation). The Israel/Diaspora schedule comes from
11375
+ * `location.getIsrael()`.
11376
+ *
11377
+ * Throws if sunset cannot be calculated for the given location
11378
+ * (e.g. polar regions).
11379
+ * @example
11380
+ * import {isAssurBemlacha, Location} from '@hebcal/core';
11381
+ * const loc = Location.lookup('Jerusalem')!;
11382
+ * // Friday after sunset:
11383
+ * isAssurBemlacha(new Date('2024-04-26T18:00:00Z'), loc, false); // true
11384
+ * @param currentTime the moment to test (with hour/minute)
11385
+ * @param location geographic location (also supplies Israel/Diaspora flag and tzid)
11386
+ * @param useElevation include elevation when computing sunset
11387
+ * @return `true` if *melacha* is prohibited, `false` if it is not
11388
+ */
11389
+ function isAssurBemlacha(currentTime, location, useElevation) {
11390
+ // Determine the calendar date in the location's timezone, not the
11391
+ // timezone of the computer running this code. Otherwise the day-of-week,
11392
+ // Hebrew date and sunset/tzais times would depend on the machine's
11393
+ // local timezone, giving different (incorrect) results near midnight.
11394
+ const isoDate = getPseudoISO(location.getTzid(), currentTime);
11395
+ const year = Number.parseInt(isoDate.substring(0, 4), 10);
11396
+ const month = Number.parseInt(isoDate.substring(5, 7), 10);
11397
+ const day = Number.parseInt(isoDate.substring(8, 10), 10);
11398
+ const hd = new HDate(new Date(year, month - 1, day));
11399
+ const zmanim = new Zmanim(location, hd, useElevation);
11400
+ // erev shabbos, YT or YT sheni and after shkiah
11401
+ const sunset = zmanim.sunset();
11402
+ const sunsetMillis = sunset.getTime();
11403
+ if (Number.isNaN(sunsetMillis)) {
11404
+ throw new Error('Could not determine sunset');
11405
+ }
11406
+ // erev shabbos, YT or YT sheni and after shkiah
11407
+ const il = location.getIsrael();
11408
+ const currentMillis = currentTime.getTime();
11409
+ const dow = hd.getDay();
11410
+ if (currentMillis >= sunsetMillis && (dow === 5 || isYomTov(hd.next(), il))) {
11411
+ return true;
11412
+ }
11413
+ // is shabbos or YT and it is before tzais
11414
+ if (dow === 6 || isYomTov(hd, il)) {
11415
+ const tzais = zmanim.tzeit();
11416
+ const tzaisMillis = tzais.getTime();
11417
+ return currentMillis <= tzaisMillis;
11418
+ }
11419
+ return false;
11420
+ }
11421
+
11422
+ const { NISAN: NISAN$4, SIVAN: SIVAN$2, TAMUZ: TAMUZ$1, AV: AV$2 } = months;
11423
+ const SAT$2 = 6;
11424
+ function getHDate(date) {
11425
+ return HDate.isHDate(date) ? date : new HDate(date);
11426
+ }
11427
+ function isSefiratHaOmer(hd) {
11428
+ const hyear = hd.getFullYear();
11429
+ const beginOmer = new HDate(16, NISAN$4, hyear).abs();
11430
+ const endOmer = new HDate(5, SIVAN$2, hyear).abs();
11431
+ const abs = hd.abs();
11432
+ return abs >= beginOmer && abs <= endOmer;
11433
+ }
11434
+ function isBeinHaMetzarim(hd) {
11435
+ const hyear = hd.getFullYear();
11436
+ const begin = new HDate(17, TAMUZ$1, hyear).abs();
11437
+ const tishaBav = new HDate(9, AV$2, hyear);
11438
+ const end = tishaBav.getDay() === SAT$2 ? new HDate(10, AV$2, hyear).abs() : tishaBav.abs();
11439
+ const abs = hd.abs();
11440
+ return abs >= begin && abs <= end;
11441
+ }
11442
+ /**
11443
+ * Returns `true` if the given date falls within a public period of communal
11444
+ * mourning — specifically:
11445
+ *
11446
+ * - **Sefirat HaOmer**: 16 Nisan through 5 Sivan (the 49 days of the Omer).
11447
+ * - **Bein HaMetzarim** ("between the straits"): 17 Tammuz through 9 Av
11448
+ * (10 Av when 9 Av is postponed because it falls on Shabbat).
11449
+ *
11450
+ * This is a broad helper — it does not attempt to model minhag-specific
11451
+ * exceptions within those periods (e.g. Lag BaOmer, Rosh Chodesh Iyar,
11452
+ * the distinction between Sephardic and Ashkenazic customs on which
11453
+ * portion of the Omer is observed as mourning, etc.).
11454
+ * @example
11455
+ * import {isAveilut, HDate, months} from '@hebcal/core';
11456
+ * isAveilut(new HDate(20, months.NISAN, 5784)); // true (Omer)
11457
+ * isAveilut(new HDate(25, months.TAMUZ, 5784)); // true (Three Weeks)
11458
+ * isAveilut(new HDate(15, months.AV, 5784)); // false
11459
+ * @param date Hebrew Date, Gregorian date, or absolute R.D. day number
11460
+ * @return `true` if the date is during a mourning period
11461
+ */
11462
+ function isAveilut(date) {
11463
+ const hd = getHDate(date);
11464
+ return isSefiratHaOmer(hd) || isBeinHaMetzarim(hd);
11465
+ }
11466
+
11467
+ const { NISAN: NISAN$3, IYYAR: IYYAR$2, SIVAN: SIVAN$1, AV: AV$1, ELUL: ELUL$1, TISHREI: TISHREI$2, SHVAT, ADAR_II: ADAR_II$1 } = months;
11301
11468
  const { CHAG: CHAG$1, LIGHT_CANDLES: LIGHT_CANDLES$2, YOM_TOV_ENDS: YOM_TOV_ENDS$1, CHUL_ONLY: CHUL_ONLY$1, IL_ONLY: IL_ONLY$2, LIGHT_CANDLES_TZEIS: LIGHT_CANDLES_TZEIS$3, MAJOR_FAST: MAJOR_FAST$2, MINOR_HOLIDAY: MINOR_HOLIDAY$2, EREV: EREV$2, CHOL_HAMOED: CHOL_HAMOED$1, } = flags;
11302
11469
  /**
11303
11470
  * Transliterated names of holidays, used by `Event.getDesc()`
@@ -11558,82 +11725,82 @@ const staticHolidays = [
11558
11725
  holiday(ADAR_II$1, 14, d.PURIM, MINOR_HOLIDAY$2, { emoji: emojiPurim }),
11559
11726
  holiday(ADAR_II$1, 15, d.SHUSHAN_PURIM, MINOR_HOLIDAY$2, { emoji: emojiPurim }),
11560
11727
  // Pesach Israel
11561
- holiday(NISAN$4, 14, d.EREV_PESACH, IL_ONLY$2 | EREV$2 | LIGHT_CANDLES$2, {
11728
+ holiday(NISAN$3, 14, d.EREV_PESACH, IL_ONLY$2 | EREV$2 | LIGHT_CANDLES$2, {
11562
11729
  emoji: emojiErevPesach,
11563
11730
  }),
11564
- holiday(NISAN$4, 15, d.PESACH_I, IL_ONLY$2 | CHAG$1 | YOM_TOV_ENDS$1, {
11731
+ holiday(NISAN$3, 15, d.PESACH_I, IL_ONLY$2 | CHAG$1 | YOM_TOV_ENDS$1, {
11565
11732
  emoji: emojiPesach,
11566
11733
  }),
11567
- holiday(NISAN$4, 16, d.PESACH_II_CHM, IL_ONLY$2 | CHOL_HAMOED$1, {
11734
+ holiday(NISAN$3, 16, d.PESACH_II_CHM, IL_ONLY$2 | CHOL_HAMOED$1, {
11568
11735
  chmDay: 1,
11569
11736
  emoji: emojiPesach,
11570
11737
  }),
11571
- holiday(NISAN$4, 17, d.PESACH_III_CHM, IL_ONLY$2 | CHOL_HAMOED$1, {
11738
+ holiday(NISAN$3, 17, d.PESACH_III_CHM, IL_ONLY$2 | CHOL_HAMOED$1, {
11572
11739
  chmDay: 2,
11573
11740
  emoji: emojiPesach,
11574
11741
  }),
11575
- holiday(NISAN$4, 18, d.PESACH_IV_CHM, IL_ONLY$2 | CHOL_HAMOED$1, {
11742
+ holiday(NISAN$3, 18, d.PESACH_IV_CHM, IL_ONLY$2 | CHOL_HAMOED$1, {
11576
11743
  chmDay: 3,
11577
11744
  emoji: emojiPesach,
11578
11745
  }),
11579
- holiday(NISAN$4, 19, d.PESACH_V_CHM, IL_ONLY$2 | CHOL_HAMOED$1, {
11746
+ holiday(NISAN$3, 19, d.PESACH_V_CHM, IL_ONLY$2 | CHOL_HAMOED$1, {
11580
11747
  chmDay: 4,
11581
11748
  emoji: emojiPesach,
11582
11749
  }),
11583
- holiday(NISAN$4, 20, d.PESACH_VI_CHM, IL_ONLY$2 | CHOL_HAMOED$1 | LIGHT_CANDLES$2, {
11750
+ holiday(NISAN$3, 20, d.PESACH_VI_CHM, IL_ONLY$2 | CHOL_HAMOED$1 | LIGHT_CANDLES$2, {
11584
11751
  chmDay: 5,
11585
11752
  emoji: emojiPesach,
11586
11753
  }),
11587
- holiday(NISAN$4, 21, d.PESACH_VII, IL_ONLY$2 | CHAG$1 | YOM_TOV_ENDS$1, {
11754
+ holiday(NISAN$3, 21, d.PESACH_VII, IL_ONLY$2 | CHAG$1 | YOM_TOV_ENDS$1, {
11588
11755
  emoji: emojiPesach,
11589
11756
  }),
11590
11757
  // Pesach chutz l'aretz
11591
- holiday(NISAN$4, 14, d.EREV_PESACH, CHUL_ONLY$1 | EREV$2 | LIGHT_CANDLES$2, {
11758
+ holiday(NISAN$3, 14, d.EREV_PESACH, CHUL_ONLY$1 | EREV$2 | LIGHT_CANDLES$2, {
11592
11759
  emoji: emojiErevPesach,
11593
11760
  }),
11594
- holiday(NISAN$4, 15, d.PESACH_I, CHUL_ONLY$1 | CHAG$1 | LIGHT_CANDLES_TZEIS$3, {
11761
+ holiday(NISAN$3, 15, d.PESACH_I, CHUL_ONLY$1 | CHAG$1 | LIGHT_CANDLES_TZEIS$3, {
11595
11762
  emoji: emojiErevPesach,
11596
11763
  }),
11597
- holiday(NISAN$4, 16, d.PESACH_II, CHUL_ONLY$1 | CHAG$1 | YOM_TOV_ENDS$1, {
11764
+ holiday(NISAN$3, 16, d.PESACH_II, CHUL_ONLY$1 | CHAG$1 | YOM_TOV_ENDS$1, {
11598
11765
  emoji: emojiPesach,
11599
11766
  }),
11600
- holiday(NISAN$4, 17, d.PESACH_III_CHM, CHUL_ONLY$1 | CHOL_HAMOED$1, {
11767
+ holiday(NISAN$3, 17, d.PESACH_III_CHM, CHUL_ONLY$1 | CHOL_HAMOED$1, {
11601
11768
  chmDay: 1,
11602
11769
  emoji: emojiPesach,
11603
11770
  }),
11604
- holiday(NISAN$4, 18, d.PESACH_IV_CHM, CHUL_ONLY$1 | CHOL_HAMOED$1, {
11771
+ holiday(NISAN$3, 18, d.PESACH_IV_CHM, CHUL_ONLY$1 | CHOL_HAMOED$1, {
11605
11772
  chmDay: 2,
11606
11773
  emoji: emojiPesach,
11607
11774
  }),
11608
- holiday(NISAN$4, 19, d.PESACH_V_CHM, CHUL_ONLY$1 | CHOL_HAMOED$1, {
11775
+ holiday(NISAN$3, 19, d.PESACH_V_CHM, CHUL_ONLY$1 | CHOL_HAMOED$1, {
11609
11776
  chmDay: 3,
11610
11777
  emoji: emojiPesach,
11611
11778
  }),
11612
- holiday(NISAN$4, 20, d.PESACH_VI_CHM, CHUL_ONLY$1 | CHOL_HAMOED$1 | LIGHT_CANDLES$2, {
11779
+ holiday(NISAN$3, 20, d.PESACH_VI_CHM, CHUL_ONLY$1 | CHOL_HAMOED$1 | LIGHT_CANDLES$2, {
11613
11780
  chmDay: 4,
11614
11781
  emoji: emojiPesach,
11615
11782
  }),
11616
- holiday(NISAN$4, 21, d.PESACH_VII, CHUL_ONLY$1 | CHAG$1 | LIGHT_CANDLES_TZEIS$3, {
11783
+ holiday(NISAN$3, 21, d.PESACH_VII, CHUL_ONLY$1 | CHAG$1 | LIGHT_CANDLES_TZEIS$3, {
11617
11784
  emoji: emojiPesach,
11618
11785
  }),
11619
- holiday(NISAN$4, 22, d.PESACH_VIII, CHUL_ONLY$1 | CHAG$1 | YOM_TOV_ENDS$1, {
11786
+ holiday(NISAN$3, 22, d.PESACH_VIII, CHUL_ONLY$1 | CHAG$1 | YOM_TOV_ENDS$1, {
11620
11787
  emoji: emojiPesach,
11621
11788
  }),
11622
11789
  holiday(IYYAR$2, 14, d.PESACH_SHENI, MINOR_HOLIDAY$2),
11623
11790
  holiday(IYYAR$2, 18, d.LAG_BAOMER, MINOR_HOLIDAY$2, { emoji: '🔥' }),
11624
- holiday(SIVAN$2, 5, d.EREV_SHAVUOT, EREV$2 | LIGHT_CANDLES$2, {
11791
+ holiday(SIVAN$1, 5, d.EREV_SHAVUOT, EREV$2 | LIGHT_CANDLES$2, {
11625
11792
  emoji: emojiShavuot,
11626
11793
  }),
11627
- holiday(SIVAN$2, 6, d.SHAVUOT, IL_ONLY$2 | CHAG$1 | YOM_TOV_ENDS$1, {
11794
+ holiday(SIVAN$1, 6, d.SHAVUOT, IL_ONLY$2 | CHAG$1 | YOM_TOV_ENDS$1, {
11628
11795
  emoji: emojiShavuot,
11629
11796
  }),
11630
- holiday(SIVAN$2, 6, d.SHAVUOT_I, CHUL_ONLY$1 | CHAG$1 | LIGHT_CANDLES_TZEIS$3, {
11797
+ holiday(SIVAN$1, 6, d.SHAVUOT_I, CHUL_ONLY$1 | CHAG$1 | LIGHT_CANDLES_TZEIS$3, {
11631
11798
  emoji: emojiShavuot,
11632
11799
  }),
11633
- holiday(SIVAN$2, 7, d.SHAVUOT_II, CHUL_ONLY$1 | CHAG$1 | YOM_TOV_ENDS$1, {
11800
+ holiday(SIVAN$1, 7, d.SHAVUOT_II, CHUL_ONLY$1 | CHAG$1 | YOM_TOV_ENDS$1, {
11634
11801
  emoji: emojiShavuot,
11635
11802
  }),
11636
- holiday(AV$2, 15, d.TU_BAV, MINOR_HOLIDAY$2, { emoji: '❤️' }),
11803
+ holiday(AV$1, 15, d.TU_BAV, MINOR_HOLIDAY$2, { emoji: '❤️' }),
11637
11804
  holiday(ELUL$1, 1, d.ROSH_HASHANA_LABEHEMOT, MINOR_HOLIDAY$2, { emoji: '🐑' }),
11638
11805
  holiday(ELUL$1, 29, d.EREV_ROSH_HASHANA, EREV$2 | LIGHT_CANDLES$2, {
11639
11806
  emoji: emojiRoshHashana,
@@ -11873,7 +12040,7 @@ var Day;
11873
12040
  Day[Day["FRI"] = 5] = "FRI";
11874
12041
  Day[Day["SAT"] = 6] = "SAT";
11875
12042
  })(Day || (Day = {}));
11876
- const { NISAN: NISAN$3, IYYAR: IYYAR$1, CHESHVAN: CHESHVAN$1 } = months;
12043
+ const { NISAN: NISAN$2, IYYAR: IYYAR$1, CHESHVAN: CHESHVAN$1 } = months;
11877
12044
  /**
11878
12045
  * Yom HaShoah first observed in 1951.
11879
12046
  * When the actual date of Yom Hashoah falls on a Friday, the
@@ -11886,12 +12053,12 @@ function dateYomHaShoah(year) {
11886
12053
  if (year < 5711) {
11887
12054
  return null;
11888
12055
  }
11889
- let nisan27dt = new HDate(27, NISAN$3, year);
12056
+ let nisan27dt = new HDate(27, NISAN$2, year);
11890
12057
  if (nisan27dt.getDay() === Day.FRI) {
11891
- nisan27dt = new HDate(26, NISAN$3, year);
12058
+ nisan27dt = new HDate(26, NISAN$2, year);
11892
12059
  }
11893
12060
  else if (nisan27dt.getDay() === Day.SUN) {
11894
- nisan27dt = new HDate(28, NISAN$3, year);
12061
+ nisan27dt = new HDate(28, NISAN$2, year);
11895
12062
  }
11896
12063
  return nisan27dt;
11897
12064
  }
@@ -11904,7 +12071,7 @@ function dateYomHaZikaron(year) {
11904
12071
  return null;
11905
12072
  }
11906
12073
  let day;
11907
- const pesach = new HDate(15, NISAN$3, year);
12074
+ const pesach = new HDate(15, NISAN$2, year);
11908
12075
  const pdow = pesach.getDay();
11909
12076
  if (pdow === Day.SUN) {
11910
12077
  day = 2;
@@ -11986,7 +12153,7 @@ const staticModernHolidays = [
11986
12153
  suppressEmoji: true,
11987
12154
  postpone: 'friSatToThu',
11988
12155
  },
11989
- { firstYear: 5777, mm: NISAN$3, dd: 10, desc: holidayDesc.YOM_HAALIYAH, chul: true },
12156
+ { firstYear: 5777, mm: NISAN$2, dd: 10, desc: holidayDesc.YOM_HAALIYAH, chul: true },
11990
12157
  {
11991
12158
  firstYear: 5777,
11992
12159
  mm: CHESHVAN$1,
@@ -12499,7 +12666,7 @@ const parshiot = [
12499
12666
  * date on or after Rosh Hashana of `year` (whose R.D. day is `rh`)
12500
12667
  */
12501
12668
  function toAbsInYear(hd, rh, year) {
12502
- const abs = typeof hd === 'number' ? hd : HDate.isHDate(hd) ? hd.abs() : NaN;
12669
+ const abs = typeof hd === 'number' ? hd : HDate.isHDate(hd) ? hd.abs() : Number.NaN;
12503
12670
  if (Number.isNaN(abs)) {
12504
12671
  throw new TypeError(`Bad date argument: ${hd}`);
12505
12672
  }
@@ -12868,10 +13035,24 @@ class YomKippurKatanEvent extends HolidayEvent {
12868
13035
  * @param [il] use the Israeli schedule for holidays
12869
13036
  */
12870
13037
  function getHolidaysOnDate(date, il) {
12871
- const hd = HDate.isHDate(date) ? date : new HDate(date);
12872
- const hdStr = hd.toString();
12873
- const yearMap = getHolidaysForYear_(hd.getFullYear());
12874
- const events = yearMap.get(hdStr);
13038
+ let abs;
13039
+ let entry;
13040
+ const last = lastEntry;
13041
+ if (typeof date === 'number' &&
13042
+ last !== undefined &&
13043
+ date >= last.startAbs &&
13044
+ date <= last.endAbs) {
13045
+ // Callers often walk day by day; skip the R.D. → Hebrew date
13046
+ // conversion while the date stays within the most recently used year.
13047
+ abs = date;
13048
+ entry = last;
13049
+ }
13050
+ else {
13051
+ const hd = HDate.isHDate(date) ? date : new HDate(date);
13052
+ abs = hd.abs();
13053
+ entry = getYearEntry(hd.getFullYear());
13054
+ }
13055
+ const events = entry.map.get(abs);
12875
13056
  // if il isn't a boolean return both diaspora + IL for day
12876
13057
  if (il === undefined || events === undefined) {
12877
13058
  return events;
@@ -12883,12 +13064,15 @@ const SUN = 0;
12883
13064
  const TUE = 2;
12884
13065
  const THU = 4;
12885
13066
  const FRI$1 = 5;
12886
- const SAT$2 = 6;
12887
- const { NISAN: NISAN$2, IYYAR, TAMUZ: TAMUZ$1, AV: AV$1, TISHREI: TISHREI$1, CHESHVAN, KISLEV, TEVET, ADAR_I, ADAR_II } = months;
13067
+ const SAT$1 = 6;
13068
+ const { NISAN: NISAN$1, IYYAR, TAMUZ, AV, TISHREI: TISHREI$1, CHESHVAN, KISLEV, TEVET, ADAR_I, ADAR_II } = months;
12888
13069
  const yearCache = new QuickLRU({ maxSize: 120 });
13070
+ /** Most recently used year, so day-by-day callers skip the LRU lookup */
13071
+ let lastEntry;
13072
+ const stringMapCache = new WeakMap();
12889
13073
  function addToMap(map, ...events) {
12890
13074
  for (const ev of events) {
12891
- const key = ev.date.toString();
13075
+ const key = ev.date.abs();
12892
13076
  const arr = map.get(key);
12893
13077
  if (arr !== undefined) {
12894
13078
  arr.push(ev);
@@ -12984,7 +13168,7 @@ function addTishreiHolidays(map, year, RH) {
12984
13168
  const tzomGedaliahDay = RH.getDay() === THU ? 4 : 3;
12985
13169
  addToMap(map, new HolidayEvent(new HDate(tzomGedaliahDay, TISHREI$1, year), holidayDesc.TZOM_GEDALIAH, MINOR_FAST$1),
12986
13170
  // first SAT after RH
12987
- new HolidayEvent(new HDate(HDate.dayOnOrBefore(SAT$2, 7 + RH.abs())), holidayDesc.SHABBAT_SHUVA, SPECIAL_SHABBAT$1));
13171
+ new HolidayEvent(new HDate(HDate.dayOnOrBefore(SAT$1, 7 + RH.abs())), holidayDesc.SHABBAT_SHUVA, SPECIAL_SHABBAT$1));
12988
13172
  }
12989
13173
  function addChanukahAndTevet(map, year) {
12990
13174
  const rchTevet = HDate.shortKislev(year)
@@ -13001,15 +13185,15 @@ function addChanukahAndTevet(map, year) {
13001
13185
  }
13002
13186
  function addPesachSeasonHolidays(map, year, pesach) {
13003
13187
  const pesachAbs = pesach.abs();
13004
- const haChodeshAbs = HDate.dayOnOrBefore(SAT$2, pesachAbs - 14);
13005
- addToMap(map, new HolidayEvent(new HDate(HDate.dayOnOrBefore(SAT$2, pesachAbs - 43)), holidayDesc.SHABBAT_SHEKALIM, SPECIAL_SHABBAT$1), new HolidayEvent(new HDate(HDate.dayOnOrBefore(SAT$2, pesachAbs - 30)), holidayDesc.SHABBAT_ZACHOR, SPECIAL_SHABBAT$1), new HolidayEvent(new HDate(pesachAbs - (pesach.getDay() === TUE ? 33 : 31)), holidayDesc.TAANIT_ESTHER, MINOR_FAST$1), new HolidayEvent(new HDate(haChodeshAbs - 7), holidayDesc.SHABBAT_PARAH, SPECIAL_SHABBAT$1), new HolidayEvent(new HDate(haChodeshAbs), holidayDesc.SHABBAT_HACHODESH, SPECIAL_SHABBAT$1), new HolidayEvent(new HDate(HDate.dayOnOrBefore(SAT$2, pesachAbs - 1)), holidayDesc.SHABBAT_HAGADOL, SPECIAL_SHABBAT$1), new HolidayEvent(
13188
+ const haChodeshAbs = HDate.dayOnOrBefore(SAT$1, pesachAbs - 14);
13189
+ addToMap(map, new HolidayEvent(new HDate(HDate.dayOnOrBefore(SAT$1, pesachAbs - 43)), holidayDesc.SHABBAT_SHEKALIM, SPECIAL_SHABBAT$1), new HolidayEvent(new HDate(HDate.dayOnOrBefore(SAT$1, pesachAbs - 30)), holidayDesc.SHABBAT_ZACHOR, SPECIAL_SHABBAT$1), new HolidayEvent(new HDate(pesachAbs - (pesach.getDay() === TUE ? 33 : 31)), holidayDesc.TAANIT_ESTHER, MINOR_FAST$1), new HolidayEvent(new HDate(haChodeshAbs - 7), holidayDesc.SHABBAT_PARAH, SPECIAL_SHABBAT$1), new HolidayEvent(new HDate(haChodeshAbs), holidayDesc.SHABBAT_HACHODESH, SPECIAL_SHABBAT$1), new HolidayEvent(new HDate(HDate.dayOnOrBefore(SAT$1, pesachAbs - 1)), holidayDesc.SHABBAT_HAGADOL, SPECIAL_SHABBAT$1), new HolidayEvent(
13006
13190
  // if the fast falls on Shabbat, move to Thursday
13007
- pesach.prev().getDay() === SAT$2
13191
+ pesach.prev().getDay() === SAT$1
13008
13192
  ? pesach.onOrBefore(THU)
13009
- : new HDate(14, NISAN$2, year), holidayDesc.TAANIT_BECHOROT, MINOR_FAST$1));
13193
+ : new HDate(14, NISAN$1, year), holidayDesc.TAANIT_BECHOROT, MINOR_FAST$1));
13010
13194
  }
13011
13195
  function addLeilSelichot(map, year) {
13012
- addToMap(map, new HolidayEvent(new HDate(HDate.dayOnOrBefore(SAT$2, new HDate(1, TISHREI$1, year + 1).abs() - 4)), holidayDesc.LEIL_SELICHOT, MINOR_HOLIDAY$1, { emoji: '🕍' }));
13196
+ addToMap(map, new HolidayEvent(new HDate(HDate.dayOnOrBefore(SAT$1, new HDate(1, TISHREI$1, year + 1).abs() - 4)), holidayDesc.LEIL_SELICHOT, MINOR_HOLIDAY$1, { emoji: '🕍' }));
13013
13197
  }
13014
13198
  function addPurimVariants(map, year, pesach) {
13015
13199
  if (pesach.getDay() === SUN) {
@@ -13020,26 +13204,26 @@ function addPurimVariants(map, year, pesach) {
13020
13204
  }
13021
13205
  }
13022
13206
  function addSummerFasts(map, year) {
13023
- let tamuz17 = new HDate(17, TAMUZ$1, year);
13207
+ let tamuz17 = new HDate(17, TAMUZ, year);
13024
13208
  let tamuz17attrs;
13025
- if (tamuz17.getDay() === SAT$2) {
13026
- tamuz17 = new HDate(18, TAMUZ$1, year);
13209
+ if (tamuz17.getDay() === SAT$1) {
13210
+ tamuz17 = new HDate(18, TAMUZ, year);
13027
13211
  tamuz17attrs = { observed: true };
13028
13212
  }
13029
13213
  addToMap(map, new HolidayEvent(tamuz17, holidayDesc.TZOM_TAMMUZ, MINOR_FAST$1, tamuz17attrs));
13030
- let av9dt = new HDate(9, AV$1, year);
13214
+ let av9dt = new HDate(9, AV, year);
13031
13215
  let av9title = holidayDesc.TISHA_BAV;
13032
13216
  let av9attrs;
13033
- if (av9dt.getDay() === SAT$2) {
13217
+ if (av9dt.getDay() === SAT$1) {
13034
13218
  av9dt = av9dt.next();
13035
13219
  av9attrs = { observed: true };
13036
13220
  av9title += ' (observed)';
13037
13221
  }
13038
13222
  const av9abs = av9dt.abs();
13039
- addToMap(map, new HolidayEvent(new HDate(HDate.dayOnOrBefore(SAT$2, av9abs)), holidayDesc.SHABBAT_CHAZON, SPECIAL_SHABBAT$1), new HolidayEvent(av9dt.prev(), holidayDesc.EREV_TISHA_BAV, EREV$1 | MAJOR_FAST$1, av9attrs), new HolidayEvent(av9dt, av9title, MAJOR_FAST$1, av9attrs), new HolidayEvent(new HDate(HDate.dayOnOrBefore(SAT$2, av9abs + 7)), holidayDesc.SHABBAT_NACHAMU, SPECIAL_SHABBAT$1));
13223
+ addToMap(map, new HolidayEvent(new HDate(HDate.dayOnOrBefore(SAT$1, av9abs)), holidayDesc.SHABBAT_CHAZON, SPECIAL_SHABBAT$1), new HolidayEvent(av9dt.prev(), holidayDesc.EREV_TISHA_BAV, EREV$1 | MAJOR_FAST$1, av9attrs), new HolidayEvent(av9dt, av9title, MAJOR_FAST$1, av9attrs), new HolidayEvent(new HDate(HDate.dayOnOrBefore(SAT$1, av9abs + 7)), holidayDesc.SHABBAT_NACHAMU, SPECIAL_SHABBAT$1));
13040
13224
  }
13041
13225
  function daysInPreviousMonth(month, year) {
13042
- return month === NISAN$2
13226
+ return month === NISAN$1
13043
13227
  ? HDate.daysInMonth(HDate.monthsInYear(year - 1), year - 1)
13044
13228
  : HDate.daysInMonth(month - 1, year);
13045
13229
  }
@@ -13069,7 +13253,7 @@ function addYomKippurKatan(map, year) {
13069
13253
  }
13070
13254
  let ykk = new HDate(29, month, year);
13071
13255
  const dow = ykk.getDay();
13072
- if (dow === FRI$1 || dow === SAT$2) {
13256
+ if (dow === FRI$1 || dow === SAT$1) {
13073
13257
  ykk = ykk.onOrBefore(THU);
13074
13258
  }
13075
13259
  const nextMonthName = HDate.getMonthName(nextMonth, year);
@@ -13079,7 +13263,7 @@ function addYomKippurKatan(map, year) {
13079
13263
  function addBehab(map, year) {
13080
13264
  for (const month of [CHESHVAN, IYYAR]) {
13081
13265
  const roshChodesh = new HDate(1, month, year);
13082
- let shabbos = new HDate(HDate.dayOnOrBefore(SAT$2, roshChodesh.abs() + 6));
13266
+ let shabbos = new HDate(HDate.dayOnOrBefore(SAT$1, roshChodesh.abs() + 6));
13083
13267
  if (shabbos.abs() === roshChodesh.abs()) {
13084
13268
  shabbos = new HDate(shabbos.abs() + 7);
13085
13269
  }
@@ -13092,25 +13276,54 @@ function addBehab(map, year) {
13092
13276
  }
13093
13277
  }
13094
13278
  }
13279
+ /**
13280
+ * Holidays for an entire Hebrew year, indexed by R.D. day number
13281
+ * (`HDate.abs()`), so that per-day lookups don't have to build a date string.
13282
+ * The result is cached in an internal LRU and shared between callers.
13283
+ * @internal
13284
+ */
13285
+ function getHolidaysForYearByRd(year) {
13286
+ return getYearEntry(year).map;
13287
+ }
13095
13288
  /**
13096
13289
  * Lower-level holidays interface, which returns a `Map` of `Event`s indexed by
13097
13290
  * `HDate.toString()`. These events must filtered especially for `flags.IL_ONLY`
13098
13291
  * or `flags.CHUL_ONLY` depending on Israel vs. Diaspora holiday scheme.
13292
+ *
13293
+ * A string-keyed copy of {@link getHolidaysForYearByRd}, built once per
13294
+ * cached year; the event arrays are shared with it.
13099
13295
  * @internal
13100
13296
  */
13101
13297
  function getHolidaysForYear_(year) {
13298
+ const entry = getYearEntry(year);
13299
+ let strMap = stringMapCache.get(entry);
13300
+ if (strMap === undefined) {
13301
+ strMap = new Map();
13302
+ for (const [abs, events] of entry.map) {
13303
+ strMap.set(new HDate(abs).toString(), events);
13304
+ }
13305
+ stringMapCache.set(entry, strMap);
13306
+ }
13307
+ return strMap;
13308
+ }
13309
+ function getYearEntry(year) {
13310
+ const last = lastEntry;
13311
+ if (last?.year === year) {
13312
+ return last;
13313
+ }
13314
+ const entry = yearCache.get(year) ?? makeYearEntry(year);
13315
+ lastEntry = entry;
13316
+ return entry;
13317
+ }
13318
+ function makeYearEntry(year) {
13102
13319
  if (typeof year !== 'number') {
13103
13320
  throw new TypeError(`bad Hebrew year: ${year}`);
13104
13321
  }
13105
13322
  if (year < 1 || year > 32658) {
13106
13323
  throw new RangeError(`Hebrew year ${year} out of range 1-32658`);
13107
13324
  }
13108
- const cached = yearCache.get(year);
13109
- if (cached) {
13110
- return cached;
13111
- }
13112
13325
  const RH = new HDate(1, TISHREI$1, year);
13113
- const pesach = new HDate(15, NISAN$2, year);
13326
+ const pesach = new HDate(15, NISAN$1, year);
13114
13327
  const map = new Map();
13115
13328
  addStaticHolidays(map, year);
13116
13329
  addTishreiHolidays(map, year, RH);
@@ -13138,8 +13351,14 @@ function getHolidaysForYear_(year) {
13138
13351
  for (const arr of map.values()) {
13139
13352
  arr.sort((a, b) => timeOfDay(a) - timeOfDay(b));
13140
13353
  }
13141
- yearCache.set(year, map);
13142
- return map;
13354
+ const entry = {
13355
+ year,
13356
+ map,
13357
+ startAbs: RH.abs(),
13358
+ endAbs: HDate.hebrew2abs(year + 1, TISHREI$1, 1) - 1,
13359
+ };
13360
+ yearCache.set(year, entry);
13361
+ return entry;
13143
13362
  }
13144
13363
  /** 28 years of 365.25 days */
13145
13364
  const BIRKAT_HACHAMAH_CYCLE_DAYS = 10227;
@@ -13156,7 +13375,7 @@ const BIRKAT_HACHAMAH_REMAINDER = 172;
13156
13375
  */
13157
13376
  function getBirkatHaChama(year) {
13158
13377
  const leap = HDate.isLeapYear(year);
13159
- const startMonth = leap ? ADAR_II : NISAN$2;
13378
+ const startMonth = leap ? ADAR_II : NISAN$1;
13160
13379
  const startDay = leap ? 20 : 1;
13161
13380
  const baseRd = HDate.hebrew2abs(year, startMonth, startDay);
13162
13381
  for (let day = 0; day <= 40; day++) {
@@ -13183,141 +13402,25 @@ function getBirkatHaChama(year) {
13183
13402
  * @param il use the Israeli schedule for holidays
13184
13403
  */
13185
13404
  function getHolidaysForYearArray(year, il) {
13186
- const yearMap = getHolidaysForYear_(year);
13187
- const startAbs = HDate.hebrew2abs(year, TISHREI$1, 1);
13188
- const endAbs = HDate.hebrew2abs(year + 1, TISHREI$1, 1) - 1;
13405
+ const { map, startAbs, endAbs } = getYearEntry(year);
13406
+ const days = [];
13407
+ for (const abs of map.keys()) {
13408
+ if (abs >= startAbs && abs <= endAbs) {
13409
+ days.push(abs);
13410
+ }
13411
+ }
13412
+ days.sort((a, b) => a - b);
13189
13413
  const events = [];
13190
- for (let absDt = startAbs; absDt <= endAbs; absDt++) {
13191
- const hd = new HDate(absDt);
13192
- const holidays = yearMap.get(hd.toString());
13193
- if (holidays) {
13194
- events.push(...holidays.filter(ev => ev.observedIn(il)));
13414
+ for (const abs of days) {
13415
+ for (const ev of map.get(abs)) {
13416
+ if (ev.observedIn(il)) {
13417
+ events.push(ev);
13418
+ }
13195
13419
  }
13196
13420
  }
13197
13421
  return events;
13198
13422
  }
13199
13423
 
13200
- function isTomorrowShabbosOrYomTov(dow, events) {
13201
- return (dow === 5 ||
13202
- events.some(ev => ev.hasAnyFlag('LIGHT_CANDLES', 'LIGHT_CANDLES_TZEIS')));
13203
- }
13204
- /**
13205
- * Returns true if it is _Shabbos_ or if it is a _Yom Tov_ day that has a
13206
- * _melacha_ (work) prohibition.
13207
- *
13208
- * @param dow day of week, where `6` is Shabbos
13209
- * @param events events occurring on the day
13210
- * @return `true` if the day is a _Yom Tov_ that is _assur bemlacha_, or _Shabbos_
13211
- */
13212
- function isTodayAssurBemelacha(dow, events) {
13213
- return dow === 6 || events.some(ev => ev.hasFlag('CHAG'));
13214
- }
13215
- /**
13216
- * Returns `true` if the given moment (date + time) falls within a period
13217
- * when *melacha* (work) is prohibited — i.e. Shabbat or a Yom Tov.
13218
- *
13219
- * The Shabbat/Yom Tov window is taken to begin at sunset (shkiah) on the
13220
- * preceding day (Erev Shabbat / Erev Yom Tov / Yom Tov sheni) and to end
13221
- * at *tzais* (nightfall) on the day itself. *Tzais* is calculated using a
13222
- * solar depression of 8.5° for simplicity; consult a halachic authority
13223
- * for more stringent opinions.
13224
- *
13225
- * `useElevation` controls whether the location's elevation is taken into
13226
- * account when computing sunset (it has no effect on the degree-based
13227
- * tzais calculation). The Israel/Diaspora schedule comes from
13228
- * `location.getIsrael()`.
13229
- *
13230
- * Throws if sunset cannot be calculated for the given location
13231
- * (e.g. polar regions).
13232
- * @example
13233
- * import {isAssurBemlacha, Location} from '@hebcal/core';
13234
- * const loc = Location.lookup('Jerusalem')!;
13235
- * // Friday after sunset:
13236
- * isAssurBemlacha(new Date('2024-04-26T18:00:00Z'), loc, false); // true
13237
- * @param currentTime the moment to test (with hour/minute)
13238
- * @param location geographic location (also supplies Israel/Diaspora flag and tzid)
13239
- * @param useElevation include elevation when computing sunset
13240
- * @return `true` if *melacha* is prohibited, `false` if it is not
13241
- */
13242
- function isAssurBemlacha(currentTime, location, useElevation) {
13243
- // Determine the calendar date in the location's timezone, not the
13244
- // timezone of the computer running this code. Otherwise the day-of-week,
13245
- // Hebrew date and sunset/tzais times would depend on the machine's
13246
- // local timezone, giving different (incorrect) results near midnight.
13247
- const isoDate = getPseudoISO(location.getTzid(), currentTime);
13248
- const year = parseInt(isoDate.substring(0, 4), 10);
13249
- const month = parseInt(isoDate.substring(5, 7), 10);
13250
- const day = parseInt(isoDate.substring(8, 10), 10);
13251
- const hd = new HDate(new Date(year, month - 1, day));
13252
- const zmanim = new Zmanim(location, hd, useElevation);
13253
- // erev shabbos, YT or YT sheni and after shkiah
13254
- const sunset = zmanim.sunset();
13255
- const sunsetMillis = sunset.getTime();
13256
- if (Number.isNaN(sunsetMillis)) {
13257
- throw new Error('Could not determine sunset');
13258
- }
13259
- // erev shabbos, YT or YT sheni and after shkiah
13260
- const il = location.getIsrael();
13261
- const currentMillis = currentTime.getTime();
13262
- const dow = hd.getDay();
13263
- const events = getHolidaysOnDate(hd, il) ?? [];
13264
- if (isTomorrowShabbosOrYomTov(dow, events) && currentMillis >= sunsetMillis) {
13265
- return true;
13266
- }
13267
- // is shabbos or YT and it is before tzais
13268
- if (isTodayAssurBemelacha(dow, events)) {
13269
- const tzais = zmanim.tzeit();
13270
- const tzaisMillis = tzais.getTime();
13271
- return currentMillis <= tzaisMillis;
13272
- }
13273
- return false;
13274
- }
13275
-
13276
- const { NISAN: NISAN$1, SIVAN: SIVAN$1, TAMUZ, AV } = months;
13277
- const SAT$1 = 6;
13278
- function getHDate(date) {
13279
- return HDate.isHDate(date) ? date : new HDate(date);
13280
- }
13281
- function isSefiratHaOmer(hd) {
13282
- const hyear = hd.getFullYear();
13283
- const beginOmer = new HDate(16, NISAN$1, hyear).abs();
13284
- const endOmer = new HDate(5, SIVAN$1, hyear).abs();
13285
- const abs = hd.abs();
13286
- return abs >= beginOmer && abs <= endOmer;
13287
- }
13288
- function isBeinHaMetzarim(hd) {
13289
- const hyear = hd.getFullYear();
13290
- const begin = new HDate(17, TAMUZ, hyear).abs();
13291
- const tishaBav = new HDate(9, AV, hyear);
13292
- const end = tishaBav.getDay() === SAT$1 ? new HDate(10, AV, hyear).abs() : tishaBav.abs();
13293
- const abs = hd.abs();
13294
- return abs >= begin && abs <= end;
13295
- }
13296
- /**
13297
- * Returns `true` if the given date falls within a public period of communal
13298
- * mourning — specifically:
13299
- *
13300
- * - **Sefirat HaOmer**: 16 Nisan through 5 Sivan (the 49 days of the Omer).
13301
- * - **Bein HaMetzarim** ("between the straits"): 17 Tammuz through 9 Av
13302
- * (10 Av when 9 Av is postponed because it falls on Shabbat).
13303
- *
13304
- * This is a broad helper — it does not attempt to model minhag-specific
13305
- * exceptions within those periods (e.g. Lag BaOmer, Rosh Chodesh Iyar,
13306
- * the distinction between Sephardic and Ashkenazic customs on which
13307
- * portion of the Omer is observed as mourning, etc.).
13308
- * @example
13309
- * import {isAveilut, HDate, months} from '@hebcal/core';
13310
- * isAveilut(new HDate(20, months.NISAN, 5784)); // true (Omer)
13311
- * isAveilut(new HDate(25, months.TAMUZ, 5784)); // true (Three Weeks)
13312
- * isAveilut(new HDate(15, months.AV, 5784)); // false
13313
- * @param date Hebrew Date, Gregorian date, or absolute R.D. day number
13314
- * @return `true` if the date is during a mourning period
13315
- */
13316
- function isAveilut(date) {
13317
- const hd = getHDate(date);
13318
- return isSefiratHaOmer(hd) || isBeinHaMetzarim(hd);
13319
- }
13320
-
13321
13424
  /**
13322
13425
  * Returns `true` if the given date is observed as a major or minor fast day.
13323
13426
  *
@@ -13382,7 +13485,13 @@ function makeCandleEvent(ev, hd, options, isFriday, isSaturday) {
13382
13485
  return new HavdalahEvent(hd, mask, time, location, options.havdalahMins, ev, options);
13383
13486
  }
13384
13487
  else {
13385
- mask |= LIGHT_CANDLES$1;
13488
+ // Exactly one of the two candle-lighting flags, chosen by how the time
13489
+ // was computed: LIGHT_CANDLES for minutes before sunset (Shabbat or the
13490
+ // start of a chag), LIGHT_CANDLES_TZEIS for nightfall / Havdalah time
13491
+ // (the second night of Yom Tov, or a chag that begins Saturday night).
13492
+ mask = useHavdalahOffset
13493
+ ? (mask & ~LIGHT_CANDLES$1) | LIGHT_CANDLES_TZEIS$1
13494
+ : (mask & ~LIGHT_CANDLES_TZEIS$1) | LIGHT_CANDLES$1;
13386
13495
  return new CandleLightingEvent(hd, mask, time, location, ev, options);
13387
13496
  }
13388
13497
  }
@@ -13396,7 +13505,9 @@ const MINOR_FAST_END_MINUTES_IL = 15;
13396
13505
  * Returns `val` when it is a finite nonzero number, otherwise `undefined`
13397
13506
  */
13398
13507
  function nonzero(val) {
13399
- return typeof val === 'number' && isFinite(val) && val !== 0 ? val : undefined;
13508
+ return typeof val === 'number' && Number.isFinite(val) && val !== 0
13509
+ ? val
13510
+ : undefined;
13400
13511
  }
13401
13512
  /**
13402
13513
  * Computes the "Fast begins" time for a minor fast (one that begins at dawn).
@@ -13651,8 +13762,7 @@ function isShabbatOrChag(hd, il) {
13651
13762
  if (hd.getDay() === 6) {
13652
13763
  return true;
13653
13764
  }
13654
- const events = getHolidaysOnDate(hd, il) ?? [];
13655
- return events.some(ev => ev.hasFlag('CHAG'));
13765
+ return isYomTov(hd, il);
13656
13766
  }
13657
13767
  /**
13658
13768
  * Makes the "Latest Kiddush Levana" event for one Hebrew month, or
@@ -13790,16 +13900,7 @@ const sefirot = {
13790
13900
  he: {
13791
13901
  infix: null,
13792
13902
  infix26: null,
13793
- words: [
13794
- '',
13795
- 'חֶֽסֶד',
13796
- 'גְּבוּרָה',
13797
- 'תִּפְאֶֽרֶת',
13798
- 'נֶּֽצַח',
13799
- 'הוֹד',
13800
- 'יְּסוֹד',
13801
- 'מַלְכוּת',
13802
- ],
13903
+ words: ['', 'חֶֽסֶד', 'גְּבוּרָה', 'תִּפְאֶֽרֶת', 'נֶּֽצַח', 'הוֹד', 'יְּסוֹד', 'מַלְכוּת'],
13803
13904
  pfxWords: [
13804
13905
  '',
13805
13906
  'שֶׁבְּחֶֽסֶד',
@@ -14549,7 +14650,7 @@ function getMonth(options) {
14549
14650
  return options.month;
14550
14651
  }
14551
14652
  }
14552
- return NaN;
14653
+ return Number.NaN;
14553
14654
  }
14554
14655
  function startEndGregorian(theMonth, theYear, numYears) {
14555
14656
  const gregMonth = theMonth ? theMonth - 1 : 0;
@@ -14905,7 +15006,7 @@ function calendar(options = {}) {
14905
15006
  const hyear = hd.getFullYear();
14906
15007
  if (hyear !== currentYear) {
14907
15008
  currentYear = hyear;
14908
- holidaysYear = getHolidaysForYear_(currentYear);
15009
+ holidaysYear = getHolidaysForYearByRd(currentYear);
14909
15010
  if (options.sedrot) {
14910
15011
  sedra = getSedra(currentYear, il);
14911
15012
  }
@@ -14919,7 +15020,7 @@ function calendar(options = {}) {
14919
15020
  const isFriday = dow === FRI;
14920
15021
  const isSaturday = dow === SAT;
14921
15022
  let candlesEv;
14922
- const holidays0 = holidaysYear.get(hd.toString()) || [];
15023
+ const holidays0 = holidaysYear.get(abs) || [];
14923
15024
  const holidays = holidays0.filter(ev => ev.observedIn(il));
14924
15025
  if (options.sedrot && isSaturday) {
14925
15026
  const parsha0 = sedra.lookup(abs);
@@ -15694,7 +15795,7 @@ class HebrewCalendar {
15694
15795
  const today = new HDate(date);
15695
15796
  const friday = today.after(5);
15696
15797
  const tomorrow = today.next();
15697
- return isChag(friday, il) && !isChag(today, il) && isChag(tomorrow, il);
15798
+ return isYomTov(friday, il) && !isYomTov(today, il) && isYomTov(tomorrow, il);
15698
15799
  }
15699
15800
  /**
15700
15801
  * Helper function to format a 24-hour (00:00-23:59) time string in either
@@ -15793,10 +15894,6 @@ class HebrewCalendar {
15793
15894
  return tachanun(hdate, il);
15794
15895
  }
15795
15896
  }
15796
- function isChag(date, il) {
15797
- const events = getHolidaysOnDate(date, il) ?? [];
15798
- return events.some(ev => ev.hasFlag('CHAG'));
15799
- }
15800
15897
 
15801
15898
  exports.AsaraBTevetEvent = AsaraBTevetEvent;
15802
15899
  exports.CandleLightingEvent = CandleLightingEvent;
@@ -15840,6 +15937,7 @@ exports.holidayDesc = holidayDesc;
15840
15937
  exports.isAssurBemlacha = isAssurBemlacha;
15841
15938
  exports.isAveilut = isAveilut;
15842
15939
  exports.isFastDay = isFastDay;
15940
+ exports.isYomTov = isYomTov;
15843
15941
  exports.months = months;
15844
15942
  exports.parshaYear = parshaYear;
15845
15943
  exports.parshiot = parshiot;