@hebcal/core 6.14.6 → 6.15.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.
Files changed (65) hide show
  1. package/README.md +26 -1
  2. package/dist/bundle.js +627 -380
  3. package/dist/bundle.js.map +1 -1
  4. package/dist/bundle.min.js +7 -7
  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.d.ts +15 -1
  10. package/dist/esm/KiddushLevanaEvent.js +17 -7
  11. package/dist/esm/KiddushLevanaEvent.js.map +1 -1
  12. package/dist/esm/MevarchimChodeshEvent.js +1 -1
  13. package/dist/esm/ParshaEvent.js +1 -1
  14. package/dist/esm/TimedEvent.js +1 -1
  15. package/dist/esm/YomKippurKatanEvent.js +1 -1
  16. package/dist/esm/ashkenazi.po.js +1 -1
  17. package/dist/esm/calendar.js +5 -5
  18. package/dist/esm/calendar.js.map +1 -1
  19. package/dist/esm/candles.js +7 -7
  20. package/dist/esm/candles.js.map +1 -1
  21. package/dist/esm/cities.json.js +1 -1
  22. package/dist/esm/event.js +1 -1
  23. package/dist/esm/getStartAndEnd.js +2 -2
  24. package/dist/esm/getStartAndEnd.js.map +1 -1
  25. package/dist/esm/hallel.js +1 -1
  26. package/dist/esm/he-x-NoNikud.po.js +1 -1
  27. package/dist/esm/he.po.js +1 -1
  28. package/dist/esm/hebcal.js +1 -1
  29. package/dist/esm/holidays.js +1 -1
  30. package/dist/esm/horizon.d.ts +94 -0
  31. package/dist/esm/horizon.js +146 -0
  32. package/dist/esm/horizon.js.map +1 -0
  33. package/dist/esm/index.d.ts +2 -0
  34. package/dist/esm/index.js +1 -1
  35. package/dist/esm/isAssurBemlacha.js +2 -2
  36. package/dist/esm/isAssurBemlacha.js.map +1 -1
  37. package/dist/esm/isAveilut.js +1 -1
  38. package/dist/esm/isFastDay.js +1 -1
  39. package/dist/esm/locale.js +1 -1
  40. package/dist/esm/location.js +3 -3
  41. package/dist/esm/location.js.map +1 -1
  42. package/dist/esm/modern.js +1 -1
  43. package/dist/esm/molad.js +1 -1
  44. package/dist/esm/moladBase.js +1 -1
  45. package/dist/esm/moladDate.js +1 -1
  46. package/dist/esm/omer.js +1 -1
  47. package/dist/esm/parshaName.js +1 -1
  48. package/dist/esm/parshaYear.js +1 -1
  49. package/dist/esm/pkgVersion.d.ts +1 -1
  50. package/dist/esm/pkgVersion.js +2 -2
  51. package/dist/esm/pkgVersion.js.map +1 -1
  52. package/dist/esm/reformatTimeStr.js +1 -1
  53. package/dist/esm/sedra.js +2 -2
  54. package/dist/esm/sedra.js.map +1 -1
  55. package/dist/esm/sefira.json.js +1 -1
  56. package/dist/esm/staticHolidays.js +1 -1
  57. package/dist/esm/string.js +1 -1
  58. package/dist/esm/tachanun.js +1 -1
  59. package/dist/esm/zenith.d.ts +2 -1
  60. package/dist/esm/zenith.js +4 -3
  61. package/dist/esm/zenith.js.map +1 -1
  62. package/dist/esm/zmanim.d.ts +117 -5
  63. package/dist/esm/zmanim.js +209 -15
  64. package/dist/esm/zmanim.js.map +1 -1
  65. package/package.json +12 -12
@@ -1,6 +1,7 @@
1
1
  import 'temporal-polyfill/global';
2
2
  import { GeoLocation } from '@hebcal/noaa';
3
3
  import { HDate } from '@hebcal/hdate';
4
+ import { HorizonProfile } from './horizon.js';
4
5
  /**
5
6
  * Calculate halachic times (zmanim / זְמַנִּים) for a given day and location.
6
7
  * Calculations are available for tzeit / tzais (nightfall),
@@ -136,6 +137,10 @@ export declare class Zmanim {
136
137
  * `useElevation` setting.
137
138
  */
138
139
  chatzot(): Date;
