Skip to content

Commit

Permalink
Fix rendering of Shabbat Mevarchim memo to respect hour12 and locale #…
Browse files Browse the repository at this point in the history
  • Loading branch information
mjradwin committed Jan 14, 2024
1 parent c486953 commit 326ce96
Show file tree
Hide file tree
Showing 12 changed files with 521 additions and 474 deletions.
123 changes: 60 additions & 63 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hebcal/core",
"version": "5.0.9",
"version": "5.1.0",
"author": "Michael J. Radwin (https://github.com/mjradwin)",
"contributors": [
"Eyal Schachter (https://github.com/Scimonster)",
Expand Down
14 changes: 6 additions & 8 deletions src/candles.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,30 @@ import {Locale} from './locale.js';
import {reformatTimeStr} from './reformatTimeStr.js';
import {Zmanim} from './zmanim.js';

const FRI = 5;
const SAT = 6;

/**
* @private
* @param {Event} e
* @param {HDate} hd
* @param {number} dow
* @param {CalOptions} options
* @param {boolean} isFriday
* @param {boolean} isSaturday
* @return {Event}
*/
export function makeCandleEvent(e, hd, dow, options) {
export function makeCandleEvent(e, hd, options, isFriday, isSaturday) {
let havdalahTitle = false;
let useHavdalahOffset = dow === SAT;
let useHavdalahOffset = isSaturday;
let mask = e ? e.getFlags() : flags.LIGHT_CANDLES;
if (typeof e !== 'undefined') {
// if linked event && dow == FRI, use Candle lighting time & title
if (dow !== FRI) {
if (!isFriday) {
if (mask & (flags.LIGHT_CANDLES_TZEIS | flags.CHANUKAH_CANDLES)) {
useHavdalahOffset = true;
} else if (mask & flags.YOM_TOV_ENDS) {
havdalahTitle = true;
useHavdalahOffset = true;
}
}
} else if (dow === SAT) {
} else if (isSaturday) {
havdalahTitle = true;
mask = flags.LIGHT_CANDLES_TZEIS;
}
Expand Down
28 changes: 18 additions & 10 deletions src/candles.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ test('makeCandleEvent-nosunset', (t) => {
const events = [];
for (const dt of dates) {
const hd = new HDate(new Date(dt[0], dt[1], dt[2]));
const ev = makeCandleEvent(undefined, hd, hd.getDay(), options);
const dow = hd.getDay();
const isFri = dow === 5;
const isSat = dow === 6;
const ev = makeCandleEvent(undefined, hd, options, isFri, isSat);
events.push(ev);
}
const result = events.map(eventDateDesc);
Expand All @@ -62,7 +65,10 @@ test('makeCandleEvent-nosunset', (t) => {
const events2 = [];
for (const dt of dates) {
const hd = new HDate(new Date(dt[0], dt[1], dt[2]));
const ev = makeCandleEvent(undefined, hd, hd.getDay(), options);
const dow = hd.getDay();
const isFri = dow === 5;
const isSat = dow === 6;
const ev = makeCandleEvent(undefined, hd, options, isFri, isSat);
events2.push(ev);
}
const result2 = events2.map(eventDateDesc);
Expand Down Expand Up @@ -508,16 +514,18 @@ test('renderBrief', (t) => {
test('havdalahDeg', (t) => {
const hd = new HDate(new Date(2020, 4, 16));
const dow = hd.getDay();
const isFri = dow === 5;
const isSat = dow === 6;
const location = new Location(0, 0, false, 'UTC', undefined, 'GB');
const events = [
makeCandleEvent(undefined, hd, dow, {location}),
makeCandleEvent(undefined, hd, dow, {location, havdalahDeg: 6.5}),
makeCandleEvent(undefined, hd, dow, {location, havdalahDeg: 7.0833}),
makeCandleEvent(undefined, hd, dow, {location, havdalahDeg: 7.5}),
makeCandleEvent(undefined, hd, dow, {location, havdalahDeg: 8.5}),
makeCandleEvent(undefined, hd, dow, {location, havdalahMins: 42}),
makeCandleEvent(undefined, hd, dow, {location, havdalahMins: 50}),
makeCandleEvent(undefined, hd, dow, {location, havdalahMins: 72}),
makeCandleEvent(undefined, hd, {location}, isFri, isSat),
makeCandleEvent(undefined, hd, {location, havdalahDeg: 6.5}, isFri, isSat),
makeCandleEvent(undefined, hd, {location, havdalahDeg: 7.0833}, isFri, isSat),
makeCandleEvent(undefined, hd, {location, havdalahDeg: 7.5}, isFri, isSat),
makeCandleEvent(undefined, hd, {location, havdalahDeg: 8.5}, isFri, isSat),
makeCandleEvent(undefined, hd, {location, havdalahMins: 42}, isFri, isSat),
makeCandleEvent(undefined, hd, {location, havdalahMins: 50}, isFri, isSat),
makeCandleEvent(undefined, hd, {location, havdalahMins: 72}, isFri, isSat),
];
const results = events.map(eventDateDesc);
const expected = [
Expand Down
Loading

0 comments on commit 326ce96

Please sign in to comment.