X Tutup
Skip to content

Commit 63c7732

Browse files
re-formate wth standard.js
1 parent cd26e97 commit 63c7732

File tree

1 file changed

+21
-21
lines changed

1 file changed

+21
-21
lines changed

Conversions/DateToDay.js

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
11
/*
22
DateToDay Method
33
----------------
4-
The DateToDay method takes a date in string format and
5-
returns the name of a day. The approach behind this method
6-
is very simple, we first take a string date and check
7-
whether their date is valid or not, if the date is valid
8-
then we do this But apply the algorithm shown below. The
9-
algorithm shown below gives us the number of the day and
4+
The DateToDay method takes a date in string format and
5+
returns the name of a day. The approach behind this method
6+
is very simple, we first take a string date and check
7+
whether their date is valid or not, if the date is valid
8+
then we do this But apply the algorithm shown below. The
9+
algorithm shown below gives us the number of the day and
1010
finally converts it to the name of the day.
1111
1212
Algorithm & Explanation : https://cs.uwaterloo.ca/~alopez-o/math-faq/node73.html
1313
*/
1414

1515
// March is taken as the first month of the year.
1616
const calcMonthList = {
17-
1: 11,
18-
2: 12,
19-
3: 1,
20-
4: 2,
21-
5: 3,
22-
6: 4,
23-
7: 5,
24-
8: 6,
25-
9: 7,
26-
10: 8,
27-
11: 9,
28-
12: 10
17+
1: 11,
18+
2: 12,
19+
3: 1,
20+
4: 2,
21+
5: 3,
22+
6: 4,
23+
7: 5,
24+
8: 6,
25+
9: 7,
26+
10: 8,
27+
11: 9,
28+
12: 10
2929
}
3030

3131
// show the week day in a number : Sunday - Saturday => 0 - 6
@@ -47,16 +47,16 @@ const DateToDay = (date) => {
4747
// extarct the date
4848
const [day, month, year] = date.split('/').map((x) => Number(x))
4949
// check the data are valid or not.
50-
if ( day < 0 || day > 31 || month > 12 || month < 0) {
50+
if (day < 0 || day > 31 || month > 12 || month < 0) {
5151
return new TypeError('Date is not valid.')
5252
}
5353
// divide year to century and yearDigit value.
5454
const yearDigit = (year % 100)
5555
const century = Math.floor(year / 100)
5656
// Apply the algorithm shown above
57-
const weekDay = Math.abs((day + Math.floor((2.6 * calcMonthList[month]) - 0.2) - (2 * century) + yearDigit + Math.floor(yearDigit/4) + Math.floor(century/4)) % 7)
57+
const weekDay = Math.abs((day + Math.floor((2.6 * calcMonthList[month]) - 0.2) - (2 * century) + yearDigit + Math.floor(yearDigit / 4) + Math.floor(century / 4)) % 7)
5858
// return the weekDay name.
59-
return daysNameList[weekDay];
59+
return daysNameList[weekDay]
6060
}
6161

6262
// Example : DateToDay("18/12/2020") => Friday

0 commit comments

Comments
 (0)
X Tutup