Last active
April 19, 2020 05:05
-
-
Save pignuante/ca17258ac4bde1251eedec02adacd0e0 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
function getWeekOfMonth(date) { | |
let adjustedDate = date.getDate()+date.getDay(); | |
let prefixes = ['0', '1', '2', '3', '4', '5']; | |
return (parseInt(prefixes[0 | adjustedDate / 7])+1); | |
} | |
function getDateOfWeek(w, y) { | |
var d = (1 + (w - 1) * 7); // 1st of January + 7 days for each week | |
return new Date(y, 0, d); | |
} | |
function getDateOfISOWeek(w, y) { | |
var simple = new Date(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()); | |
return ISOweekStart; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment