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

Add Spanish Holidays #34

Merged
merged 9 commits into from
Feb 7, 2024
Merged

Add Spanish Holidays #34

merged 9 commits into from
Feb 7, 2024

Conversation

jaltez
Copy link
Contributor

@jaltez jaltez commented Jan 17, 2024

No description provided.

@markitosgv
Copy link

Hello, first thanks for the PR, but there are some things that need to be fixed:

  • In Spain, each autonomous community defines 4 days that do not have to coincide between them.
  • Each municipality also sets 2 days (this could be excluded from the scope of this library).

Then there is an issue and it is that national holidays do not always fall on the same days, sometimes the 1st of Jan if it falls on a Sunday is moved to the 2nd day or something like that.

How do you think this issue could be handled, or should there really be a PR each time the holidays for the following year are approved?

Thank you!

@jaltez
Copy link
Contributor Author

jaltez commented Jan 18, 2024

I think it is a problem that will occur in multiple locations, while the scope of the library only reaches countries and not country regions. I have only included national holidays that are common to all autonomous communities.

It would be necessary to be able to go down a level to filter by autonomous community or obtain all of them, indicating which community it belongs to (similar to the behavior of Google Calendar).

Regarding the free placement of holidays, perhaps it would be necessary to be able to specify it by year, and yes, update periodically after approval.

What do you think?

Thanks!

@Nielsvanpach
Copy link
Member

Could you rebase your branch on our main branch? That way I can run the tests

@jaltez
Copy link
Contributor Author

jaltez commented Jan 19, 2024

Done.

@Nielsvanpach
Copy link
Member

It seems like Spain has some additional holidays, based on the regions? We added some docs on how we think this could be implemented. Could you extend this PR with support? Thanks!

https://github.com/spatie/holidays?tab=readme-ov-file#contributing-a-new-country

@jaltez
Copy link
Contributor Author

jaltez commented Jan 19, 2024

Yes, I just saw it. I'll add them!

return $this->regionHolidays2024();
}

return [];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not familiar with the holidays in Spain, but isn't it possible to calculate the days instead of hardcoding them? This way we can have correct data for more years.

@jaltez
Copy link
Contributor Author

jaltez commented Jan 20, 2024

National, fixed and variable holidays are always the same.

Each autonomous community is free to assign additional holidays that are agreed upon before the beginning of each year. These holidays vary each year, for example, holidays are moved to Monday if they fall on a Sunday, or they are changed to another holiday if there is a long period of time without one.

The problem for these cases is that there are no fixed rules that allow it to be calculated either in the future or in the past, in addition to the fact that each community has different preferences. I think the only thing that can be done is to add some history from recent years, and since we cannot obtain future dates prospectively, add new ones as these are approved.

In my proposal I have tried to group and unify duplicate dates to add some clarity, but to consider regional cases I can't think of many alternatives.

@Nielsvanpach
Copy link
Member

If it's random every year, adding a bit of historical data seems fine to me.

src/Countries/Spain.php Outdated Show resolved Hide resolved
tests/Countries/SpainTest.php Outdated Show resolved Hide resolved
tests/Countries/SpainTest.php Outdated Show resolved Hide resolved
Copy link
Member

@Nielsvanpach Nielsvanpach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, thanks!


/** @return array<string, string> */
protected function regionHolidays(int $year): array
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$holidays = Holidays::for(Spain::make(year: 2020, region: 'es-an'))->get(); 

In this case I think we should throw an exception, as we won't be returning the region based holidays.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, and implement some direct way to also return national holidays, which are still valid, when there is no regional information for a specific year?

Copy link
Member

@Nielsvanpach Nielsvanpach Jan 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer an exception, as the user clearly expects region based holidays, which we cannot provide.

This can be a dedicated RuntimeException class, so it's easier to catch

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use InvalidYear::rang()

Copy link
Member

@Nielsvanpach Nielsvanpach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your work on this!

@Nielsvanpach Nielsvanpach merged commit 8ef9b96 into spatie:main Feb 7, 2024
7 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants