martinjw / holiday Goto Github PK
View Code? Open in Web Editor NEWCalculate Public Holidays
License: MIT License
Calculate Public Holidays
License: MIT License
For the SouthAfricaPublicHoliday implementation, the rules in South Africa are slightly different in that only public holidays that fall on a Sunday are carried over to the following Monday. Public holidays that fall on a Saturday do not get observed on another day.
Could you add targets for .net standard 2.0 and/or 2.1 for the next release?
I had a .net standard 2.1 library using this package and on the solution using that library I got a lot of NU1605 detected package downgrade errors when publishing, because Holiday package was including old version of NETstandard.library to the build.
I have built the holiday package my self from the source in this repo targeting .net standard 2.1 (and only that, didn't want to install extra SDKs for other targets) and my solution publishes fine with it.
It looks like the name/localization ID argument was omitted from the Holiday
constructor in the Thanksgiving
, Christmas
, etc. static methods on USAFederalReserveHoliday
.
Introduced 8th March 2019, Berlin only. Fixed day (next 8 March 2020 is a weekend)
If Christmas day is on a Sunday (and therefore Boxing day on Monday) the observed date for Christmas day should be the Tuesday according to https://www.gov.uk/bank-holidays (see 2022), with Boxing day being observed on the Monday. This library puts Christmas day on the Monday and moves Boxing day to Tuesday.
I'm willing to create a PR with a fix for this if you'd like me to.
Hi there,
Firstly a great library, but I have a come across an issue while using your library:
Using **Australian Public Holiday** with state **NSW** and Year **2016**
Code
// Get the holidays based on state
var calendar = new AustraliaPublicHoliday { State = AustraliaPublicHoliday.States.NSW };
var result = calendar.PublicHolidayNames(2016);
**Exception: Message: "An item with the same key has already been added. Key: [26/12/2016 12:00:00 AM, Boxing Day]" **
'calendar.PublicHolidayNames(2016)' threw an exception of type 'System.ArgumentException'
Data: {System.Collections.ListDictionaryInternal}
HResult: -2147024809
HelpLink: null
InnerException: null
Message: "An item with the same key has already been added. Key: [26/12/2016 12:00:00 AM, Boxing Day]"
ParamName: null
Source: "System.Collections"
StackTrace: " at System.Collections.Generic.TreeSet`1.AddIfNotPresent(T item)\r\n at System.Collections.Generic.SortedDictionary`2.Add(TKey key, TValue value)\r\n at PublicHoliday.AustraliaPublicHoliday.PublicHolidayNames(Int32 year)"
TargetSite: {Boolean AddIfNotPresent(T)}
Even though this error shouldn't really be happening, as a first step I think it's important to ensure that the same item can't be added twice.
Example test.
[TestMethod]
public void TestTimeBetweenDatesRemovingHolidaysAndWeekends()
{
// Arrange
var start = new DateTime(2017, 12, 22, 12, 00, 00);
var end = new DateTime(2017, 12, 27, 12, 00, 00);
// Act
var result = new SwedenPublicHoliday().TimeBetweenDatesWithoutHolidaysAndWeekends(start, end);
// Assert
Assert.AreEqual(new TimeSpan(24, 0, 0), result);
}
I see that CanadaPublicHoliday takes an argument to determine Province, can there be something similar for American States? Some states don't observe some federal holidays, or observe them on different days than what is currently returned, not to mention all the state-only holidays. See Delaware not celebrating President's Day as an example.
When getting the PublicHolidayNames(2020) for Japan, this exception is thrown
An item with the same key has already been added. Key: 5/4/2020 12:00:00 AM
Reason:
ConstitutionMemorialDay(2020) is set to May 3 which is moved to May 4 because May 3 is a Sunday.
GreeneryDay(2020) is already set to May 4 which causes the exception to be thrown
Hi Martin,
The subject oh holidays is very interesting and depth.
In discovering the commenthol project I found the idea very interesting and I wanted to make a C# dll much more rigid and formal, because I am primarily a software developer. I use their data that I format according to my architecture.
I have already started to integrate several (55) countries, the work will be long and tedious.
You did a lot of work on your dll and congratulations!
If you want to take a moment to see, this is my project : https://github.com/Shaenn/ID3iHoliday
You will excuse me, but, I'm French, and the documentation is all in French... ;-)
Best regards Shaenn!
Liberation Day is not always a public holiday in all sectors in the Netherlands. For the most sectors itβs only a day off at Lustrum years (2020, 2025) since 2020. Would it be possible to add a configuration future / flag for this?
For 2020 the early May bank holiday has been moved to Friday 8 May 2020.
Hi there,
Just wondering if there is any consideration given to naming of King vs Queens birthday?
Hey, I have a minor issue, where I am building a feature in another public NuGet package that would optionally take IPublicHolidays
as parameter.
Right now I would have to reference the whole Holiday package, but I actually only need to reference IPublicHolidays
interface.
Would it be possible to move IPublicHolidays
to a separate NuGet like Holiday.Interfaces
or Holiday.Model
?
I assume the main NuGet package Holiday
would later depend on this newly created NuGet package.
In HolidayCalculator.cs the current code calculates the day and month and then assigns it to a new DateTime. It is a complex calculation for retrieving the day and month value while the DateTime stores it as a day counter
Current code:
var g = year % 19;
var c = year / 100;
var h = (c - c / 4 - (8 * c + 13) / 25 + 19 * g + 15) % 30;
var i = h - (h / 28) * (1 - (h / 28) * (29 / (h + 1)) * ((21 - g) / 11));
var j = (year + year / 4 + i + 2 - c + c / 4) % 7;
var p = i - j;
var easterDay = 1 + (p + 27 + (p + 6) / 40) % 31;
var easterMonth = 3 + (p + 26) / 30;
return new DateTime(year, easterMonth, easterDay);
Instead this code could be used and works (tested). The variable l is an offset value in days and can be applied directly to AddDays on DateOnly or DateTime
var century = year / 100;
var n = year % 19;
var h = (century - century / 4 - (8 * century + 13) / 25 + 19 * n + 15) % 30;
var i = h - h / 28 * (1 - h / 28 * (29 / (h + 1)) * ((21 - n) / 11));
var j = year + year / 4 + i + 2 - century + century / 4;
var l = i - j % 7;
return new DateTime(year, 3, 28).AddDays(l);
Hello there,
I was about to use your nice and useful lib and did some validation prior to that. I found a little bug:
The following code snippet will print the dates 30.5.2013 and 26.5.2016 (Corpus Christi), which should not happen:
var h = new AustriaPublicHoliday();
for (int year = 2010; year < 2018; year++)
{
var days = h.PublicHolidays(year);
var fd = days.Where(d => !h.IsPublicHoliday(d));
if (fd.Any())
Console.WriteLine(string.Join(Environment.NewLine, fd));
}
Wouldn't it be easier to use the PublicHolidays list to check against a single date in the IsPublicHolday method?
Best regards,
Oliver
Taken from here.
It should be the 1st of February if the 1st of February is a Friday.
I can make a PR to fix this if you want to.
π Hello everyone!
π We're gearing up for a fantastic Hacktoberfest event at my company this year! As part of our preparations, we're scouting for great open-source projects to contribute to, and we'd like to suggest that repositories participating in Hacktoberfest consider adding the "Hacktoberfest" label to make it easier for contributors to find relevant issues and pull requests. π·οΈ
By doing this, you not only encourage us but also many others in the open-source community to get involved in your project. Rest assured, we'll adhere to your project's guidelines and contribute meaningfully.
If your project has specific Hacktoberfest participation guidelines, kindly let us know, and we'll ensure our contributions align with your expectations.
Thanks for considering our request, and we look forward to contributing to your project during this exciting event! π
I was going to create a patch that add Swedish public holidays. However, it appears that I don't know much about how holidays and days off work in other countries. In Sweden we have two "classes" of holidays:
Since I will be using this library to query if a specific day is on or off work I would need a IsDayOffWork()
method rather then the IsPublicHoliday()
method.
Would it be ok to add this or perhaps the IsDayOffWork()
belongs in another library and this is only for public holidays?
Readme talks about IsBankHoliday()
method in IPublicHolidays
but it doesn't seem to exist in master? That's probably a more suited method for my case?
When getting the PublicHolidayNames(2023) for Turkey, this exception is thrown:
An item with the same key has already been added. Key: 4/23/2023 12:00:00 AM
Reason:
Because National Sovereignty and Children's Day coincides with the 3rd day of Ramadan Feast.
I would like to request Japan's holidays to be included if possible :-)
Is the Greek / Orthodox Easter holidays planned to be implemented? Are they covered otherwise?
Hi,
Thanks for this project. I noted that the package PublicHoliday is up to version 1.3.2.
Any chance you update it with last version 1.4 containing SpainPublicHolidays
?
Thanks
Is there any way to retrieve an IPublicHoliday
based on a culture code like en-US
?
Holiday.HolidayDate is returning ObservedDate and not the "Original" date. When checking all holidays that fall over weekends, Holiday.HolidayDate and Holiday.ObservedDate are always the same (i.e. they both return the observed date)
I'm using the new USAPublicHoliday().GetHolidaysInDateRange(startDate, endDate);
function to get the holidays based on our time frame, which isn't 1/1/xxxx - 12/31/xxxx, its more like 2/1 - 1/31.
It requires multiple calls to get the holiday names using new USAPublicHoliday().PublicHolidayNames(year);
because it has to run for two years and then do some filtering based on dates.
It would be nice if the name of the holiday was just included on the object returned from the GetHolidaysInDateRange()
call.
Great library and project!
From my understanding the following Public Holidays in Ireland does not move if there is a weekend.
MayDay in Ireland should be the First Monday in May. As of now IrelandPublicHoliday takes 1 May (with weekend fix).
All of the info above is taken from the link below.
https://www.citizensinformation.ie/en/employment/employment-rights-and-conditions/leave-and-holidays/public-holidays/#lc3a51
I can make a PR to fix this if you want to.
National Day for Truth and Reconciliation day is a new paid Federal holiday with the fixed date of September 30th from 2021 onwards.
Not all provinces are observing but federally regulated industries are regardless of province (similar to Remembrance Day). Although, many cities (city employees) in non-observing provinces are observing.
Hi there,
I just had a chance to try the library out with the new "king" support but I don't know if it's working
I seem to get only Queens Birthday as the name, am I doing something wrong?
Originally posted by @dotnetshadow in #84 (comment)
Hi Martin
We have a similar project you are interested on a collaboration?
Best regards
Tino
Error in Line: bHols.Add(Ascension(easter), "Christi Himmelfahrt"); -> An element with the same key has already been added.
In the Year 2008 is "Staatsfeiertag" and "Christi Himmelfahrt" on the same date 1.5.2008 !
I wonder how we could return the "English" name of the holiday. π€
For example a new method that would return a list with a date and a name
Hi,
Could you review the implemented rule for Liberation Day - Netherlands?
According with official dutch government and wikipedia sites, Liberation Day is celebrated every year since 1990, and every five years between 1945 and 1989:
Great Library
I was wondering how you would go about solving the following issue.
Given a date, if it's a working day return it, else return the next working day.
EDIT I just looked at the source code, it seems NextWorkingDay
should do exactly what I'm after.
I agree with the comment made here:
#5
Suggesting that an overload would be be needed to determine if we would like to include the current date in the check for NextWorkingDay
Last year a few german states added the reformation day as bank holiday. These should be added to the Array.
public bool HasReformation => Array.IndexOf(new[] { States.BB, States.MV, States.SN, States.ST, States.TH, States.HB, States.HH, States.NI, States.SH}, State) > -1;
Source: https://de.wikipedia.org/wiki/Gesetzliche_Feiertage_in_Deutschland
I've checked holidays for year 2022 and here are my findings:
June 5th (Pentecost)
November 16th (Repentance and prayer day)
September 20th (World's children day)
if (this.HasWorldChildrensDay(2019))
dateTimeList.Add(GermanPublicHoliday.WorldChildrensDay(2019));
July 17th (Easter Sunday)
Package version: v2.16.2
Tested method: IList PublicHolidays(int year)
just notice Anniversary days are missing in NZPublicHoliday. should we add them?
Hello!
I've recently been looking into using this package for determining bank closing days in Scandinavia, but noticed that Denmark is wrong.
Constitution Day and Labour Day are not public holidays in Denmark, but are days off as part of agreement between unions and employers - and very often mutually exclusive.
I would personally remove both days from the class, but this isn't backwards compatible, so I'd like to know how you'd like this change to be made, before I start implementing it (or if you'll do it yourself).
Thanks π
Hi
In SwitzerlandPublicHoliday.cs the names for WhitSunday and WhitMonday are missing an "f".
It should be
{WhitSunday(easter), "Pfingsten"},
{WhitMonday(easter), "Pfingstmontag"},
Could this be fixed please?
According to the news,
The B.C. government has announced that this year's Family Day will be the last time it falls on the second Monday of February.
Starting in 2019, the holiday will be on the third Monday of February, moving it in line with other provinces in Canada.
Link to the news: https://www.cbc.ca/news/canada/british-columbia/b-c-family-day-moving-one-week-later-starting-in-2019-1.4528735
In CanadaPublicHoliday.cs, we just need to add a simple validation to check if the input year is >= 2019 when province is 'BC'.
Thanks everyone for making this a great project!
When an observed day (i.e. holidays that are moved because they are on a weekend) is returned would it possible to return the original date as well?
Also, in some locations when a holiday falls on a weekend, it is moved to a weekday as an observed day. In some of these locations only the observed day is considered a holiday whereas in others both the observed and original days are considered holidays. This is an important distinction in some jurisdictions.
Is there any chance of supporting an additional flag against observed holidays that indicate the original day is or isn't a holiday?
var thanksgiving2018 = USAPublicHoliday.Thanksgiving(2018);
Assert.AreEqual(new DateTime(2018, 11, 22), thanksgiving2018, "Fourth Thursday of November");
Hi,
first of all thanks to your great library.
I have found two problems in german holiday recognition.
Apparently Easter Sunday and Whit Sunday are public holidays in Brandenburg (BB)
Each Sunday is a public holiday in Hessen (HE)
Think these extensions would be useful.
The reverse of the current booleans -
Get an individual holiday.
Currently there is GetHolidaysInDateRange
, i have a use case where im checking an individual date at a time, then add the holiday name to the record if there is a holiday.
Let me know what you think of the above, and if all good i'll look at doing a PR
Commonwealth countries including the UK, Australia, Canada and New Zealand have announced a one-off 'Day of Mourning' in recognition of the death of Queen Elizabeth II, either falling on the day of her funeral in the UK (19th September 2022) or a day shortly thereafter (22 Sep for Australia, 26 Sep for NZ).
Would it be worth submitting a PR to include these one-off public holidays to allow for users of the library to recognise that these dates are in fact public holidays, or because it's only a one-off in the very near future (and people might not update their libraries quick enough) is it not worth it?
Hi,
Could you support chinese holiday?
Thanks!
In Denmark, the day after ascension is considered a nonbank day.
So for financial dates this is considered a holiday.
Would like to add a fix so this can be configured.
The following piece of code causes an ArgumentException:
new NorwayPublicHoliday().PublicHolidays(2043);
It looks the implementations for Netherlands and Estonia are missing are they not supported anymore
A declarative, efficient, and flexible JavaScript library for building user interfaces.
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. πππ
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google β€οΈ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.