forked from thuva4/Algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
39 lines (36 loc) · 879 Bytes
/
Copy pathindex.js
File metadata and controls
39 lines (36 loc) · 879 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
39
/* eslint-disable valid-jsdoc */
/**
* 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) {
const 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};