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.
Merge branch 'spatie:main' into main
- Loading branch information
Showing
4 changed files
with
105 additions
and
1 deletion.
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
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,40 @@ | ||
<?php | ||
|
||
namespace Spatie\Holidays\Countries; | ||
|
||
use Carbon\CarbonImmutable; | ||
|
||
class Italy extends Country | ||
{ | ||
public function countryCode(): string | ||
{ | ||
return 'it'; | ||
} | ||
|
||
protected function allHolidays(int $year): array | ||
{ | ||
return array_merge([ | ||
'Capodanno' => '01-01', | ||
'Epifania' => '01-06', | ||
'Liberazione dal nazifascismo' => '04-25', | ||
'Festa del lavoro' => '05-01', | ||
'Festa della Repubblica' => '06-02', | ||
'Assunzione di Maria' => '08-15', | ||
'Ognissanti' => '11-01', | ||
'Immacolata Concezione' => '12-08', | ||
'Natale di Gesù' => '12-25', | ||
'Santo Stefano' => '12-26', | ||
], $this->variableHolidays($year)); | ||
} | ||
|
||
/** @return array<string, CarbonImmutable> */ | ||
protected function variableHolidays(int $year): array | ||
{ | ||
$easter = CarbonImmutable::createFromTimestamp(easter_date($year)) | ||
->setTimezone('Europe/Rome'); | ||
|
||
return [ | ||
'Lunedì di Pasqua' => $easter->addDay(), | ||
]; | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
tests/.pest/snapshots/Countries/ItalyTest/it_can_calculate_italian_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,46 @@ | ||
[ | ||
{ | ||
"name": "Capodanno", | ||
"date": "2024-01-01" | ||
}, | ||
{ | ||
"name": "Epifania", | ||
"date": "2024-01-06" | ||
}, | ||
{ | ||
"name": "Luned\u00ec di Pasqua", | ||
"date": "2024-04-01" | ||
}, | ||
{ | ||
"name": "Liberazione dal nazifascismo", | ||
"date": "2024-04-25" | ||
}, | ||
{ | ||
"name": "Festa del lavoro", | ||
"date": "2024-05-01" | ||
}, | ||
{ | ||
"name": "Festa della Repubblica", | ||
"date": "2024-06-02" | ||
}, | ||
{ | ||
"name": "Assunzione di Maria", | ||
"date": "2024-08-15" | ||
}, | ||
{ | ||
"name": "Ognissanti", | ||
"date": "2024-11-01" | ||
}, | ||
{ | ||
"name": "Immacolata Concezione", | ||
"date": "2024-12-08" | ||
}, | ||
{ | ||
"name": "Natale di Ges\u00f9", | ||
"date": "2024-12-25" | ||
}, | ||
{ | ||
"name": "Santo Stefano", | ||
"date": "2024-12-26" | ||
} | ||
] |
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 italian holidays', function () { | ||
CarbonImmutable::setTestNowAndTimezone('2024-01-01'); | ||
|
||
$holidays = Holidays::for(country: 'it')->get(); | ||
|
||
expect($holidays) | ||
->toBeArray() | ||
->not()->toBeEmpty(); | ||
|
||
expect(formatDates($holidays))->toMatchSnapshot(); | ||
}); |