Last active
July 24, 2020 07:18
-
-
Save joe-oli/39566a7f1beba0439346a2a9b235c1f1 to your computer and use it in GitHub Desktop.
Weekend in Javascript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function isWeekend(thisDate) { | |
let tf = Object.prototype.toString.call(thisDate) === '[object Date]' | |
if (tf) | |
throw new Exception("input parameter is not a Date) | |
//.getDay() returns a integer between 0 and 6 (0 being Sunday, 6 being Saturday). | |
if( thisDate.getDay() == 6 || thisDate.getDay() == 0 ) | |
return true; | |
else | |
return false; | |
} | |
/* *** USAGE *** */ | |
let dt = new Date() | |
if isWeekend(dt) | |
alert(`${dt} is weekend') | |
else | |
alert(`${dt} is NOT weekend') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment