Skip to content

Instantly share code, notes, and snippets.

@angelorocha
Last active March 28, 2023 14:43
Show Gist options
  • Save angelorocha/ec37d0a19212f2d306efa7981ad69f66 to your computer and use it in GitHub Desktop.
Save angelorocha/ec37d0a19212f2d306efa7981ad69f66 to your computer and use it in GitHub Desktop.
Brazilian holidays wordpress php class
<?php
/**
* Based on
* https://www.php.net/manual/pt_BR/function.easter-date.php#96686
*/
class BrazilHolidays {
/**
* Get date (unix format) of all holidays of the year
*
* @param int|null $year
*
* @return array
*/
public static function get( int $year = null ): array {
if ( is_null( $year ) ) {
$year = intval( current_time( 'Y' ) );
}
$easter = easter_date( $year );
$easter_day = (int) date( 'j', $easter );
$easter_month = (int) date( 'n', $easter );
$easter_year = (int) date( 'Y', $easter );
$holidays = [
/** Fixed holidays */
// Confraternização Universal
mktime( 0, 0, 0, 1, 1, $year ),
// Tiradentes
mktime( 0, 0, 0, 4, 21, $year ),
// Dia do Trabalhador
mktime( 0, 0, 0, 5, 1, $year ),
// Dia da Independência
mktime( 0, 0, 0, 9, 7, $year ),
// N. S. Aparecida
mktime( 0, 0, 0, 10, 12, $year ),
// Todos os santos
mktime( 0, 0, 0, 11, 2, $year ),
// Proclamação da república
mktime( 0, 0, 0, 11, 15, $year ),
// Natal
mktime( 0, 0, 0, 12, 25, $year ),
/** Holidays that depend on Easter */
//Segunda feria de carnaval
mktime( 0, 0, 0, $easter_month, $easter_day - 48, $easter_year ),
//Terça feria de carnaval
mktime( 0, 0, 0, $easter_month, $easter_day - 47, $easter_year ),
//Sexta feira santa
mktime( 0, 0, 0, $easter_month, $easter_day - 2, $easter_year ),
//Páscoa
mktime( 0, 0, 0, $easter_month, $easter_day, $easter_year ),
//Corpus Cristi
mktime( 0, 0, 0, $easter_month, $easter_day + 60, $easter_year ),
];
sort( $holidays );
return $holidays;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment