MCPcopy Create free account
hub / github.com/BrasilAPI/BrasilAPI / getEasterHolidays

Function getEasterHolidays

services/holidays/index.js:64–110  ·  view source on GitHub ↗
(year)

Source from the content-addressed store, hash-verified

62 * @see https://en.wikipedia.org/wiki/Computus
63 */
64export function getEasterHolidays(year) {
65 if (year < 1900 || year > 2199) {
66 throw new NotFoundError({
67 name: 'NotFoundError',
68 message: 'Ano fora do intervalo suportado entre 1900 e 2199.',
69 type: 'feriados_range_error',
70 });
71 }
72
73 const pascalFullMoonMonthDay = getPascalFullMoonDates();
74 const [refMonth, refDay] = pascalFullMoonMonthDay[year % 19];
75 const movingDate = new Date(year, refMonth, refDay);
76 const holidays = [];
77 movingDate.setDate(movingDate.getDate() + 7 - movingDate.getDay());
78 const easterDate = formatDate(movingDate);
79 holidays.push({
80 date: easterDate,
81 name: 'Páscoa',
82 type: 'national',
83 weekday: getWeekdayName(easterDate),
84 });
85 movingDate.setDate(movingDate.getDate() - 2);
86 const goodFridayDate = formatDate(movingDate);
87 holidays.push({
88 date: goodFridayDate,
89 name: 'Sexta-feira Santa',
90 type: 'national',
91 weekday: getWeekdayName(goodFridayDate),
92 });
93 movingDate.setDate(movingDate.getDate() - 45);
94 const carnavalDate = formatDate(movingDate);
95 holidays.push({
96 date: carnavalDate,
97 name: 'Carnaval',
98 type: 'national',
99 weekday: getWeekdayName(carnavalDate),
100 });
101 movingDate.setDate(movingDate.getDate() + 107);
102 const corpusChristiDate = formatDate(movingDate);
103 holidays.push({
104 date: corpusChristiDate,
105 name: 'Corpus Christi',
106 type: 'national',
107 weekday: getWeekdayName(corpusChristiDate),
108 });
109 return holidays;
110}
111
112/**
113 * Combina feriados móveis e fixos.

Callers 1

getHolidaysFunction · 0.70

Calls 3

getPascalFullMoonDatesFunction · 0.85
formatDateFunction · 0.70
getWeekdayNameFunction · 0.70

Tested by

no test coverage detected