refactor: deobfuscate getEaster function

This commit is contained in:
madkarmaa 2025-05-04 16:00:19 +02:00
parent 150f14bedf
commit be63dad3a1
No known key found for this signature in database
GPG Key ID: BF5E2EF8F188606D

View File

@ -14,25 +14,25 @@ type MonthName =
| 'november' | 'november'
| 'december'; | 'december';
// prettier-ignore
const getEaster = (): Moment => { const getEaster = (): Moment => {
const currentYear = new Date().getFullYear(); const currentYear = new Date().getFullYear();
const yearMod19 = currentYear % 19;
const century = Math.floor(currentYear / 100);
const yearInCentury = currentYear % 100;
const centuryQuotient = Math.floor(century / 4);
const centuryRemainder = century % 4;
const specialCenturyTerm = Math.floor((century + 8) / 25);
const specialCenturyCorrection = Math.floor((century - specialCenturyTerm + 1) / 3);
const lunarCorrection = (19 * yearMod19 + century - centuryQuotient - specialCenturyCorrection + 15) % 30;
const yearQuotient = Math.floor(yearInCentury / 4);
const yearRemainder = yearInCentury % 4;
const dayOfWeekCorrection = (32 + 2 * centuryRemainder + 2 * yearQuotient - lunarCorrection - yearRemainder) % 7;
const specialLunarCorrection = Math.floor((yearMod19 + 11 * lunarCorrection + 22 * dayOfWeekCorrection) / 451);
const easterMonth = Math.floor((lunarCorrection + dayOfWeekCorrection - 7 * specialLunarCorrection + 114) / 31);
const easterDay = ((lunarCorrection + dayOfWeekCorrection - 7 * specialLunarCorrection + 114) % 31) + 1;
const a = currentYear % 19, return moment(new Date(currentYear, easterMonth - 1, easterDay));
b = Math.floor(currentYear / 100),
c = currentYear % 100,
d = Math.floor(b / 4),
e = b % 4,
f = Math.floor((b + 8) / 25),
g = Math.floor((b - f + 1) / 3),
h = (19 * a + b - d - g + 15) % 30,
i = Math.floor(c / 4),
k = c % 4,
L = (32 + 2 * e + 2 * i - h - k) % 7,
m = Math.floor((a + 11 * h + 22 * L) / 451),
month = Math.floor((h + L - 7 * m + 114) / 31),
day = ((h + L - 7 * m + 114) % 31) + 1;
return moment(new Date(currentYear, month - 1, day));
}; };
export const events = { export const events = {