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 pull request #169 from IvarsSaudinis/main
Add latvian holidays
- Loading branch information
Showing
3 changed files
with
139 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,63 @@ | ||
<?php | ||
|
||
namespace Spatie\Holidays\Countries; | ||
|
||
use Carbon\CarbonImmutable; | ||
|
||
class Latvia extends Country | ||
{ | ||
public function countryCode(): string | ||
{ | ||
return 'lv'; | ||
} | ||
|
||
protected function allHolidays(int $year): array | ||
{ | ||
return array_merge([ | ||
'Jaunais gads' => '01-01', | ||
'Darba svētki' => '05-01', | ||
'Latvijas Republikas Neatkarības deklarācijas pasludināšanas diena' => '05-04', | ||
'Līgo diena' => '06-23', | ||
'Jāņu diena' => '06-24', | ||
'Latvijas Republikas proklamēšanas diena' => '11-18', | ||
'Ziemassvētku vakars' => '12-24', | ||
'Pirmie Ziemassvētki' => '12-25', | ||
'Otrie Ziemassvētki' => '12-26', | ||
'Vecgada vakars' => '12-31', | ||
], $this->variableHolidays($year), $this->postponedHolidays($year)); | ||
} | ||
|
||
/** @return array<string, CarbonImmutable> */ | ||
protected function variableHolidays(int $year): array | ||
{ | ||
$easter = $this->easter($year); | ||
|
||
return [ | ||
'Lielā Piektdiena' => $easter->subDays(2), | ||
'Pirmās Lieldienas' => $easter, | ||
'Otrās Lieldienas' => $easter->addDay(), | ||
]; | ||
} | ||
|
||
/** @return array<string, string> */ | ||
protected function postponedHolidays(int $year): array | ||
{ | ||
// If the holidays - May 4 and November 18 - fall on a Saturday or Sunday, | ||
// the next working day is designated as a holiday. | ||
$holidays = []; | ||
|
||
$date = new CarbonImmutable(); | ||
|
||
$date = $date->setDate($year, 5, 4); | ||
if($date->isWeekend()) { | ||
$holidays['Pārceltā 4. maija brīvdiena'] = $date->nextWeekday()->format('m-d'); | ||
} | ||
|
||
$date = $date->setDate($year, 11, 18); | ||
if($date->isWeekend()) { | ||
$holidays['Pārceltā 18. novembra brīvdiena'] = $date->nextWeekday()->format('m-d'); | ||
} | ||
|
||
return $holidays; | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
tests/.pest/snapshots/Countries/LatviaTest/it_can_calculate_latvian_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": "Jaunais gads", | ||
"date": "2024-01-01" | ||
}, | ||
{ | ||
"name": "Liel\u0101 Piektdiena", | ||
"date": "2024-03-29" | ||
}, | ||
{ | ||
"name": "Pirm\u0101s Lieldienas", | ||
"date": "2024-03-31" | ||
}, | ||
{ | ||
"name": "Otr\u0101s Lieldienas", | ||
"date": "2024-04-01" | ||
}, | ||
{ | ||
"name": "Darba sv\u0113tki", | ||
"date": "2024-05-01" | ||
}, | ||
{ | ||
"name": "Latvijas Republikas Neatkar\u012bbas deklar\u0101cijas pasludin\u0101\u0161anas diena", | ||
"date": "2024-05-04" | ||
}, | ||
{ | ||
"name": "P\u0101rcelt\u0101 4. maija br\u012bvdiena", | ||
"date": "2024-05-06" | ||
}, | ||
{ | ||
"name": "L\u012bgo diena", | ||
"date": "2024-06-23" | ||
}, | ||
{ | ||
"name": "J\u0101\u0146u diena", | ||
"date": "2024-06-24" | ||
}, | ||
{ | ||
"name": "Latvijas Republikas proklam\u0113\u0161anas diena", | ||
"date": "2024-11-18" | ||
}, | ||
{ | ||
"name": "Ziemassv\u0113tku vakars", | ||
"date": "2024-12-24" | ||
}, | ||
{ | ||
"name": "Pirmie Ziemassv\u0113tki", | ||
"date": "2024-12-25" | ||
}, | ||
{ | ||
"name": "Otrie Ziemassv\u0113tki", | ||
"date": "2024-12-26" | ||
}, | ||
{ | ||
"name": "Vecgada vakars", | ||
"date": "2024-12-31" | ||
} | ||
] |
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 latvian holidays', function () { | ||
CarbonImmutable::setTestNowAndTimezone('2024-01-01', 'Europe/Riga'); | ||
|
||
$holidays = Holidays::for(country: 'lv')->get(); | ||
|
||
expect($holidays) | ||
->toBeArray() | ||
->not()->toBeEmpty(); | ||
|
||
expect(formatDates($holidays))->toMatchSnapshot(); | ||
}); |