Voici une méthode alternative basée sur un algorithme que R. Sivaraman a adapté pour le calendrier grégorien à partir d'un algorithme développé à l'origine par J. Meeus pour le calendrier julien (voir https://en.wikipedia.org/wiki/Computus).
Cela semble être une solution plus élégante et plus intuitive que l'algorithme de Gauss déjà mentionné. Au moins, il rase quelques étapes (seulement 5 au total plus le JS date methods) et utilise moins de variables (seulement 4 au total plus le mois, la date et l'année).
function computus(y) {
var date, a, b, c, m, d;
// Instantiate the date object.
date = new Date;
// Set the timestamp to midnight.
date.setHours(0, 0, 0, 0);
// Set the year.
date.setFullYear(y);
// Find the golden number.
a = y % 19;
// Choose which version of the algorithm to use based on the given year.
b = (2200 <= y && y <= 2299) ?
((11 * a) + 4) % 30 :
((11 * a) + 5) % 30;
// Determine whether or not to compensate for the previous step.
c = ((b === 0) || (b === 1 && a > 10)) ?
(b + 1) :
b;
// Use c first to find the month: April or March.
m = (1 <= c && c <= 19) ? 3 : 2;
// Then use c to find the full moon after the northward equinox.
d = (50 - c) % 31;
// Mark the date of that full moon—the "Paschal" full moon.
date.setMonth(m, d);
// Count forward the number of days until the following Sunday (Easter).
date.setMonth(m, d + (7 - date.getDay()));
// Gregorian Western Easter Sunday
return date;
}
Par exemple:
console.log(computus(2016)); // Date 2016-03-27T05:00:00.000Z
Merci, je laisse mes autres fonctions convertissent en un horodatage Unix –
Pour 2016, il donne « 03.27 », qui est « le dimanche de Pâques » pour 2016. Ainsi correcte pour 2016 ... – Tompi