Skip to content

Instantly share code, notes, and snippets.

@tobiasroeder
Created November 29, 2022 13:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tobiasroeder/39e23693b5f21f97434478c9a63e6f0f to your computer and use it in GitHub Desktop.
Save tobiasroeder/39e23693b5f21f97434478c9a63e6f0f to your computer and use it in GitHub Desktop.
Get the date for all four advent.
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