forked from thuva4/Algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDoomsday.js
More file actions
38 lines (35 loc) · 937 Bytes
/
Copy pathDoomsday.js
File metadata and controls
38 lines (35 loc) · 937 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
36
37
38
/**
* Determines the day of the week using Tomohiko Sakamoto's Algorithm
* to calculate Day of Week based on Gregorian calendar.
*/
function dow(y, m, d) {
let t = [0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4];
y -= (m < 3) ? 1 : 0;
return Math.round(y + y / 4 - y / 100 + y / 400 + t[m - 1] + d) % 7;
}
/**
* Determines the day of the week using Tomohiko Sakamoto's Algorithm
* to calculate Day of Week based on Gregorian calendar.
*/
function dowS(y, m, d) {
switch (dow(y, m, d)) {
case 0:
return "Sunday";
case 1:
return "Monday";
case 2:
return "Tuesday";
case 3:
return "Wednesday";
case 4:
return "Thursday";
case 5:
return "Friday";
case 6:
return "Saturday";
default:
console.log("Unknown dow");
}
return null;
}
module.exports = { dow, dowS};