Skip to content

Commit

Permalink
Fixed Brazilian Carnaval Day, added Ash Wednesday to Brazilian Holida…
Browse files Browse the repository at this point in the history
…ys (#92)

* Fixed Brazilian Carnaval Day, added Ash Wednesday to Brazilian Holidays and added/modified related unit tests.
  • Loading branch information
glauberm authored and stelgenhof committed Feb 20, 2018
1 parent 7305bdf commit f61bf64
Show file tree
Hide file tree
Showing 6 changed files with 174 additions and 17 deletions.
25 changes: 19 additions & 6 deletions src/Yasumi/Provider/Brazil.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public function initialize()
$this->addHoliday($this->easter($this->year, $this->timezone, $this->locale, Holiday::TYPE_OBSERVANCE));
$this->addHoliday($this->corpusChristi($this->year, $this->timezone, $this->locale, Holiday::TYPE_OBSERVANCE));
$this->addHoliday($this->goodFriday($this->year, $this->timezone, $this->locale));
$this->addHoliday($this->ashWednesday($this->year, $this->timezone, $this->locale, Holiday::TYPE_OBSERVANCE));

/**
* Carnaval
Expand All @@ -60,13 +61,25 @@ public function initialize()
* @link https://en.wikipedia.org/wiki/Brazilian_Carnival
*/
if ($this->year >= 1700) {
$easter = $this->calculateEaster($this->year, $this->timezone);

$carnavalMonday = clone $easter;
$this->addHoliday(new Holiday(
'carnavalDay',
['pt_BR' => 'Carnaval'],
$this->calculateEaster($this->year, $this->timezone)->sub(new DateInterval('P51D')),
$this->locale,
Holiday::TYPE_OBSERVANCE
));
'carnavalMonday',
['pt_BR' => 'Segunda-feira de Carnaval'],
$carnavalMonday->sub(new DateInterval('P48D')),
$this->locale,
Holiday::TYPE_OBSERVANCE
));

$carnavalTuesday = clone $easter;
$this->addHoliday(new Holiday(
'carnavalTuesday',
['pt_BR' => 'Terça-feira de Carnaval'],
$carnavalTuesday->sub(new DateInterval('P47D')),
$this->locale,
Holiday::TYPE_OBSERVANCE
));
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/Yasumi/data/translations/ashWednesday.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@
'it_CH' => 'Mercoledi delle Ceneri',
'nl_BE' => 'Aswoensdag',
'nl_NL' => 'Aswoensdag',
'pt_BR' => 'Quarta-feira de Cinzas',
];
64 changes: 64 additions & 0 deletions tests/Brazil/AshWednesdayTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php
/**
* This file is part of the Yasumi package.
*
* Copyright (c) 2015 - 2018 AzuyaLabs
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @author Sacha Telgenhof <[email protected]>
*/

namespace Yasumi\tests\Brazil;

use DateTime;
use DateTimeZone;
use Yasumi\Holiday;
use Yasumi\tests\YasumiTestCaseInterface;

