hebcal / hebcal-es6

perpetual Jewish Calendar with holidays, Shabbat and holiday candle lighting and havdalah times, Torah readings, and more
https://hebcal.github.io/api/core/
GNU General Public License v2.0
98 stars 14 forks source link

Eruv Tavshilin implemenation #445

Closed PupaRebbe closed 3 months ago

PupaRebbe commented 3 months ago

Not sure which class should implement this, probably HebrewCalendar. Here is the code:

function eruvTavshilin(dt, il){
    if(dt.getDay() <3 || dt.getDay() >4) return false;
    const today = new HDate(dt);
    const friday = today.after(5), tomorrow = today.next();
    if(!isChag(friday, il) || isChag(today, il) || !isChag(tomorrow, il)) return false;
    return true;
}

function isChag(dt, il){
    const options = {
        start: dt,
        end: dt,
        mask: flags.CHAG,
        il: il
    };
    const events = HebrewCalendar.calendar(options);
    return Boolean(events.length);
}
mjradwin commented 3 months ago

Added to 5.4.0

HebrewCalendar.eruvTavshilin(date, il) ⇒ boolean

Eruv Tavshilin

Kind: static method of HebrewCalendar

Param Type
date Date | HDate
il boolean