-
-
Notifications
You must be signed in to change notification settings - Fork 196
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
Conversation
Added the Colombia's holidays. There's a situation with some holidays due to the "Emiliany Law" they are moved to the following monday.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Could you rebase your branch on main, so I can run the tests here?
Added the Colombia's holidays. There's a situation with some holidays due to the "Emiliany Law" they are moved to the following monday.
Deleted the line as suggested by @Nielsvanpach
@Nielsvanpach Ok. I'm pretty sure I messed up something. |
No worries. Make sure your fork is in sync with this package: You could always try a new branch from main and make a new PR |
Done. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This implementation looks correct, I also tested it.
Could you verify if the dates are correct in the generated snapshot? At the moment the test is failing |
@Nielsvanpach The dates are correct and they make match with snapshot, the problem seems to be with the data types for private function emilianiHoliday(CarbonImmutable|bool $date = false) ?? |
I'm not aware of the situation in Colombia. I'll leave this PR open for other Colombians to discuss |
Ok, I did some extra reviews and it seems there was some problems with "Dia de San José" date, and also because all Emiliani dates timezone were not set. So @Nielsvanpach @luisprmat , I guess everything should work fine now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @alvleont, your change of 'March 19' to 'March 20' for "Día de san José" may work but it is not the right thing to do. Testing with your code I also found an error in 2026 with the day of the "Reyes magos"; in the snapshot it is obtained on "2026-01-05" but it should be "2026-01-12".
Reviewing I found the following problems for which I propose these solutions:
Problem 1 - The delays of one day in some cases are due to the creation of the dates on the GitHub actions test server, since if it is very close at midnight it is created for the next day and therefore it does not match the snapshot. Solution: After creating the date with CarbonImmutable
we chain the method ->startOfDay()
to reset the time to 00:00:00 so I no longer see the need to use timezone.
Problem 2 - The phpstan
analysis fails because the data type of the method CarbonImmutable::createFromFormat
returns an union type CarbonImmutable|false
but the emilianiHoliday
method expects a parameter with only CarbonImmutable
type. Solution: Use the method CarbonImmutable::createFromDate($year, $month, $day, $timezone?)
, this method returns only CarbonImmutable
and it does not generate problems with phpstan
.
CONCLUSION
This is my proposal for src/Countries/Colombia.php
<?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 [
'Reyes Magos' => $this->emilianiHoliday(CarbonImmutable::createFromDate($year, 1, 6)->startOfDay()),
'Día de San José' => $this->emilianiHoliday(CarbonImmutable::createFromDate($year, 3, 19)->startOfDay()),
'San Pedro y San Pablo' => $this->emilianiHoliday(CarbonImmutable::createFromDate($year, 6, 29)->startOfDay()),
'Asunción de la Virgen' => $this->emilianiHoliday(CarbonImmutable::createFromDate($year, 8, 15)->startOfDay()),
'Día de la raza' => $this->emilianiHoliday(CarbonImmutable::createFromDate($year, 10, 12)->startOfDay()),
'Todos los santos' => $this->emilianiHoliday(CarbonImmutable::createFromDate($year, 11, 1)->startOfDay()),
'Independencia de Cartagena' => $this->emilianiHoliday(CarbonImmutable::createFromDate($year, 11, 11)->startOfDay()),
'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');
}
}
}
I also suggest changing emilianiHoliday
to something more descriptive like movableHoliday
or something, but it's not as relevant.
- 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"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewing, I tested from 2016 to 2026 (in my PC, time for Colombia) and i didn't find errors. The code looks good and I think we should merge it, if an error arises later we will report it and we will resolve it.
@Nielsvanpach please review! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is perfect! Will withdraw mine
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Added the Colombia's holidays. There's a situation with some holidays due to the "Emiliany Law" they are moved to the following monday if it is not monday, so a function to deal with that was added.