generated from spatie/package-skeleton-php
-
-
Notifications
You must be signed in to change notification settings - Fork 199
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 finland
- Loading branch information
Showing
20 changed files
with
218 additions
and
46 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 |
---|---|---|
@@ -1,9 +1,6 @@ | ||
name: Fix PHP code style issues | ||
|
||
on: | ||
push: | ||
paths: | ||
- '**.php' | ||
on: [push] | ||
|
||
permissions: | ||
contents: write | ||
|
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
name: PHPStan | ||
|
||
on: [push] | ||
on: [push, pull_request] | ||
|
||
jobs: | ||
phpstan: | ||
|
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
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
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,31 @@ | ||
<?php | ||
|
||
use Spatie\Holidays\Countries\Country; | ||
use Spatie\Holidays\Holidays; | ||
|
||
use function Laravel\Prompts\select; | ||
|
||
require __DIR__.'/vendor/autoload.php'; | ||
|
||
$countries = []; | ||
|
||
foreach (glob(__DIR__.'/src/Countries/*.php') as $filename) { // @phpstan-ignore-line | ||
$countryClass = '\\Spatie\\Holidays\\Countries\\'.basename($filename, '.php'); | ||
|
||
if (basename($filename) === 'Country.php') { | ||
continue; | ||
} | ||
|
||
$countries[$countryClass] = str_replace('\\Spatie\\Holidays\\Countries\\', '', $countryClass); | ||
} | ||
|
||
/** @var Country $class */ | ||
$class = select('Select a country', $countries); | ||
|
||
$result = collect(Holidays::for($class::make())->get()) | ||
->map(fn (array $holiday) => [ | ||
'name' => $holiday['name'], | ||
'date' => $holiday['date']->format('Y-m-d'), // @phpstan-ignore-line | ||
])->toArray(); | ||
|
||
dd($result); |
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
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
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,46 @@ | ||
<?php | ||
|
||
namespace Spatie\Holidays\Countries; | ||
|
||
use Carbon\CarbonImmutable; | ||
|
||
class Denmark extends Country | ||
{ | ||
public function countryCode(): string | ||
{ | ||
return 'da'; | ||
} | ||
|
||
protected function allHolidays(int $year): array | ||
{ | ||
return array_merge([ | ||
'Nytår' => '01-01', | ||
'Juleaften' => '12-24', | ||
'Juledag' => '12-25', | ||
'Anden Juledag' => '12-26', | ||
], $this->variableHolidays($year)); | ||
} | ||
|
||
/** @return array<string, CarbonImmutable> */ | ||
protected function variableHolidays(int $year): array | ||
{ | ||
$easter = CarbonImmutable::createFromTimestamp(easter_date($year)) | ||
->setTimezone('Europe/Copenhagen'); | ||
|
||
$holidays = [ | ||
'Påskedag' => $easter->addDay(), | ||
'Skærtorsdag' => $easter->subDays(3), | ||
'Langfredag' => $easter->subDays(2), | ||
'Anden Påskedag' => $easter->addDays(2), | ||
'Kristi Himmelfartsdag' => $easter->addDays(39), | ||
'Pinse' => $easter->addDays(49), | ||
'Anden Pinsedag' => $easter->addDays(50), | ||
]; | ||
|
||
if ($year < 2024) { | ||
$holidays['Store Bededag'] = $easter->addDays(26); | ||
} | ||
|
||
return $holidays; | ||
} | ||
} |
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
46 changes: 46 additions & 0 deletions
46
tests/.pest/snapshots/Countries/DenmarkTest/it_can_calculate_danish_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": "Nyt\u00e5r", | ||
"date": "2024-01-01" | ||
}, | ||
{ | ||
"name": "Sk\u00e6rtorsdag", | ||
"date": "2024-03-28" | ||
}, | ||
{ | ||
"name": "Langfredag", | ||
"date": "2024-03-29" | ||
}, | ||
{ | ||
"name": "P\u00e5skedag", | ||
"date": "2024-04-01" | ||
}, | ||
{ | ||
"name": "Anden P\u00e5skedag", | ||
"date": "2024-04-02" | ||
}, | ||
{ | ||
"name": "Kristi Himmelfartsdag", | ||
"date": "2024-05-09" | ||
}, | ||
{ | ||
"name": "Pinse", | ||
"date": "2024-05-19" | ||
}, | ||
{ | ||
"name": "Anden Pinsedag", | ||
"date": "2024-05-20" | ||
}, | ||
{ | ||
"name": "Juleaften", | ||
"date": "2024-12-24" | ||
}, | ||
{ | ||
"name": "Juledag", | ||
"date": "2024-12-25" | ||
}, | ||
{ | ||
"name": "Anden Juledag", | ||
"date": "2024-12-26" | ||
} | ||
] |
Oops, something went wrong.