Created
October 6, 2023 12:54
-
-
Save utlime/b54677f3ebd9dd7558b524c9031e33d6 to your computer and use it in GitHub Desktop.
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
/** | |
* @param {number} year | |
* @return {Date} | |
*/ | |
function getBlackFridayDate(year) { | |
const date = new Date(year, 10, 1); // first day of November | |
const day = date.getDay(); | |
if (day < 4) { | |
date.setDate(date.getDate() + (4 - day)); // first Thusday of November | |
} else if (day > 4) { | |
date.setDate(date.getDate() + 7 - (day - 4)); // first Thusday of November | |
} | |
date.setDate(date.getDate() + 7 * 3 + 1); // fourth Friday of November | |
return date; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment