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.
* Adding Colombia Holidays Added the Colombia's holidays. There's a situation with some holidays due to the "Emiliany Law" they are moved to the following monday. * Adding Colombia Holidays Added the Colombia's holidays. There's a situation with some holidays due to the "Emiliany Law" they are moved to the following monday. * Update Colombia.php Deleted the line as suggested by @Nielsvanpach * Update Colombia.php * Added changes to Colombia.php and to the test file - Suggestions from @luisprmat were incorporated. - All the work of emiliani holiday generation was included into the emilianiHoliday method to achieve code readability - The order of the holidays was updated to ensure that the next emiliani holiday that appears can be included at the end of the list. - The test was updated because it's "colombian holidays" not "colombia holidays"
- Loading branch information
Showing
3 changed files
with
150 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,58 @@ | ||
<?php | ||
|
||
namespace Spatie\Holidays\Countries; | ||
|
||
use Carbon\CarbonImmutable; | ||
|
||
class Colombia extends Country | ||
{ | ||
public function countryCode(): string | ||
{ | ||
return 'co'; | ||
} | ||
|
||
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 = $this->easter($year); | ||
|
||
return [ | ||
'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), | ||
'Reyes Magos' => $this->emilianiHoliday($year, 1, 6), | ||
'Día de San José' => $this->emilianiHoliday($year, 3, 19), | ||
'San Pedro y San Pablo' => $this->emilianiHoliday($year, 6, 29), | ||
'Asunción de la Virgen' => $this->emilianiHoliday($year, 8, 15), | ||
'Día de la raza' => $this->emilianiHoliday($year, 10, 12), | ||
'Todos los santos' => $this->emilianiHoliday($year, 11, 1), | ||
'Independencia de Cartagena' => $this->emilianiHoliday($year, 11, 11), | ||
|
||
]; | ||
} | ||
|
||
/** @return CarbonImmutable */ | ||
private function emilianiHoliday(int $year, int $month, int $day): CarbonImmutable | ||
{ | ||
$dateObj = CarbonImmutable::createFromDate($year, $month, $day, 'America/Bogota')->startOfDay(); | ||
if ($dateObj->is('Monday')) { | ||
return $dateObj; | ||
} else { | ||
return $dateObj->next('Monday'); | ||
} | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
tests/.pest/snapshots/Countries/ColombiaTest/it_can_calculate_colombian_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,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" | ||
} | ||
] |
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 colombian holidays', function () { | ||
CarbonImmutable::setTestNowAndTimezone('2024-01-01'); | ||
|
||
$holidays = Holidays::for(country: 'co')->get(); | ||
|
||
expect($holidays) | ||
->toBeArray() | ||
->not()->toBeEmpty(); | ||
|
||
expect(formatDates($holidays))->toMatchSnapshot(); | ||
}); |