Skip to content

Commit

Permalink
Merge pull request #169 from IvarsSaudinis/main
Browse files Browse the repository at this point in the history
Add latvian holidays
  • Loading branch information
Nielsvanpach authored Jan 24, 2024
2 parents 93bd4f6 + 0936074 commit 12131ff
Show file tree
Hide file tree
Showing 3 changed files with 139 additions and 0 deletions.
63 changes: 63 additions & 0 deletions src/Countries/Latvia.php
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;
}
}
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"
}
]
18 changes: 18 additions & 0 deletions tests/Countries/LatviaTest.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 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();
});

0 comments on commit 12131ff

Please sign in to comment.