140
+ /**
141
+ * {@link chatzot} as epoch milliseconds, before the seconds are cut.
142
+ */
143
+ private chatzotMillis;
139
144
  /**
140
145
  * Midnight – Chatzot; Sunset plus 6 halachic hours.
141
146
  * If elevation is enabled, this function will include elevation in the calculation.
@@ -336,6 +341,111 @@ export declare class Zmanim {
336
341
  * Alias for sunset
337
342
  */
338
343
  shkiah(): Date;
344
+ /**
345
+ * Visible sunrise — _netz ha-nireh_ (הנץ הנראה): the moment the sun's upper
346
+ * limb, bent up by atmospheric refraction, first clears the real terrain
347
+ * skyline to the east, rather than the flat sea-level horizon {@link sunrise}
348
+ * uses. In mountainous locations (most of Israel) this is noticeably later
349
+ * than {@link sunrise}; many printed Israeli calendars list it alongside the
350
+ * standard time.
351
+ *
352
+ * The caller supplies a {@link HorizonProfile} — the apparent altitude of the
353
+ * skyline as a function of azimuth (a constant, a list of
354
+ * azimuth/elevation samples, or a function). Building such a profile from
355
+ * terrain / digital-elevation-model data is outside this library.
356
+ *
357
+ * The method follows Keller & Hall, _Computers & Geosciences_ 26 (2000), and
358
+ * the Chai Tables (chaitables.com): refraction is Sinclair below 15° and
359
+ * Bennett at or above 15° at standard atmosphere (1010 hPa, 10 °C), applied
360
+ * to the sun's upper limb. No cushion or safety margin is added.
361
+ *
362
+ * The `useElevation` setting is intentionally ignored: the profile is
363
+ * measured from the observer's own eye position (already accounting for the
364
+ * observer's height, terrestrial refraction and Earth's curvature — a sea
365
+ * horizon seen from a height is a negative angle), so applying the library's
366
+ * sea-level-vs-elevation adjustment on top would double-count.
367
+ * @example
368
+ * import {GeoLocation, Zmanim} from '@hebcal/core';
369
+ * const gloc = new GeoLocation('Jerusalem', 31.78, 35.22, 0, 'Asia/Jerusalem');
370
+ * const zmanim = new Zmanim(gloc, new Date(2026, 9, 29), false);
371
+ * const tzid = 'Asia/Jerusalem';
372
+ * // A constant: the skyline is 3° above level in every direction
373
+ * Zmanim.formatISOWithTimeZone(tzid, zmanim.visibleSunrise(3));
374
+ * // '2026-10-29T06:09:07+02:00'
375
+ * // Samples: a 5° ridge to the east (azimuth 90), flat elsewhere; values
376
+ * // between samples are interpolated, and the list wraps around at 360°
377
+ * const ridge = [
378
+ * {azimuth: 60, elevation: 0},
379
+ * {azimuth: 80, elevation: 5},
380
+ * {azimuth: 100, elevation: 5},
381
+ * {azimuth: 120, elevation: 0},
382
+ * ];
383
+ * Zmanim.formatISOWithTimeZone(tzid, zmanim.visibleSunrise(ridge));
384
+ * // '2026-10-29T06:09:43+02:00'
385
+ * // A function of azimuth (degrees clockwise from true north)
386
+ * Zmanim.formatISOWithTimeZone(tzid, zmanim.visibleSunrise((az) => (az > 70 && az < 110 ? 5 : 0)));
387
+ * // '2026-10-29T06:19:24+02:00'
388
+ * // A flat profile of 0 reproduces sunrise() to within a second
389
+ * Zmanim.formatISOWithTimeZone(tzid, zmanim.visibleSunrise(0));
390
+ * // '2026-10-29T05:52:46+02:00'
391
+ * Zmanim.formatISOWithTimeZone(tzid, zmanim.sunrise());
392
+ * // '2026-10-29T05:52:46+02:00'
393
+ * @param horizon the terrain horizon profile
394
+ * @return the `Date` (to the second) when the sun first becomes visible, or
395
+ * an `Invalid Date` when there is no such crossing that day (polar
396
+ * night/day, or the sun never clears the profile).
397
+ */
398
+ visibleSunrise(horizon: HorizonProfile): Date;
399
+ /**
400
+ * Visible sunset — _shkiah nireit_ (שקיעה נראית): the symmetric evening
401
+ * counterpart of {@link visibleSunrise}, the last moment the sun's upper
402
+ * limb is visible above the real terrain skyline to the west before it
403
+ * disappears behind the ridge line.
404
+ *
405
+ * See {@link visibleSunrise} for the horizon-profile argument, the
406
+ * refraction model, the upper-limb convention, that no cushion is added, and
407
+ * why `useElevation` is ignored.
408
+ * @example
409
+ * import {GeoLocation, Zmanim} from '@hebcal/core';
410
+ * // 300 m up on the Carmel: the sea horizon to the west sits about half a
411
+ * // degree *below* level, so the visible sunset is later than sunset()
412
+ * const tzid = 'Asia/Jerusalem';
413
+ * const gloc = new GeoLocation('Haifa', 32.8, 34.98, 300, tzid);
414
+ * const zmanim = new Zmanim(gloc, new Date(2026, 9, 29), false);
415
+ * Zmanim.formatISOWithTimeZone(tzid, zmanim.sunset());
416
+ * // '2026-10-29T16:52:01+02:00'
417
+ * Zmanim.formatISOWithTimeZone(tzid, zmanim.visibleSunset((az) => (az > 240 && az < 300 ? -0.5 : 0)));
418
+ * // '2026-10-29T16:55:07+02:00'
419
+ * @param horizon the terrain horizon profile
420
+ * @return the `Date` (to the second) when the sun was last visible, or an
421
+ * `Invalid Date` when there is no such crossing that day.
422
+ */
423
+ visibleSunset(horizon: HorizonProfile): Date;
424
+ /**
425
+ * Alias for {@link visibleSunrise}
426
+ * @param horizon the terrain horizon profile
427
+ */
428
+ neitzHaNireh(horizon: HorizonProfile): Date;
429
+ /**
430
+ * Alias for {@link visibleSunset}
431
+ * @param horizon the terrain horizon profile
432
+ */
433
+ shkiahNireit(horizon: HorizonProfile): Date;
434
+ /**
435
+ * Shared search driving {@link visibleSunrise} / {@link visibleSunset}.
436
+ *
437
+ * Scans the sun's geometric centre altitude `a` upward from −2.5° to +10° in
438
+ * 0.05° steps. At each step it maps `a` to a time (via the sea-level
439
+ * sunrise/sunset for the zenith `90 − a`) and that time to the sun's azimuth,
440
+ * then compares the upper limb's apparent altitude against the horizon
441
+ * profile at that azimuth. The sun is visible once that difference `g` is
442
+ * `≥ 0`; the first upward crossing is bisected to 0.0005° and its time
443
+ * returned. For sunrise this is the first moment seen; for sunset (same
444
+ * upward scan, afternoon times) it is the last moment seen.
445
+ * @param horizon the terrain horizon profile
446
+ * @param rising `true` for the morning, `false` for the evening
447
+ */
448
+ private visibleSunMillis;
339
449
  /**
340
450
  * Rabbeinu Tam holds that bein hashmashos is a specific time
341
451
  * between sunset and tzeis hakochavim.
@@ -475,7 +585,7 @@ export declare class Zmanim {
475
585
  *
476
586
  * According to the Baal Hatanya, _netz amiti_, or true (halachic) sunrise, is when the top of the sun's
477
587
  * disk is visible at an elevation similar to the mountains of Eretz Yisrael. The time is calculated as the point at which
478
- * the center of the sun's disk is 1.583° below the horizon. This degree-based calculation can be found in Rabbi Shalom
588
+ * the center of the sun's disk is 1° 35' (1.58333°) below the horizon. This degree-based calculation can be found in Rabbi Shalom
479
589
  * DovBer Levine's commentary on
480
590
  * [The Baal Hatanya's Seder Hachnasas Shabbos](https://www.chabadlibrary.org/books/pdf/Seder-Hachnosas-Shabbos.pdf).
481
591
  * From an elevation of 546 meters, the top of [Har Hacarmel](https://en.wikipedia.org/wiki/Mount_Carmel),
@@ -504,7 +614,7 @@ export declare class Zmanim {
504
614
  *
505
615
  * According to the Baal Hatanya, _shkiah amiti_, true (_halachic_) sunset, is when the top of the
506
616
  * sun's disk disappears from view at an elevation similar to the mountains of _Eretz Yisrael_.
507
- * This time is calculated as the point at which the center of the sun's disk is 1.583 degrees below the horizon.
617
+ * This time is calculated as the point at which the center of the sun's disk is 1° 35' below the horizon.
508
618
  *
509
619
  * Note: _shkiah amiti_ is used only for calculating certain _zmanim_, and is intentionally unpublished. For
510
620
  * practical purposes, all daytime mitzvos should be completed before the published time for _shkiah_ / sunset.
@@ -562,9 +672,11 @@ export declare class Zmanim {
562
672
  * [Ra"sh](https://en.wikipedia.org/wiki/Asher_ben_Jehiel),
563
673
  * [Tur](https://en.wikipedia.org/wiki/Jacob_ben_Asher),
564
674
  * [GRA](https://en.wikipedia.org/wiki/Vilna_Gaon) and others are of the opinion that _mincha_ can be prayed
565
- * _lechatchila_ starting at _mincha gedola_. This is calculated as 6.5 sea level solar hours after
566
- * _netz amiti_ (sunrise), based on the opinion of the Baal Hatanya that the day is calculated from
567
- * _netz amiti_ (sunrise) to _shkiah amiti_ (sunset).
675
+ * _lechatchila_ starting at _mincha gedola_. This is calculated as {@link chatzot} (the midpoint of
676
+ * sea level sunrise and sunset) plus half a solar hour, based on the opinion of the Baal Hatanya that
677
+ * the day is calculated from _netz amiti_ (sunrise) to _shkiah amiti_ (sunset). This is how Chabad.org
678
+ * calculates it; 6.5 solar hours after _netz amiti_ differs by under a second, but that is enough to
679
+ * change the printed minute on a few days a year.
568
680
  * @return the `Date` of the time of _mincha gedola_ according to the Baal Hatanya. If the calculation
569
681
  * can't be computed, such as in the Arctic Circle where there is at least one day a year where the sun does not rise
570
682
  * and one where it does not set, an `Invalid Date` will be returned.
@@ -1,9 +1,10 @@
1
- /*! @hebcal/core v6.14.6, distributed under GPLv2 or later https://www.gnu.org/licenses/gpl-2.0.txt */
1
+ /*! @hebcal/core v6.15.0, distributed under GPLv2 or later https://www.gnu.org/licenses/gpl-2.0.txt */
2
2
  import 'temporal-polyfill/global';
