Skip to content

Commit

Permalink
Added changes to Colombia.php and to the test file
Browse files Browse the repository at this point in the history
- 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
alvleont committed Jan 23, 2024
1 parent 238bc0d commit ad5460c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
26 changes: 13 additions & 13 deletions src/Countries/Colombia.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,33 +26,33 @@ protected function allHolidays(int $year): array
/** @return array<string, CarbonImmutable> */
protected function variableHolidays(int $year): array
{
$easter = CarbonImmutable::createFromTimestamp(easter_date($year))
->setTimezone('America/Bogota');
$easter = $this->easter($year);

return [
'Reyes Magos' => $this->emilianiHoliday(CarbonImmutable::createFromFormat('Y-m-d', $year . '-01-06')->setTimezone('America/Bogota')),
'Día de San José' => $this->emilianiHoliday(CarbonImmutable::createFromFormat('Y-m-d', $year . '-03-20')->setTimezone('America/Bogota')),
'San Pedro y San Pablo' => $this->emilianiHoliday(CarbonImmutable::createFromFormat('Y-m-d', $year . '-06-29')->setTimezone('America/Bogota')),
'Asunción de la Virgen' => $this->emilianiHoliday(CarbonImmutable::createFromFormat('Y-m-d', $year . '-08-15')->setTimezone('America/Bogota')),
'Día de la raza' => $this->emilianiHoliday(CarbonImmutable::createFromFormat('Y-m-d', $year . '-10-12')->setTimezone('America/Bogota')),
'Todos los santos' => $this->emilianiHoliday(CarbonImmutable::createFromFormat('Y-m-d', $year . '-11-01')->setTimezone('America/Bogota')),
'Independencia de Cartagena' => $this->emilianiHoliday(CarbonImmutable::createFromFormat('Y-m-d', $year . '-11-11')->setTimezone('America/Bogota')),
'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(CarbonImmutable $date): CarbonImmutable
private function emilianiHoliday(int $year, int $month, int $day): CarbonImmutable
{
if ($date->is('Monday')) {
return $date;
$dateObj = CarbonImmutable::createFromDate($year, $month, $day, 'America/Bogota')->startOfDay();
if ($dateObj->is('Monday')) {
return $dateObj;
} else {
return $date->next('Monday');
return $dateObj->next('Monday');
}
}
}
2 changes: 1 addition & 1 deletion tests/Countries/ColombiaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Carbon\CarbonImmutable;
use Spatie\Holidays\Holidays;

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

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

0 comments on commit ad5460c

Please sign in to comment.