-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Expand file tree
/
Copy pathZellersCongruenceAlgorithm.js
More file actions
35 lines (35 loc) · 813 Bytes
/
ZellersCongruenceAlgorithm.js
File metadata and controls
35 lines (35 loc) · 813 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// Zeller's Congruence Algorithm finds the day of the week from the Gregorian Date. Wikipedia: https://un5qgjbzw9dxcq3ecfxberhh.julianrbryant.com/wiki/Zeller%27s_congruence
export const zellersCongruenceAlgorithm = (day, month, year) => {
if (
typeof day !== 'number' ||
typeof month !== 'number' ||
typeof year !== 'number'
) {
throw new TypeError('Arguments are not all numbers.')
}
const q = day
let m = month
let y = year
if (month < 3) {
m += 12
y -= 1
}
day =
(q +
Math.floor((26 * (m + 1)) / 10) +
(y % 100) +
Math.floor((y % 100) / 4) +
Math.floor(Math.floor(y / 100) / 4) +
5 * Math.floor(y / 100)) %
7
const days = [
'Saturday',
'Sunday',
'Monday',
'Tuesday',
'Wednesday',
'Thursday',
'Friday'
]
return days[day]
}