hebcal / hebcal-js

⛔️ DEPRECATED - a perpetual Jewish Calendar (JavaScript)
GNU General Public License v3.0
123 stars 40 forks source link

I don't get how tachanun works #38

Closed orelzion closed 7 years ago

orelzion commented 7 years ago

Hi

A great library, thanks! I didn't understand how Tachanun works, it seems that it returns different integers than described, or I'm calling it wrong

When I'm trying to get Tachanun for 4th of Tishri, it returns 7, the same is with 8th, but 9th returns 0. Also, Yom Haatzmaut returns 3

Can you please explain how to use this function? Thanks

Scimonster commented 7 years ago

The function returns an integer that functions as a bitmask. To understand the return values, you can look at them in binary (3 bits):

0 - 000 - not all congregations say tachanun, no Shacharit, no Mincha [i.e no tachanun, according to everyone]
1 - 001 - not all congregations say tachanun, no Shacharit, yes Mincha [I don't think this is possible]
2 - 010 - not all congregations say tachanun, yes Shacharit, no Mincha [Some say tachanun at Shacharit]
3 - 011 - not all congregations say tachanun, yes Shacharit, yes Mincha [Some congregations say tachanun]
4 - 100 - all congregations say tachanun, no Shacharit, no Mincha [impossible return value]
5 - 101 - all congregations say tachanun, no Shacharit, yes Mincha [also impossible, same reason as 1]
6 - 110 - all congregations say tachanun, yes Shacharit, no Mincha [Tachanun at Shacharit, according to everyone]
7 - 111 - all congregations say tachanun, yes Shacharit, yes Mincha [Tachanun at Shacharit and Mincha, according to everyone]

You can extract values using bitwise AND (&):

today.tachanun() & 1 // truthy if Tachanun is said at Mincha, falsy otherwise
today.tachanun() & 2 // truthy if Tachanun is said at Shacharit, falsy otherwise
today.tachanun() & 4 // truthy if Tachanun is said by all congregations at the tefilot indicated by the other two bits, falsy otherwise

Hope this helps.

Scimonster commented 7 years ago

Added a tachanun_uf() function in v2.2.4.

new Hebcal.HDate('1 Tishrei').tachanun_uf() // { shacharit: false, mincha: false, all_congs: false }
new Hebcal.HDate('25 Tishrei').tachanun_uf() // { shacharit: true, mincha: true, all_congs: false }
new Hebcal.HDate('6 Cheshvan').tachanun_uf() // { shacharit: true, mincha: true, all_congs: true }
new Hebcal.HDate().onOrAfter(5).tachanun_uf() // Friday: { shacharit: true, mincha: false, all_congs: true }
new Hebcal.HDate().onOrAfter(6).tachanun_uf() // Shabbat: { shacharit: false, mincha: true, all_congs: true }