3
3
  import { NOAACalculator } from '@hebcal/noaa';
4
4
  import { HDate, isDate, getTimezoneOffset, pad2, getPseudoISO } from '@hebcal/hdate';
5
5
  import { Molad } from './molad.js';
6
6
  import { GEOMETRIC_ZENITH, CIVIL_ZENITH, DEG_16_POINT_1, DEG_8_POINT_5, DEG_7_POINT_083, ZENITH_1_POINT_583 } from './zenith.js';
7
+ import { upperLimbApparentAltitude, horizonElevation } from './horizon.js';
7
8
 
8
9
  /**
9
10
  * Converts an instant to a `Date`, discarding milliseconds.
@@ -220,10 +221,16 @@ class Zmanim {
220
221
  * `useElevation` setting.
221
222
  */
222
223
  chatzot() {
224
+ return millisToDate(this.chatzotMillis());
225
+ }
226
+ /**
227
+ * {@link chatzot} as epoch milliseconds, before the seconds are cut.
228
+ */
229
+ chatzotMillis() {
223
230
  const startOfDay = this.sunriseMillis(GEOMETRIC_ZENITH, false);
224
231
  const endOfDay = this.sunsetMillis(GEOMETRIC_ZENITH, false);
225
232
  // NOAACalculator.getSunTransit(): sunrise plus 6 temporal hours
226
- return millisToDate(startOfDay + temporalHourMillis(startOfDay, endOfDay) * 6);
233
+ return startOfDay + temporalHourMillis(startOfDay, endOfDay) * 6;
227
234
  }
