generated from spatie/package-skeleton-php
-
-
Notifications
You must be signed in to change notification settings - Fork 198
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
38207cb
commit c74e36e
Showing
3 changed files
with
109 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
namespace Spatie\Holidays\Countries; | ||
|
||
use Carbon\CarbonImmutable; | ||
|
||
class Brazil extends Country | ||
{ | ||
public function countryCode(): string | ||
{ | ||
return 'br'; | ||
} | ||
|
||
/** @return array<string, CarbonImmutable> */ | ||
protected function allHolidays(int $year): array | ||
{ | ||
return array_merge([ | ||
'Dia de Ano Novo' => '01-01', | ||
'Dia de Tiradentes' => '04-21', | ||
'Dia do Trabalhador' => '05-01', | ||
'Independência do Brasil' => '09-07', | ||
'Nossa Senhora Aparecida' => '10-12', | ||
'Finados' => '11-02', | ||
'Proclamação da República' => '11-15', | ||
'Natal' => '12-25', | ||
], $this->variableHolidays($year)); | ||
} | ||
|
||
/** @return array<string, CarbonImmutable> */ | ||
protected function variableHolidays(int $year): array | ||
{ | ||
$easter = CarbonImmutable::createFromTimestamp(easter_date($year))->setTimezone('America/Sao_Paulo'); | ||
|
||
return [ | ||
'Páscoa' => $easter, | ||
'Carnaval' => $easter->subDays(47), | ||
'Sexta-feira Santa' => $easter->subDays(2), | ||
'Corpus Christi' => $easter->addDays(60), | ||
]; | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
tests/.pest/snapshots/Countries/BrazilTest/it_can_calculate_brazil_holidays.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
[ | ||
{ | ||
"name": "Dia de Ano Novo", | ||
"date": "2024-01-01" | ||
}, | ||
{ | ||
"name": "Carnaval", | ||
"date": "2024-02-13" | ||
}, | ||
{ | ||
"name": "Sexta-feira Santa", | ||
"date": "2024-03-29" | ||
}, | ||
{ | ||
"name": "P\u00e1scoa", | ||
"date": "2024-03-31" | ||
}, | ||
{ | ||
"name": "Dia de Tiradentes", | ||
"date": "2024-04-21" | ||
}, | ||
{ | ||
"name": "Dia do Trabalhador", | ||
"date": "2024-05-01" | ||
}, | ||
{ | ||
"name": "Corpus Christi", | ||
"date": "2024-05-30" | ||
}, | ||
{ | ||
"name": "Independ\u00eancia do Brasil", | ||
"date": "2024-09-07" | ||
}, | ||
{ | ||
"name": "Nossa Senhora Aparecida", | ||
"date": "2024-10-12" | ||
}, | ||
{ | ||
"name": "Finados", | ||
"date": "2024-11-02" | ||
}, | ||
{ | ||
"name": "Proclama\u00e7\u00e3o da Rep\u00fablica", | ||
"date": "2024-11-15" | ||
}, | ||
{ | ||
"name": "Natal", | ||
"date": "2024-12-25" | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
namespace Spatie\Holidays\Tests\Countries; | ||
|
||
use Carbon\CarbonImmutable; | ||
use Spatie\Holidays\Holidays; | ||
|
||
it('can calculate brazil holidays', function () { | ||
CarbonImmutable::setTestNowAndTimezone('2024-01-01'); | ||
|
||
$holidays = Holidays::for(country: 'br')->get(); | ||
|
||
expect($holidays) | ||
->toBeArray() | ||
->not()->toBeEmpty(); | ||
|
||
expect(formatDates($holidays))->toMatchSnapshot(); | ||
}); |