Created
December 8, 2015 11:00
-
-
Save romuleald/2fb63e6426faffb7abfa to your computer and use it in GitHub Desktop.
Get day in a week
This file contains 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
/** | |
* | |
* @param date Date | |
* @param dayOfWeek {Number} between 1 (monday) to 7 (sunday) | |
*/ | |
var getDayOfWeek = function (date, dayOfWeek) { | |
if(dayOfWeek > 7 || dayOfWeek < 1){ | |
console.warn('dayOfWeek is out of range (1-7), was:', dayOfWeek); | |
} | |
var _date = new Date(date); | |
_date.setDate(_date.getDate() - (_date.getDay() || 7) + dayOfWeek); | |
return _date; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment