Created
July 27, 2017 21:36
-
-
Save kodie/b277e7e3903bc38e29e806396fd08280 to your computer and use it in GitHub Desktop.
Calculate when Rosh Hashanah is
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var roshHashanah = function(y) { | |
var g = (y % 19) + 1 | |
var n = (Math.floor(y / 100) - Math.floor(y / 400) - 2) + ((765433 / 492480 * ((12 * g) % 19)) + ((y % 4) / 4) - ((313 * y + 89081) / 98496)); | |
var r = Math.floor(n); | |
var m = 9; | |
var h = m; | |
var d = r; | |
if (r > 30) { h = 10; d = r - 30; } | |
var a = Math.floor((14 - h) / 12); | |
var i = y - a; | |
var s = h + 12 * a - 2; | |
var w = (h + i + Math.floor(i / 4) - Math.floor(i / 100) + Math.floor(i / 400) + Math.floor(31 * s / 12)) % 7; | |
if (w === 0 || w === 3 || w === 5) { | |
r += 1; | |
} else if (w === 1) { | |
if ((n - r) >= 23269 / 25920 && ((12 * g) % 19) > 11) { r++; } | |
} else if (w === 2) { | |
if ((n - r) >= 1367 / 2160 && ((12 * g) % 19) > 6) { r += 2; } | |
} | |
var d = r; | |
if (r > 30) { m = 10; d = r - 30; } | |
return moment([y, (m - 1), (d - 1)]); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment