Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Dominican Republic holidays #57

Merged
merged 4 commits into from
Jan 20, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions src/Countries/DominicanRepublic.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace Spatie\Holidays\Countries;

use Carbon\CarbonImmutable;

class DominicanRepublic extends Country
{
public function countryCode(): string
{
return 'do';
}

/** @return array<string, CarbonImmutable | string> */
KiritoXD01 marked this conversation as resolved.
Show resolved Hide resolved
protected function allHolidays(int $year): array
{
return array_merge([
'Año Nuevo' => '01-01',
'Día de la Altagracia' => '01-21',
'Día de Duarte' => '01-26',
'Día de la Independencia' => '02-27',
'Día del Trabajo' => '05-01',
'Día de la Restauración' => '08-16',
'Día de las Mercedes' => '09-24',
'Día de la Constitución' => '11-06',
'Día de la Virgen de la Altagracia' => '12-08',
'Navidad' => '12-25',
], $this->variableHolidays($year));
}

/** @return array<string, CarbonImmutable> */
protected function variableHolidays(int $year): array
{
$easter = CarbonImmutable::createFromTimestamp(easter_date($year))
->setTimezone('America/Santo_Domingo');

return [
'Jueves Santo' => $easter->subDays(3),
'Viernes Santo' => $easter->subDays(2),
];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
[
{
"name": "A\u00f1o Nuevo",
"date": "2024-01-01"
},
{
"name": "D\u00eda de la Altagracia",
"date": "2024-01-21"
},
{
"name": "D\u00eda de Duarte",
"date": "2024-01-26"
},
{
"name": "D\u00eda de la Independencia",
"date": "2024-02-27"
},
{
"name": "Jueves Santo",
"date": "2024-03-28"
},
{
"name": "Viernes Santo",
"date": "2024-03-29"
},
{
"name": "D\u00eda del Trabajo",
"date": "2024-05-01"
},
{
"name": "D\u00eda de la Restauraci\u00f3n",
"date": "2024-08-16"
},
{
"name": "D\u00eda de las Mercedes",
"date": "2024-09-24"
},
{
"name": "D\u00eda de la Constituci\u00f3n",
"date": "2024-11-06"
},
{
"name": "D\u00eda de la Virgen de la Altagracia",
"date": "2024-12-08"
},
{
"name": "Navidad",
"date": "2024-12-25"
}
]
19 changes: 19 additions & 0 deletions tests/Countries/DominicanRepublicTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace Spatie\Holidays\Tests\Countries;

use Carbon\CarbonImmutable;
use Spatie\Holidays\Holidays;

it('can calculate dominican republic holidays', function () {
CarbonImmutable::setTestNowAndTimezone('2024-01-01');

$holidays = Holidays::for(country: 'do')->get();

expect($holidays)
->toBeArray()
->not()->toBeEmpty();

expect(formatDates($holidays))->toMatchSnapshot();
});