Created
November 29, 2022 13:46
-
-
Save tobiasroeder/39e23693b5f21f97434478c9a63e6f0f to your computer and use it in GitHub Desktop.
Get the date for all four advent.
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
class Advent { | |
#oneDayMs = 86400000; | |
constructor(year = new Date().getFullYear()) { | |
this.christmasEve = `${year}-12-24`; | |
this.christmasEveDate = new Date(this.christmasEve); | |
} | |
#getDiff(days) { | |
return this.christmasEveDate.getDay() + days; | |
} | |
#calcDate(days) { | |
return +this.christmasEveDate - this.#getDiff(days) * this.#oneDayMs; | |
} | |
first() { | |
return this.#calcDate(21); | |
} | |
second() { | |
return this.#calcDate(14); | |
} | |
third() { | |
return this.#calcDate(7); | |
} | |
fourth() { | |
return this.#calcDate(0); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment