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 Colombia Holidays #55

Merged
merged 10 commits into from
Jan 24, 2024
59 changes: 59 additions & 0 deletions src/Countries/Colombia.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

namespace Spatie\Holidays\Countries;

use Carbon\CarbonImmutable;

class Colombia extends Country
{
public function countryCode(): string
{
return 'co';
}

/** @return array<string, CarbonImmutable> */
alvleont 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 del Trabajo' => '05-01',
'Día de la independencia' => '07-20',
'Batalla de Boyacá' => '08-07',
'Inmaculada Concepción' => '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/Bogota');

return [
'Reyes Magos' => $this->emilianiHoliday(CarbonImmutable::createFromFormat('Y-m-d', $year . '-01-06')),
'Día de San José' => $this->emilianiHoliday(CarbonImmutable::createFromFormat('Y-m-d', $year . '-03-19')),
'San Pedro y San Pablo' => $this->emilianiHoliday(CarbonImmutable::createFromFormat('Y-m-d', $year . '-06-29')),
'Asunción de la Virgen' => $this->emilianiHoliday(CarbonImmutable::createFromFormat('Y-m-d', $year . '-08-15')),
'Día de la raza' => $this->emilianiHoliday(CarbonImmutable::createFromFormat('Y-m-d', $year . '-10-12')),
'Todos los santos' => $this->emilianiHoliday(CarbonImmutable::createFromFormat('Y-m-d', $year . '-11-01')),
'Independencia de Cartagena' => $this->emilianiHoliday(CarbonImmutable::createFromFormat('Y-m-d', $year . '-11-11')),
'Jueves Santo' => $easter->subDays(3),
'Viernes Santo' => $easter->subDays(2),
'Ascención de Jesús' => $easter->addDays(43),
'Corpus Christi' => $easter->addDays(64),
'Sagrado corazón de Jesús' => $easter->addDays(71),

];
}

/** @return CarbonImmutable */
private function emilianiHoliday(CarbonImmutable $date): CarbonImmutable
{
if ($date->is('Monday')) {
return $date;
} else {
return $date->next('Monday');
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
[
{
"name": "A\u00f1o Nuevo",
"date": "2024-01-01"
},
{
"name": "Reyes Magos",
"date": "2024-01-08"
},
{
"name": "D\u00eda de San Jos\u00e9",
"date": "2024-03-25"
},
{
"name": "Jueves Santo",
"date": "2024-03-28"
},
{
"name": "Viernes Santo",
"date": "2024-03-29"
},
{
"name": "D\u00eda del Trabajo",
"date": "2024-05-01"
},
{
"name": "Ascenci\u00f3n de Jes\u00fas",
"date": "2024-05-13"
},
{
"name": "Corpus Christi",
"date": "2024-06-03"
},
{
"name": "Sagrado coraz\u00f3n de Jes\u00fas",
"date": "2024-06-10"
},
{
"name": "San Pedro y San Pablo",
"date": "2024-07-01"
},
{
"name": "D\u00eda de la independencia",
"date": "2024-07-20"
},
{
"name": "Batalla de Boyac\u00e1",
"date": "2024-08-07"
},
{
"name": "Asunci\u00f3n de la Virgen",
"date": "2024-08-19"
},
{
"name": "D\u00eda de la raza",
"date": "2024-10-14"
},
{
"name": "Todos los santos",
"date": "2024-11-04"
},
{
"name": "Independencia de Cartagena",
"date": "2024-11-11"
},
{
"name": "Inmaculada Concepci\u00f3n",
"date": "2024-12-08"
},
{
"name": "Navidad",
"date": "2024-12-25"
}
]
18 changes: 18 additions & 0 deletions tests/Countries/ColombiaTest.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 colombia holidays', function () {
CarbonImmutable::setTestNowAndTimezone('2024-01-01');

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

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

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