Skip to content

Commit

Permalink
Merge branch 'spatie:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
omakei authored Jan 18, 2024
2 parents 7976468 + d8cbb76 commit 89ce854
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ use Spatie\Holidays\Countries\Belgium;
$holidays = Holidays::for(Belgium::make())->get();
```

Alternatively, you could also pass an ISO code to the `for` method.
Alternatively, you could also pass an [ISO 3166-1](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2#Officially_assigned_code_elements) code to the `for` method.

```php
use Spatie\Holidays\Holidays;
Expand Down
40 changes: 40 additions & 0 deletions src/Countries/Italy.php
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(),
];
}
}
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"
}
]
18 changes: 18 additions & 0 deletions tests/Countries/ItalyTest.php
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();
});

0 comments on commit 89ce854

Please sign in to comment.