228
235
  /**
229
236
  * Midnight – Chatzot; Sunset plus 6 halachic hours.
@@ -514,6 +521,190 @@ class Zmanim {
514
521
  shkiah() {
515
522
  return this.sunset();
516
523
  }
524
+ /**
525
+ * Visible sunrise — _netz ha-nireh_ (הנץ הנראה): the moment the sun's upper
526
+ * limb, bent up by atmospheric refraction, first clears the real terrain
527
+ * skyline to the east, rather than the flat sea-level horizon {@link sunrise}
528
+ * uses. In mountainous locations (most of Israel) this is noticeably later
529
+ * than {@link sunrise}; many printed Israeli calendars list it alongside the
530
+ * standard time.
531
+ *
532
+ * The caller supplies a {@link HorizonProfile} — the apparent altitude of the
533
+ * skyline as a function of azimuth (a constant, a list of
534
+ * azimuth/elevation samples, or a function). Building such a profile from
535
+ * terrain / digital-elevation-model data is outside this library.
536
+ *
537
+ * The method follows Keller & Hall, _Computers & Geosciences_ 26 (2000), and
538
+ * the Chai Tables (chaitables.com): refraction is Sinclair below 15° and
539
+ * Bennett at or above 15° at standard atmosphere (1010 hPa, 10 °C), applied
540
+ * to the sun's upper limb. No cushion or safety margin is added.
541
+ *
542
+ * The `useElevation` setting is intentionally ignored: the profile is
543
+ * measured from the observer's own eye position (already accounting for the
544
+ * observer's height, terrestrial refraction and Earth's curvature — a sea
545
+ * horizon seen from a height is a negative angle), so applying the library's
546
+ * sea-level-vs-elevation adjustment on top would double-count.
547
+ * @example
548
+ * import {GeoLocation, Zmanim} from '@hebcal/core';
549
+ * const gloc = new GeoLocation('Jerusalem', 31.78, 35.22, 0, 'Asia/Jerusalem');
550
+ * const zmanim = new Zmanim(gloc, new Date(2026, 9, 29), false);
551
+ * const tzid = 'Asia/Jerusalem';
552
+ * // A constant: the skyline is 3° above level in every direction
553
+ * Zmanim.formatISOWithTimeZone(tzid, zmanim.visibleSunrise(3));
554
+ * // '2026-10-29T06:09:07+02:00'
555
+ * // Samples: a 5° ridge to the east (azimuth 90), flat elsewhere; values
556
+ * // between samples are interpolated, and the list wraps around at 360°
557
+ * const ridge = [
558
+ * {azimuth: 60, elevation: 0},
559
+ * {azimuth: 80, elevation: 5},
560
+ * {azimuth: 100, elevation: 5},
561
+ * {azimuth: 120, elevation: 0},
562
+ * ];
563
+ * Zmanim.formatISOWithTimeZone(tzid, zmanim.visibleSunrise(ridge));
564
+ * // '2026-10-29T06:09:43+02:00'
565
+ * // A function of azimuth (degrees clockwise from true north)
566
+ * Zmanim.formatISOWithTimeZone(tzid, zmanim.visibleSunrise((az) => (az > 70 && az < 110 ? 5 : 0)));
567
+ * // '2026-10-29T06:19:24+02:00'
568
+ * // A flat profile of 0 reproduces sunrise() to within a second
569
+ * Zmanim.formatISOWithTimeZone(tzid, zmanim.visibleSunrise(0));
570
+ * // '2026-10-29T05:52:46+02:00'
571
+ * Zmanim.formatISOWithTimeZone(tzid, zmanim.sunrise());
572
+ * // '2026-10-29T05:52:46+02:00'
573
+ * @param horizon the terrain horizon profile
574
+ * @return the `Date` (to the second) when the sun first becomes visible, or
575
+ * an `Invalid Date` when there is no such crossing that day (polar
576
+ * night/day, or the sun never clears the profile).
577
+ */
578
+ visibleSunrise(horizon) {
579
+ return this.visibleSunMillis(horizon, true);
580
+ }
581
+ /**
582
+ * Visible sunset — _shkiah nireit_ (שקיעה נראית): the symmetric evening
583
+ * counterpart of {@link visibleSunrise}, the last moment the sun's upper
584
+ * limb is visible above the real terrain skyline to the west before it
585
+ * disappears behind the ridge line.
586
+ *
587
+ * See {@link visibleSunrise} for the horizon-profile argument, the
588
+ * refraction model, the upper-limb convention, that no cushion is added, and
589
+ * why `useElevation` is ignored.
590
+ * @example
591
+ * import {GeoLocation, Zmanim} from '@hebcal/core';
592
+ * // 300 m up on the Carmel: the sea horizon to the west sits about half a
593
+ * // degree *below* level, so the visible sunset is later than sunset()
594
+ * const tzid = 'Asia/Jerusalem';
595
+ * const gloc = new GeoLocation('Haifa', 32.8, 34.98, 300, tzid);
596
+ * const zmanim = new Zmanim(gloc, new Date(2026, 9, 29), false);
597
+ * Zmanim.formatISOWithTimeZone(tzid, zmanim.sunset());
598
+ * // '2026-10-29T16:52:01+02:00'
599
+ * Zmanim.formatISOWithTimeZone(tzid, zmanim.visibleSunset((az) => (az > 240 && az < 300 ? -0.5 : 0)));
600
+ * // '2026-10-29T16:55:07+02:00'
601
+ * @param horizon the terrain horizon profile
602
+ * @return the `Date` (to the second) when the sun was last visible, or an
603
+ * `Invalid Date` when there is no such crossing that day.
604
+ */
605
+ visibleSunset(horizon) {
606
+ return this.visibleSunMillis(horizon, false);
607
+ }
608
+ /**
609
+ * Alias for {@link visibleSunrise}
610
+ * @param horizon the terrain horizon profile
611
+ */
612
+ neitzHaNireh(horizon) {
613
+ return this.visibleSunrise(horizon);
614
+ }
615
+ /**
616
+ * Alias for {@link visibleSunset}
617
+ * @param horizon the terrain horizon profile
618
+ */
619
+ shkiahNireit(horizon) {
620
+ return this.visibleSunset(horizon);
621
+ }
622
+ /**
623
+ * Shared search driving {@link visibleSunrise} / {@link visibleSunset}.
624
+ *
625
+ * Scans the sun's geometric centre altitude `a` upward from −2.5° to +10° in
626
+ * 0.05° steps. At each step it maps `a` to a time (via the sea-level
627
+ * sunrise/sunset for the zenith `90 − a`) and that time to the sun's azimuth,
628
+ * then compares the upper limb's apparent altitude against the horizon
629
+ * profile at that azimuth. The sun is visible once that difference `g` is
630
+ * `≥ 0`; the first upward crossing is bisected to 0.0005° and its time
631
+ * returned. For sunrise this is the first moment seen; for sunset (same
632
+ * upward scan, afternoon times) it is the last moment seen.
633
+ * @param horizon the terrain horizon profile
634
+ * @param rising `true` for the morning, `false` for the evening
635
+ */
636
+ visibleSunMillis(horizon, rising) {
637
+ const lat = this.gloc.getLatitude();
638
+ const lon = this.gloc.getLongitude();
639
+ const timeAt = (a) => {
640
+ // adjustZenith() silently folds in refraction + semidiameter when the
641
+ // zenith is exactly 90° (GEOMETRIC_ZENITH), which would corrupt the
642
+ // geometric-altitude mapping. Nudge by 1e-9° — far below the 0.0005°
643
+ // bisection tolerance, so harmless — to steer clear of that branch.
644
+ let zenith = 90 - a;
645
+ if (zenith === 90) {
646
+ zenith = 90 + 1e-9;
647
+ }
648
+ const utc = rising
649
+ ? this.noaa.getUTCSeaLevelSunrise(zenith)
650
+ : this.noaa.getUTCSeaLevelSunset(zenith);
651
+ return this.noaa.getEpochMillisFromTime(utc, rising);
652
+ };
653
+ const azimuthAt = (t) => {
654
+ // The zone must be 'UTC': getSolarAzimuth() reads .hour/.minute/.second
655
+ // as UTC wall-clock fields.
656
+ const zdt = Temporal.Instant.fromEpochMilliseconds(t).toZonedDateTimeISO('UTC');
657
+ // getSolarAzimuth() uses atan() without quadrant resolution, so its
658
+ // result is only correct modulo 180°. Fold into [0,180) and add 180° in
659
+ // the evening so morning azimuths lie in (0°,180°) and evening ones in
660
+ // (180°,360°). This is a no-op for an already-correct azimuth (a correct
661
+ // morning azimuth is already in (0°,180°); a correct evening azimuth maps
662
+ // to itself), so it stays correct if a future noaa resolves the quadrant.
663
+ let az = NOAACalculator.getSolarAzimuth(zdt, lat, lon);
664
+ az = ((az % 180) + 180) % 180;
665
+ if (!rising) {
666
+ az += 180;
667
+ }
668
+ return az;
669
+ };
670
+ const g = (a) => upperLimbApparentAltitude(a) -
671
+ horizonElevation(horizon, azimuthAt(timeAt(a)));
672
+ const aLo = -2.5;
673
+ const aHi = 10;
674
+ const step = 0.05;
675
+ const tol = 0.0005;
676
+ // Evaluate the low end first so polar day/night (NaN time) is caught at once.
677
+ const tLo = timeAt(aLo);
678
+ if (Number.isNaN(tLo)) {
679
+ return millisToDate(NaN);
680
+ }
681
+ if (g(aLo) >= 0) {
682
+ return millisToDate(tLo);
683
+ }
684
+ let prevA = aLo;
685
+ for (let a = aLo + step; a <= aHi + 1e-9; a += step) {
686
+ if (Number.isNaN(timeAt(a))) {
687
+ return millisToDate(NaN);
688
+ }
689
+ if (g(a) >= 0) {
690
+ // Crossing in (prevA, a): bisect the altitude bracket to 0.0005°.
691
+ let lo = prevA;
692
+ let hi = a;
693
+ while (hi - lo > tol) {
694
+ const mid = (lo + hi) / 2;
695
+ if (g(mid) >= 0) {
696
+ hi = mid;
697
+ }
698
+ else {
699
+ lo = mid;
700
+ }
701
+ }
702
+ return millisToDate(timeAt(hi));
703
+ }
704
+ prevA = a;
705
+ }
706
+ return millisToDate(NaN);
707
+ }
517
708
  /**
518
709
  * Rabbeinu Tam holds that bein hashmashos is a specific time
519
710
  * between sunset and tzeis hakochavim.
@@ -525,7 +716,7 @@ class Zmanim {
525
716
  beinHaShmashos() {
526
717
  const tzeit = this.tzeit(DEG_7_POINT_083);
527
718
  const millis = tzeit.getTime();
528
- if (isNaN(millis)) {
719
+ if (Number.isNaN(millis)) {
529
720
  return tzeit;
530
721
  }
531
722
  return new Date(millis - 13.5 * 60 * 1000);
@@ -758,7 +949,7 @@ class Zmanim {
758
949
  *
759
950
  * According to the Baal Hatanya, _netz amiti_, or true (halachic) sunrise, is when the top of the sun's
760
951
  * disk is visible at an elevation similar to the mountains of Eretz Yisrael. The time is calculated as the point at which
761
- * the center of the sun's disk is 1.583° below the horizon. This degree-based calculation can be found in Rabbi Shalom
952
+ * the center of the sun's disk is 1° 35' (1.58333°) below the horizon. This degree-based calculation can be found in Rabbi Shalom
762
953
  * DovBer Levine's commentary on
763
954
  * [The Baal Hatanya's Seder Hachnasas Shabbos](https://www.chabadlibrary.org/books/pdf/Seder-Hachnosas-Shabbos.pdf).
764
955
  * From an elevation of 546 meters, the top of [Har Hacarmel](https://en.wikipedia.org/wiki/Mount_Carmel),
@@ -789,7 +980,7 @@ class Zmanim {
789
980
  *
790
981
  * According to the Baal Hatanya, _shkiah amiti_, true (_halachic_) sunset, is when the top of the
791
982
  * sun's disk disappears from view at an elevation similar to the mountains of _Eretz Yisrael_.
792
- * This time is calculated as the point at which the center of the sun's disk is 1.583 degrees below the horizon.
983
+ * This time is calculated as the point at which the center of the sun's disk is 1° 35' below the horizon.
793
984
  *
794
985
  * Note: _shkiah amiti_ is used only for calculating certain _zmanim_, and is intentionally unpublished. For
795
986
  * practical purposes, all daytime mitzvos should be completed before the published time for _shkiah_ / sunset.
@@ -857,15 +1048,18 @@ class Zmanim {
857
1048
  * [Ra"sh](https://en.wikipedia.org/wiki/Asher_ben_Jehiel),
858
1049
  * [Tur](https://en.wikipedia.org/wiki/Jacob_ben_Asher),
859
1050
  * [GRA](https://en.wikipedia.org/wiki/Vilna_Gaon) and others are of the opinion that _mincha_ can be prayed
860
- * _lechatchila_ starting at _mincha gedola_. This is calculated as 6.5 sea level solar hours after
861
- * _netz amiti_ (sunrise), based on the opinion of the Baal Hatanya that the day is calculated from
862
- * _netz amiti_ (sunrise) to _shkiah amiti_ (sunset).
1051
+ * _lechatchila_ starting at _mincha gedola_. This is calculated as {@link chatzot} (the midpoint of
1052
+ * sea level sunrise and sunset) plus half a solar hour, based on the opinion of the Baal Hatanya that
1053
+ * the day is calculated from _netz amiti_ (sunrise) to _shkiah amiti_ (sunset). This is how Chabad.org
1054
+ * calculates it; 6.5 solar hours after _netz amiti_ differs by under a second, but that is enough to
1055
+ * change the printed minute on a few days a year.
863
1056
  * @return the `Date` of the time of _mincha gedola_ according to the Baal Hatanya. If the calculation
864
1057
  * can't be computed, such as in the Arctic Circle where there is at least one day a year where the sun does not rise
865
1058
  * and one where it does not set, an `Invalid Date` will be returned.
866
1059
  */
