generated from spatie/package-skeleton-php
-
-
Notifications
You must be signed in to change notification settings - Fork 199
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
Adds support for Portuguese Holidays #9
Merged
Merged
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
9338f9c
Added portuguese holidays
lamelas 6cc425d
Merge pull request #1 from spatie/main
lamelas d84e49a
Use proper timezone
lamelas 60866d7
Merge branch 'main' of https://github.com/lamelas/holidays
lamelas 9541ffc
Fixes small typo
lamelas 7349343
Removing Carnaval as it is not an official holiday.
lamelas 4169d89
Merge branch 'spatie:main' into main
lamelas 6c73bc3
Fix for phpstan
lamelas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,44 @@ | ||
<?php | ||
|
||
namespace Spatie\Holidays\Countries; | ||
|
||
use Carbon\CarbonImmutable; | ||
|
||
class Portugal extends Country | ||
{ | ||
public function countryCode(): string | ||
{ | ||
return 'pt'; | ||
} | ||
|
||
/** @return array<string, CarbonImmutable> */ | ||
protected function allHolidays(int $year): array | ||
{ | ||
return array_merge([ | ||
'Dia de Ano Novo' => '01-01', | ||
'Dia da Liberdade' => '04-25', | ||
'Dia do Trabalhador' => '05-01', | ||
'Dia de Portugal' => '06-10', | ||
'Assunção da Nossa Senhora' => '08-15', | ||
'Implantação da República' => '10-05', | ||
'Dia de Todos os Santos' => '11-01', | ||
'Restauração da Independência' => '12-01', | ||
'Imaculada Conceição' => '12-08', | ||
'Natal' => '12-25' | ||
], $this->variableHolidays($year)); | ||
} | ||
|
||
/** @return array<string, CarbonImmutable> */ | ||
protected function variableHolidays(int $year): array | ||
{ | ||
$easter = CarbonImmutable::createFromTimestamp(easter_date($year)) | ||
->setTimezone('Europe/Lisbon'); | ||
|
||
return [ | ||
'Páscoa' => $easter, | ||
'Carnaval' => $easter->subDays(47), | ||
'Sexta-feira Santa' => $easter->subDays(2), | ||
'Corpo de Deus' => $easter->addDays(60), | ||
]; | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
tests/.pest/snapshots/Countries/PortugalTest/it_can_calculate_portuguese_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,58 @@ | ||
[ | ||
{ | ||
"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 da Liberdade", | ||
"date": "2024-04-25" | ||
}, | ||
{ | ||
"name": "Dia do Trabalhador", | ||
"date": "2024-05-01" | ||
}, | ||
{ | ||
"name": "Corpo de Deus", | ||
"date": "2024-05-30" | ||
}, | ||
{ | ||
"name": "Dia do Portugal", | ||
"date": "2024-06-10" | ||
}, | ||
{ | ||
"name": "Assun\u00e7\u00e3o da Nossa Senhora", | ||
"date": "2024-08-15" | ||
}, | ||
{ | ||
"name": "Implanta\u00e7\u00e3o da Rep\u00fablica", | ||
"date": "2024-10-05" | ||
}, | ||
{ | ||
"name": "Dia de Todos os Santos", | ||
"date": "2024-11-01" | ||
}, | ||
{ | ||
"name": "Restaura\u00e7\u00e3o da Independ\u00eancia", | ||
"date": "2024-12-01" | ||
}, | ||
{ | ||
"name": "Imaculada Concei\u00e7\u00e3o", | ||
"date": "2024-12-08" | ||
}, | ||
{ | ||
"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,19 @@ | ||
<?php | ||
|
||
namespace Spatie\Holidays\Tests\Countries; | ||
|
||
use Carbon\CarbonImmutable; | ||
use Spatie\Holidays\Holidays; | ||
|
||
it('can calculate portuguese holidays', function () { | ||
CarbonImmutable::setTestNowAndTimezone('2024-01-01'); | ||
|
||
$holidays = Holidays::for(country: 'pt')->get(); | ||
|
||
expect($holidays) | ||
->toBeArray() | ||
->not()->toBeEmpty(); | ||
|
||
expect(formatDates($holidays))->toMatchSnapshot(); | ||
|
||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Is this an official public holiday? It's not on the list here: https://publicholidays.pt/2024-dates/
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.
That’s a tricky one, actually. It is not an official mandatory holiday (hence not appearing on the list) but it is a facultative holiday so it appears on most work contracts and the government validates it every year as a holiday for civil servants. In practical terms it is a holiday since nobody works and everything is closed.
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.
Unfortunately like you said it’s not oficial, many companies ignore it.
It should be omitted from this list, in my opinion.
Good job with the PR 💪
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.
Fair enough. I'll remove it then.