Created
August 23, 2024 21:47
-
-
Save dami-i/2d3675e029c19278f257579a5ad1af5f to your computer and use it in GitHub Desktop.
Cálculo de feriados móveis - Terça-Feira de Carnaval, Sexta-Feira Santa, Páscoa e Corpus Christi
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Todos os feriados móveis do calendário brasileiro são calculados a partir da Páscoa. | |
/** | |
* Cálculo da data da Páscoa pelo algoritmo de Meeus. | |
*/ | |
function pascoa(ano) { | |
const a = ano % 19; | |
const b = ~~(ano / 100); // Inteiro da divisão | |
const c = ano % 100; | |
const d = ~~(b / 4); | |
const e = b % 4; | |
const f = ~~((b + 8) / 25); | |
const g = ~~((b - f + 1) / 3); | |
const h = ((19 * a) + b - d - g + 15) % 30; | |
const i = ~~(c / 4); | |
const j = c % 4; | |
const k = (32 + (2 * e) + (2 * i) - h - j) % 7; | |
const l = ~~((a + (11 * h) + 22 * k) / 451); | |
const mes = ~~((h + k - (7 * l) + 114) / 31); | |
const dia = 1 + ((h + k - (7 * l) + 114) % 31); | |
return new Date(ano, mes - 1, dia); | |
} | |
/** | |
* O feriado da Sexta-Feira Santa (ou Sexta-Feira da Paixão) é 2 dias antes da Páscoa | |
*/ | |
function sextaFeiraSanta(ano) { | |
const dataPascoa = pascoa(ano); | |
return new Date(dataPascoa.getFullYear(), dataPascoa.getMonth(), dataPascoa.getDate() - 2); | |
} | |
/** | |
* A terça-feira de Carnaval é 47 dias antes da Páscoa | |
*/ | |
function carnaval(ano) { | |
const dataPascoa = pascoa(ano); | |
return new Date(dataPascoa.getFullYear(), dataPascoa.getMonth(), dataPascoa.getDate() - 47); | |
} | |
/** | |
* O feriado de Corpus Christi é 60 dias depois da Páscoa | |
*/ | |
function corpusChristi(ano) { | |
const dataPascoa = pascoa(ano); | |
return new Date(dataPascoa.getFullYear(), dataPascoa.getMonth(), dataPascoa.getDate() + 60); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment