forked from TheAlgorithms/JavaScript
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathZellersCongruenceAlgorithm.js
More file actions
Latest commit
26 lines (26 loc) · 775 Bytes
/
Copy pathZellersCongruenceAlgorithm.js
File metadata and controls
26 lines (26 loc) · 775 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
// Zeller's Congruence Algorithm finds the day of the week from the Gregorian Date. Wikipedia: https://en.wikipedia.org/wiki/Zeller%27s_congruence
exportconstzellersCongruenceAlgorithm=(day,month,year)=>{
if(typeofday!=='number'||typeofmonth!=='number'||typeofyear!=='number'){
thrownewTypeError('Arguments are not all numbers.')
}
constq=day
letm=month
lety=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
constdays=[
'Saturday',
'Sunday',
'Monday',
'Tuesday',
'Wednesday',
'Thursday',
'Friday'
]
returndays[day]
}