Created
April 4, 2019 07:47
-
-
Save Langmans/3aad83e6e4ea349e7767be81fdeb03a0 to your computer and use it in GitHub Desktop.
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 {int} y year | |
* @param {int} w ISO week (1-52) | |
* @param {int} d ISO weekday (1-7) | |
* @returns {Date} | |
*/ | |
function getDateByISOYearWeek(y, w, d) { | |
d = d || 1; | |
var simple = new Date(Date.UTC(y, 0, 1 + (w - 1) * 7)); | |
var dow = simple.getDay(); | |
var ISOweekStart = simple; | |
if (dow <= 4) | |
ISOweekStart.setDate(simple.getDate() - simple.getDay() + 1); | |
else | |
ISOweekStart.setDate(simple.getDate() + 8 - simple.getDay()); | |
ISOweekStart.setDate(ISOweekStart.getDate() + (d - 1)); | |
return ISOweekStart; | |
} | |
getDateByISOYearWeek(2020, 1, 1) // Mon Dec 30 2019 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment