Skip to content

Commit

Permalink
Merge pull request #38 from hanzi/brazil-easter-fix
Browse files Browse the repository at this point in the history
Calculate correct easter date in BR provider
  • Loading branch information
FlorianKoerner authored Oct 29, 2018
2 parents b6e3742 + b850336 commit 582adff
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
3 changes: 3 additions & 0 deletions src/Provider/AbstractEaster.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ protected function getEasterDates($year, $orthodox = false)
$saturday->modify('-1 days');
$ascensionDay = clone $easterSunday;
$ascensionDay->modify('+39 days');
$shroveTuesday = clone $easterSunday;
$shroveTuesday->modify('-47 days');


$pentecostSunday = clone $easterSunday;
Expand All @@ -78,6 +80,7 @@ protected function getEasterDates($year, $orthodox = false)
$corpusChristi->modify('+60 days');

return array(
'shroveTuesday' => $shroveTuesday,
'maundyThursday' => $maundyThursday,
'easterSunday' => $easterSunday,
'easterMonday' => $easterMonday,
Expand Down
19 changes: 5 additions & 14 deletions src/Provider/BR.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

namespace Checkdomain\Holiday\Provider;

use DateInterval;
use DateTime;
use DateTimeImmutable;

/**
* Brazilian Holiday Provider
Expand All @@ -13,7 +11,7 @@
* @see http://www.planalto.gov.br/ccivil_03/leis/l6802.htm
* @see https://pt.wikipedia.org/wiki/Feriados_no_Brasil
*/
class BR extends AbstractProvider
class BR extends AbstractEaster
{
const STATE_AC = 'Acre';
const STATE_AL = 'Alagoas';
Expand Down Expand Up @@ -48,8 +46,7 @@ class BR extends AbstractProvider
*/
public function getHolidaysByYear($year)
{
// Easter
$easter = DateTimeImmutable::createFromFormat('U', easter_date($year));
$easter = $this->getEasterDates($year);

$holidays = array(
// National Fixed
Expand All @@ -62,9 +59,9 @@ public function getHolidaysByYear($year)
'11-15' => $this->createData('Proclamação da República'),
'12-25' => $this->createData('Natal'),
// National Variable (and Optional)
$easter->sub(new DateInterval('P47D'))->format(self::DATE_FORMAT) => $this->createData('Carnaval'),
$easter->sub(new DateInterval('P2D'))->format(self::DATE_FORMAT) => $this->createData('Sexta-Feira Santa'),
$easter->add(new DateInterval('P60D'))->format(self::DATE_FORMAT) => $this->createData('Corpus Christi'),
$easter['shroveTuesday']->format(self::DATE_FORMAT) => $this->createData('Carnaval'),
$easter['goodFriday']->format(self::DATE_FORMAT) => $this->createData('Sexta-Feira Santa'),
$easter['corpusChristi']->format(self::DATE_FORMAT) => $this->createData('Corpus Christi'),
);

// Acre State
Expand Down Expand Up @@ -144,12 +141,6 @@ public function getHolidaysByYear($year)
// Rio de Janeiro State
$this->setHolidayForState($holidays, '04-23', self::STATE_RJ, 'São Jorge');
$this->setHolidayForState($holidays, '11-20', self::STATE_RJ, 'Dia da Consciência Negra');
$this->setHolidayForState(
$holidays,
$easter->sub(new DateInterval('P47D'))->format(self::DATE_FORMAT),
self::STATE_RJ,
'Carnaval'
);

// Rio Grande do Norte State
$this->setHolidayForState($holidays, '10-03', self::STATE_RN, 'Mártires de Cunhaú e Uruaçu');
Expand Down

0 comments on commit 582adff

Please sign in to comment.