Nager.Date icon indicating copy to clipboard operation
Nager.Date copied to clipboard

IsPublicHoliday(DateTime date, CountryCode countryCode) result inconsistent with GetPublicHoliday(DateTime startDate, DateTime endDate, CountryCode countryCode)

Open pmpontes opened this issue 4 years ago • 6 comments

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.

pmpontes avatar Nov 13 '20 11:11 pmpontes

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

tinohager avatar Nov 13 '20 13:11 tinohager

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.

pmpontes avatar Nov 13 '20 13:11 pmpontes

In the other method you must check this field https://github.com/nager/Nager.Date/blob/4ae81585754dc034b5685bfcedf0c19a4448c9d0/Src/Nager.Date/Model/PublicHoliday.cs#L37

tinohager avatar Nov 13 '20 13:11 tinohager

What would your implementation for the problem look like?

tinohager avatar Nov 13 '20 13:11 tinohager

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.

pmpontes avatar Nov 13 '20 13:11 pmpontes

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"))

uniquelau avatar Apr 02 '21 13:04 uniquelau