Last active
February 3, 2021 14:20
-
-
Save gkucmierz/a84bb148a9b0c1d6be99f1d89e08e6e3 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
// const Sunday = 0; | |
// const Monday = 1; | |
const TUESDAY = 2; | |
// const Wednesday = 3; | |
// const Thursday = 4; | |
// const Friday = 5; | |
// const Saturday = 6; | |
const firstDayOfMonth = (year, month, weekDay) => { | |
const DAYS_IN_WEEK = 7; | |
const day = new Date(year, month, 0).getDay(); | |
const shift = (DAYS_IN_WEEK + weekDay - day) % DAYS_IN_WEEK; | |
const date = new Date(year, month, shift); | |
return date; | |
}; | |
console.log('luty 2021', firstDayOfMonth(2021, 1, TUESDAY).toString()); | |
console.log('styczeń 2021', firstDayOfMonth(2021, 0, TUESDAY).toString()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment