From 63c7732ddae598efbcab4a3f59f0780975db5e70 Mon Sep 17 00:00:00 2001 From: Suryapratap Singh Date: Mon, 23 Aug 2021 12:34:17 +0530 Subject: [PATCH] re-formate wth standard.js --- Conversions/DateToDay.js | 42 ++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/Conversions/DateToDay.js b/Conversions/DateToDay.js index 9d619974e..ed65d1854 100644 --- a/Conversions/DateToDay.js +++ b/Conversions/DateToDay.js @@ -1,12 +1,12 @@ /* DateToDay Method ---------------- - The DateToDay method takes a date in string format and - returns the name of a day. The approach behind this method - is very simple, we first take a string date and check - whether their date is valid or not, if the date is valid - then we do this But apply the algorithm shown below. The - algorithm shown below gives us the number of the day and + The DateToDay method takes a date in string format and + returns the name of a day. The approach behind this method + is very simple, we first take a string date and check + whether their date is valid or not, if the date is valid + then we do this But apply the algorithm shown below. The + algorithm shown below gives us the number of the day and finally converts it to the name of the day. Algorithm & Explanation : https://cs.uwaterloo.ca/~alopez-o/math-faq/node73.html @@ -14,18 +14,18 @@ // March is taken as the first month of the year. const calcMonthList = { - 1: 11, - 2: 12, - 3: 1, - 4: 2, - 5: 3, - 6: 4, - 7: 5, - 8: 6, - 9: 7, - 10: 8, - 11: 9, - 12: 10 + 1: 11, + 2: 12, + 3: 1, + 4: 2, + 5: 3, + 6: 4, + 7: 5, + 8: 6, + 9: 7, + 10: 8, + 11: 9, + 12: 10 } // show the week day in a number : Sunday - Saturday => 0 - 6 @@ -47,16 +47,16 @@ const DateToDay = (date) => { // extarct the date const [day, month, year] = date.split('/').map((x) => Number(x)) // check the data are valid or not. - if ( day < 0 || day > 31 || month > 12 || month < 0) { + if (day < 0 || day > 31 || month > 12 || month < 0) { return new TypeError('Date is not valid.') } // divide year to century and yearDigit value. const yearDigit = (year % 100) const century = Math.floor(year / 100) // Apply the algorithm shown above - 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) + 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) // return the weekDay name. - return daysNameList[weekDay]; + return daysNameList[weekDay] } // Example : DateToDay("18/12/2020") => Friday