Nager.Date
Nager.Date copied to clipboard
IsPublicHoliday(DateTime date, CountryCode countryCode) result inconsistent with GetPublicHoliday(DateTime startDate, DateTime endDate, CountryCode countryCode)
Important specifications
- Which country is affected? DE
DateSystem.IsPublicHoliday(date: new DateTime(2020, 11, 18), CountryCode.DE) returns false
However:
DateSystem.GetPublicHoliday(startDate: new DateTime(2020, 11, 18), endDate: new DateTime(2020, 11, 19), CountryCode.DE) returns a list which includes the DateTime(2020, 11, 18).
Description
The two aforementioned methods return results which are inconsistent. From a quick Google search, it seems this is indeed a public holiday, so the second result seems to be correct, rather than the first.
It is only a holiday in a county not in the full country. https://github.com/nager/Nager.Date/blob/4ae81585754dc034b5685bfcedf0c19a4448c9d0/Src/Nager.Date/PublicHolidays/GermanyProvider.cs#L145
I realized that after some more research. Still, it seems somewhat misleading, considering (as far as I could find) there's no indication that the method only looks at national level holidays while the other returns holidays regardless of specificity, other than diving into the implementation. Appreciate the quick reply, though.
In the other method you must check this field https://github.com/nager/Nager.Date/blob/4ae81585754dc034b5685bfcedf0c19a4448c9d0/Src/Nager.Date/Model/PublicHoliday.cs#L37
What would your implementation for the problem look like?
After realizing this, we added a check on PublicHoliday.Global when using GetPublicHoliday(startDate,endDate,countryCode). I do understand the reason for the distinction, and don't think this is so much an implementation problem, more of a naming issue... What qualifies as a public holiday kind of changes from one to the other... Maybe the first should be named IsNationalPublicHoliday(...), which would be more suggestive of what it does, or more simply, update the description to note that only national holidays are considered. Not that this is a major issue, it's a bit of nitpicking.
Thank-you both, this thread helped me resolve an issue in here in the UK.
As Easter Monday, is a bank holiday in England, but not Scotland.
I adjusted our API calls to include the countyCode
.
if (DateSystem.IsPublicHoliday(value.UtcDateTime, _countryCode, "GB-ENG"))