/**
* Class for testing Ash Wednesday in the Brazil.
*/
class AshWednesdayTest extends BrazilBaseTestCase implements YasumiTestCaseInterface
{
/**
* The name of the holiday
*/
const HOLIDAY = 'ashWednesday';

/**
* Tests the holiday defined in this test.
*/
public function testHoliday()
{
$year = 1999;
$this->assertHoliday(
self::REGION,
self::HOLIDAY,
$year,
new DateTime("$year-2-17", new DateTimeZone(self::TIMEZONE))
);
}

/**
* Tests translated name of Ash Wednesday.
*/
public function testTranslation()
{
$this->assertTranslatedHolidayName(
self::REGION,
self::HOLIDAY,
$this->generateRandomYear(),
[self::LOCALE => 'Quarta-feira de Cinzas']
);
}

/**
* Tests type of the holiday defined in this test.
*/
public function testHolidayType()
{
$this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OBSERVANCE);
}
}
6 changes: 4 additions & 2 deletions tests/Brazil/BrazilTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,11 @@ public function testOfficialHolidays()
public function testObservedHolidays()
{
$this->assertDefinedHolidays([
'carnavalDay',
'carnavalMonday',
'carnavalTuesday',
'easter',
'corpusChristi'
'corpusChristi',
'ashWednesday',
], self::REGION, $this->year, Holiday::TYPE_OBSERVANCE);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,40 +18,40 @@
use Yasumi\tests\YasumiTestCaseInterface;

/**
* Class for testing Carnaval in Brazil.
* Class for testing Carnaval Monday in Brazil.
*/
class CarnavalDayTest extends BrazilBaseTestCase implements YasumiTestCaseInterface
class CarnavalMondayTest extends BrazilBaseTestCase implements YasumiTestCaseInterface
{
use ChristianHolidays;

/**
* The name of the holiday
*/
const HOLIDAY = 'carnavalDay';
const HOLIDAY = 'carnavalMonday';

/**
* The year in which the holiday was first established
*/
const ESTABLISHMENT_YEAR = 1700;

/**
* Tests Carnaval on or after 1700.
* Tests Carnaval Monday on or after 1700.
*/
public function testCarnavalAfter1700()
public function testCarnavalMondayAfter1700()
{
$year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR);
$this->assertHoliday(
self::REGION,
self::HOLIDAY,
$year,
$this->calculateEaster($year, self::TIMEZONE)->sub(new DateInterval('P51D'))
$this->calculateEaster($year, self::TIMEZONE)->sub(new DateInterval('P48D'))
);
}

/**
* Tests Carnaval on or before 1700.
* Tests Carnaval Monday on or before 1700.
*/
public function testCarnavalBefore1700()
public function testCarnavalMondayBefore1700()
{
$year = $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1);
$this->assertNotHoliday(self::REGION, self::HOLIDAY, $year);
Expand All @@ -63,7 +63,7 @@ public function testCarnavalBefore1700()
public function testTranslation()
{
$year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR);
$this->assertTranslatedHolidayName(self::REGION, self::HOLIDAY, $year, [self::LOCALE => 'Carnaval']);
$this->assertTranslatedHolidayName(self::REGION, self::HOLIDAY, $year, [self::LOCALE => 'Segunda-feira de Carnaval']);
}

/**
Expand Down
77 changes: 77 additions & 0 deletions tests/Brazil/CarnavalTuesdayTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php
/**
* This file is part of the Yasumi package.
*
* Copyright (c) 2015 - 2018 AzuyaLabs
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @author Sacha Telgenhof <[email protected]>
*/

namespace Yasumi\tests\Brazil;

use DateInterval;
use Yasumi\Holiday;
use Yasumi\Provider\ChristianHolidays;
use Yasumi\tests\YasumiTestCaseInterface;

/**
* Class for testing Carnaval Tuesday in Brazil.
*/
class CarnavalTuesdayTest extends BrazilBaseTestCase implements YasumiTestCaseInterface
{
use ChristianHolidays;

/**
* The name of the holiday
*/
const HOLIDAY = 'carnavalTuesday';

/**
* The year in which the holiday was first established
*/
const ESTABLISHMENT_YEAR = 1700;

/**
* Tests Carnaval Tuesday on or after 1700.
*/
public function testCarnavalTuesdayAfter1700()
{
$year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR);
$this->assertHoliday(
self::REGION,
self::HOLIDAY,
$year,
$this->calculateEaster($year, self::TIMEZONE)->sub(new DateInterval('P47D'))
);
}

/**
* Tests Carnaval Tuesday on or before 1700.
*/
public function testCarnavalTuesdayBefore1700()
{
$year = $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1);
$this->assertNotHoliday(self::REGION, self::HOLIDAY, $year);
}

/**
* Tests the translated name of the holiday defined in this test.
*/
public function testTranslation()
{
$year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR);
$this->assertTranslatedHolidayName(self::REGION, self::HOLIDAY, $year, [self::LOCALE => 'Terça-feira de Carnaval']);
}

/**
* Tests type of the holiday defined in this test.
*/
public function testHolidayType()
{
$year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR);
$this->assertHolidayType(self::REGION, self::HOLIDAY, $year, Holiday::TYPE_OBSERVANCE);
}
}

0 comments on commit f61bf64

Please sign in to comment.