867
1060
  minchaGedolaBaalHatanya() {
868
- return this.getShaahZmanisBaalHatanya(6.5);
1061
+ const hour = temporalHourMillis(this.getSunriseBaalHatanya(), this.getSunsetBaalHatanya());
1062
+ return millisToDate(this.chatzotMillis() + hour / 2);
869
1063
  }
870
1064
  /**
871
1065
  * This method returns the time of _mincha ketana_. This is the preferred earliest time to pray
@@ -913,7 +1107,7 @@ class Zmanim {
913
1107
  * {@link Location.getTimeFormatter}
914
1108
  */
915
1109
  static formatTime(dt, timeFormat) {
916
- if (isNaN(dt.getTime())) {
1110
+ if (Number.isNaN(dt.getTime())) {
917
1111
  return 'XX:XX'; // Invalid Date
918
1112
  }
919
1113
  const time = timeFormat.format(dt);
@@ -935,7 +1129,7 @@ class Zmanim {
935
1129
  */
936
1130
  static roundTime(dt) {
937
1131
  const millis = dt.getTime();
938
- if (isNaN(millis)) {
1132
+ if (Number.isNaN(millis)) {
939
1133
  return dt;
940
1134
  }
941
1135
  // Round up to next minute if needed
@@ -967,7 +1161,7 @@ class Zmanim {
967
1161
  * @param date
968
1162
  */
969
1163
  static formatISOWithTimeZone(tzid, date) {
970
- if (isNaN(date.getTime())) {
1164
+ if (Number.isNaN(date.getTime())) {
971
1165
  return '0000-00-00T00:00:00Z';
972
1166
  }
973
1167
  return (getPseudoISO(tzid, date).substring(0, 19) + Zmanim.timeZoneOffset(tzid, date));
@@ -982,7 +1176,7 @@ class Zmanim {
982
1176
  */
983
1177
  sunriseOffset(offset, roundMinute = true, forceSeaLevel = false) {
984
1178
  const sunrise = forceSeaLevel ? this.seaLevelSunrise() : this.sunrise();
985
- if (isNaN(sunrise.getTime())) {
1179
+ if (Number.isNaN(sunrise.getTime())) {
986
1180
  return sunrise;
987
1181
  }
988
1182
  if (roundMinute) {
@@ -1004,7 +1198,7 @@ class Zmanim {
1004
1198
  */
1005
1199
  sunsetOffset(offset, roundMinute = true, forceSeaLevel = false) {
1006
1200
  const sunset = forceSeaLevel ? this.seaLevelSunset() : this.sunset();
1007
- if (isNaN(sunset.getTime())) {
1201
+ if (Number.isNaN(sunset.getTime())) {
1008
1202
  return sunset;
1009
1203
  }
1010
1204
  if (roundMinute) {
@@ -1042,7 +1236,7 @@ class Zmanim {
1042
1236
  const sunset = zmanim.sunset();
1043
1237
  let hd = new HDate(date);
1044
1238
  const sunsetMillis = sunset.getTime();
1045
- if (isNaN(sunsetMillis)) {
1239
+ if (Number.isNaN(sunsetMillis)) {
1046
1240
  return hd;
1047
1241
  }
1048
1242
  if (date.getTime() >= sunsetMillis) {