-
-
Notifications
You must be signed in to change notification settings - Fork 156
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
Changes from all commits
5cf63fa
3e20587
6bf7063
c58d35f
078c802
dc22123
9c34b97
5e8d067
fa7effc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 | ||
* | ||
* 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)); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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)); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,4 +23,5 @@ | |
'nl_NL' => 'Eerste Paasdag', | ||
'pl_PL' => 'Wielkanoc', | ||
'sv_SE' => 'påskdagen', | ||
'pt_BR' => 'Páscoa' | ||
]; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,4 +30,5 @@ | |
'nl_NL' => 'Nieuwjaar', | ||
'pl_PL' => 'Nowy Rok', | ||
'sv_SE' => 'nyårsdagen', | ||
'pt_BR' => 'Ano novo' | ||
]; |
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); | ||
} | ||
} |
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'; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 ( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done! |
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', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
} | ||
} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done!