Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Holiday Provider for Brazil #21

Merged
merged 9 commits into from
May 23, 2016
128 changes: 128 additions & 0 deletions src/Yasumi/Provider/Brazil.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
<?php
/**
* This file is part of the Yasumi package.
*
* Copyright (c) 2015 - 2016 AzuyaLabs
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @author Dorian Neto <doriansampaioneto@gmail.com>
*/

namespace Yasumi\Provider;

use DateInterval;
use DateTime;
use DateTimeZone;
use Yasumi\Holiday;

/**
* Provider for all holidays in the Brazil.
*/
class Brazil extends AbstractProvider
{

use CommonHolidays, ChristianHolidays;

/**
* Initialize holidays for the Brazil.
*/
public function initialize()
{
$this->timezone = 'America/Fortaleza';

// Add common holidays
$this->addHoliday($this->newYearsDay($this->year, $this->timezone, $this->locale));
$this->addHoliday($this->internationalWorkersDay($this->year, $this->timezone, $this->locale));

// Add Christian holidays
$this->addHoliday($this->christmasDay($this->year, $this->timezone, $this->locale));
$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));

/**
* Carnaval
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind providing English description for these holidays? :) Most of the users are English speaking and would not necessarily understand Brazilian Portuguese.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done!

*
* Carnaval is the biggest popular festival of country. The festival it happens during 4 days and the last day above
* the wednesday of ashes (initiation of lent).
*
* @link https://en.wikipedia.org/wiki/Brazilian_Carnival
*/
if ($this->year >= 1700) {
$this->addHoliday(new Holiday('carnavalDay', ['pt_BR' => 'Carnaval'],
$this->calculateEaster($this->year, $this->timezone)->sub(new DateInterval('P47D')),
$this->locale, Holiday::TYPE_OBSERVANCE));
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe Carnaval is an observed holiday, not an official/national (by law) holiday. If so, please add the appropriate parameter HOLIDAY::TYPE_OBSERVANCE to the addHoliday method.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done!


/**
* Tiradentes Day
*
* Tiradentes Day is a the Brazilian national holidays. Is the a tribute to national Brazilian hero Joaquim José
* da Silva Xavier, martyr of Inconfidência Mineira. Is celebrated on 21 Abril, because the execution of
* Tiradentes got in the day, in 1792.
*
* @link https://en.wikipedia.org/wiki/Tiradentes
*/
if ($this->year >= 1792) {
$this->addHoliday(new Holiday('tiradentesDay', ['pt_BR' => 'Dia de Tiradentes'],
new DateTime("$this->year-04-21", new DateTimeZone($this->timezone)), $this->locale));
}

/**
* Independence Day
*
* The Homeland Day is a national holiday of Brazilian homeland celebrated on 7 September. The date is
* celebrated the independence declaration of Brazil to Portuguese empire on 7 September 1822.
*
* @link https://en.wikipedia.org/wiki/Independence_of_Brazil
*/
if ($this->year >= 1822) {
$this->addHoliday(new Holiday('independenceDay', ['pt_BR' => 'Dia da Independência do Brasil'],
new DateTime("$this->year-09-07", new DateTimeZone($this->timezone)), $this->locale));
}

/**
* Our Lady of Aparecida Day
*
* Our Lady of Conceição Aparecida, popularly called Our Lady Aparecida, Brazil's patroness. She is
* venerated in Catholic Church. Our Lady Aparecida is represented like a little image of Virgen Maria,
* currently in Basílica of Our Lady Aparecida, localized in São Paulo.
*
* The event is celebrated on 12 October, a national holiday in Brazil since 1980.
*
* @link https://en.wikipedia.org/wiki/Our_Lady_of_Aparecida
*/
if ($this->year >= 1980) {
$this->addHoliday(new Holiday('ourLadyOfAparecidaDay', ['pt_BR' => 'Dia de Nossa Senhora Aparecida'],
new DateTime("$this->year-10-12", new DateTimeZone($this->timezone)), $this->locale));
}

/**
* All Souls Day
*
* The All Souls day (known like Deads Day in Mexico), is celebrated for Catholic Church on 2 November.
*
* @link http://www.johninbrazil.org/all-souls-day-o-dia-dos-finados/
*/
if ($this->year >= 1300) {
$this->addHoliday(new Holiday('allSoulsDay', ['pt_BR' => 'Dia de Finados'],
new DateTime("$this->year-11-02", new DateTimeZone($this->timezone)), $this->locale));
}

/**
* Proclamation of Republic Day
*
* The Brazilian Proclamation of Republic was an act relevant military politic it happened on 15 November 1889
* that initiated the build federative presidential of govern in Brazil, downed the monarchy constitutional
* parlamentary of Brazil's Empire.
*
* @link https://en.wikipedia.org/wiki/Proclamation_of_the_Republic_(Brazil)
*/
if ($this->year >= 1889) {
$this->addHoliday(new Holiday('proclamationOfRepublicDay', ['pt_BR' => 'Dia da Proclamação da República'],
new DateTime("$this->year-11-15", new DateTimeZone($this->timezone)), $this->locale));
}
}
}
1 change: 1 addition & 0 deletions src/Yasumi/data/translations/christmasDay.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@
'nl_NL' => 'Kerstmis',
'pl_PL' => 'pierwszy dzień Bożego Narodzenia',
'sv_SE' => 'juldagen',
'pt_BR' => 'Natal'
];
3 changes: 2 additions & 1 deletion src/Yasumi/data/translations/corpusChristi.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
return [
'de_DE' => 'Fronleichnam',
'en_US' => 'Corpus Christi',
'pt_BR' => 'Corpus Christi',
'es_ES' => 'Corpus Christi',
'pl_PL' => 'Boże Ciało',
'pl_PL' => 'Boże Ciało'
];
1 change: 1 addition & 0 deletions src/Yasumi/data/translations/easter.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@
'nl_NL' => 'Eerste Paasdag',
'pl_PL' => 'Wielkanoc',
'sv_SE' => 'påskdagen',
'pt_BR' => 'Páscoa'
];
1 change: 1 addition & 0 deletions src/Yasumi/data/translations/goodFriday.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@
'nl_NL' => 'Goede Vrijdag',
'pl_PL' => 'Wielki Piątek',
'sv_SE' => 'långfredagen',
'pt_BR' => 'Sexta feira santa'
];
1 change: 1 addition & 0 deletions src/Yasumi/data/translations/internationalWorkersDay.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@
'nl_NL' => 'Dag van de arbeid',
'pl_PL' => 'Święto Pracy',
'sv_SE' => 'Första maj',
'pt_BR' => 'Dia internacional do trabalhador'
];
1 change: 1 addition & 0 deletions src/Yasumi/data/translations/newYearsDay.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@
'nl_NL' => 'Nieuwjaar',
'pl_PL' => 'Nowy Rok',
'sv_SE' => 'nyårsdagen',
'pt_BR' => 'Ano novo'
];
72 changes: 72 additions & 0 deletions tests/Brazil/AllSoulsDayTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php
/**
* This file is part of the Yasumi package.
*
* Copyright (c) 2015 - 2016 AzuyaLabs
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @author Dorian Neto <doriansampaioneto@gmail.com>
*/

namespace Yasumi\tests\Brazil;

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

/**
* Class for testing Dia dos Finados in the Brazil.
*/
class AllSoulsDayTest extends BrazilBaseTestCase implements YasumiTestCaseInterface
{
/**
* The name of the holiday
*/
const HOLIDAY = 'allSoulsDay';

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

/**
* Tests Dia dos Finados on or after 1300.
*/
public function testDiaDosFinadosAfter1300()
{
$year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR);
$this->assertHoliday(self::REGION, self::HOLIDAY, $year,
new DateTime("$year-11-02", new DateTimeZone(self::TIMEZONE)));
}

/**
* Tests Dia dos Finados on or before 1300.
*/
public function testDiaDosFinadosBefore1300()
{
$year = $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR-1);
$this->assertNotHoliday(self::REGION, self::HOLIDAY, $year,
new DateTime("$year-11-02", new DateTimeZone(self::TIMEZONE)));
}

/**
* 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 => 'Dia de Finados']);
}

/**
* 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_NATIONAL);
}
}
39 changes: 39 additions & 0 deletions tests/Brazil/BrazilBaseTestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php
/**
* This file is part of the Yasumi package.
*
* Copyright (c) 2015 - 2016 AzuyaLabs
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @author Dorian Neto <doriansampaioneto@gmail.com>
*/

namespace Yasumi\tests\Brazil;

use PHPUnit_Framework_TestCase;
use Yasumi\tests\YasumiBase;

/**
* Class BrazilBaseTestCase.
*/
abstract class BrazilBaseTestCase extends PHPUnit_Framework_TestCase
{
use YasumiBase;

/**
* Country (name) to be tested
*/
const REGION = 'Brazil';

/**
* Timezone in which this provider has holidays defined
*/
const TIMEZONE = 'America/Fortaleza';

/**
* Locale that is considered common for this provider
*/
const LOCALE = 'pt_BR';
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a constant for the common locale in Brazil. See for example the other test classes ( const LOCALE = 'nl_NL';)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done!

88 changes: 88 additions & 0 deletions tests/Brazil/BrazilTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?php
/**
* This file is part of the Yasumi package.
*
* Copyright (c) 2015 - 2016 AzuyaLabs
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @author Dorian Neto <doriansampaioneto@gmail.com>
*/

namespace Yasumi\tests\Brazil;

use Yasumi\Holiday;

/**
* Class for testing holidays in the Brazil.
*/
class BrazilTest extends BrazilBaseTestCase
{
/**
* @var int year random year number used for all tests in this Test Case
*/
protected $year;

/**
* Tests if all national holidays in the Brazil are defined by the provider class
*/
public function testNationalHolidays()
{
$this->assertDefinedHolidays([
'newYearsDay',
'goodFriday',
'tiradentesDay',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The holiday is in the correct array.

'internationalWorkersDay',
'independenceDay',
'ourLadyOfAparecidaDay',
'allSoulsDay',
'proclamationOfRepublicDay',
'christmasDay'
], self::REGION, $this->year, Holiday::TYPE_NATIONAL);
}

/**
* Tests if all observed holidays in the Brazil are defined by the provider class
*/
public function testObservedHolidays()
{
$this->assertDefinedHolidays([
'carnavalDay',
'easter',
'corpusChristi'
], self::REGION, $this->year, Holiday::TYPE_OBSERVANCE);
}

/**
* Tests if all seasonal holidays in the Brazil are defined by the provider class
*/
public function testSeasonalHolidays()
{
$this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_SEASON);
}

/**
* Tests if all bank holidays in the Brazil are defined by the provider class
*/
public function testBankHolidays()
{
$this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_BANK);
}

/**
* Tests if all other holidays in the Brazil are defined by the provider class
*/
public function testOtherHolidays()
{
$this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_OTHER);
}

/**
* Initial setup of this Test Case
*/
protected function setUp()
{
$this->year = $this->generateRandomYear(1300);
}
}
Loading