Skip to content

Instantly share code, notes, and snippets.

@tdiluzio
Last active November 24, 2021 12:06
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 tdiluzio/5e0ce7ad3eb72037cfbe3297875b702b to your computer and use it in GitHub Desktop.
Save tdiluzio/5e0ce7ad3eb72037cfbe3297875b702b to your computer and use it in GitHub Desktop.
Metropolitan France Holidays
// Christian holidays utils
// base ressources
// https://gist.github.com/johndyer/0dffbdd98c2046f41180c051f378f343#gistcomment-3774086
// https://www.codeproject.com/Articles/10860/Calculating-Christian-Holidays by Jan Schreuder
import { addDays, format, subDays } from 'date-fns';
// https://gist.github.com/johndyer/0dffbdd98c2046f41180c051f378f343#gistcomment-3774086
// getEaster day for a given year
function getEaster(year: number) {
const f = Math.floor,
G = year % 19,
C = f(year / 100),
H = (C - f(C / 4) - f((8 * C + 13) / 25) + 19 * G + 15) % 30,
I = H - f(H / 28) * (1 - f(29 / (H + 1)) * f((21 - G) / 11)),
J = (year + f(year / 4) + I + 2 - C + f(C / 4)) % 7,
L = I - J,
month = 3 + f((L + 40) / 44),
day = L + 28 - 31 * f(month / 4);
return new Date(year, month - 1, day);
}
// Movable religious holidays relative to Easter
// 1 day after Easter
const getEasterMonday = (year: number) => addDays(getEaster(year), 1);
// Ascension Day is 39 days after Easter
const getAscensionDay = (year: number) => addDays(getEaster(year), 39);
// WhitMonday is 48 days after Easter monday (49 after whit sunday)
const getWhitMonday = (year: number) => addDays(addDays(getEasterMonday(year), 1), 48);
// Christ crucifixion is 2 days before Easter
const getGoodFriday = (year: number) => subDays(getEaster(year), 2);
// END movable holidays
const yearMonthDayFormat = 'yyyy-MM-dd';
/**
*
* @param year
* @returns a dictionnary of holidays
*/
const getHolidays = (year: number): { [key: string]: string } => ({
new_year_day: `${year}-01-01`,
easter_monday: format(getEasterMonday(year), yearMonthDayFormat),
labor_day: `${year}-05-01`,
victory_1945: `${year}-05-08`,
// local Alsace/Moselle holidays
christ_crucifixion_friday: format(getGoodFriday(year), yearMonthDayFormat),
ascension_day: format(getAscensionDay(year), yearMonthDayFormat),
whit_monday: format(getWhitMonday(year), yearMonthDayFormat),
national_day: `${year}-07-14`,
assumption: `${year}-08-15`,
all_saints: `${year}-11-01`,
armistice_1918: `${year}-11-11`,
christmas: `${year}-12-25`,
// local Alsace/Moselle holidays
christmas_second_day: `${year}-12-26`,
});
export { getHolidays };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment