joaomatossilva / DateTimeExtensions

This project is a merge of several common DateTime operations on the form of extensions to System.DateTime, including natural date difference text (precise and human rounded), holidays and working days calculations on several culture locales.
http://datetimeextensions.azurewebsites.net/
Other
724 stars 303 forks source link

IndianHolidays #146

Open AnirudhG07 opened 7 months ago

AnirudhG07 commented 7 months ago

As mentioned in PR #145 (now closed) I would like some help to add Indian Holidays into this extensions. As mentioned the indian Holiday system works on Hindu Calender which means, the dates vary every year except important Government Holidays which are fixed.
If this is a system I can add the Hindu Calendar Holidays (all Indian Holidays), please share with me @joaomatossilva and also some code to use for reference, with guidelines.
It would be great if we could add an Extension for holidays which vary every year, like in India, and i am sure many Asian countries will have similar systems for some of their holidays.

joaomatossilva commented 7 months ago

You can see already on the Chinese strategy that it's using a non-gregorian calendar. The library uses the concept of Day and Months but always associated to a Calendar. This means that if exists an Hindu Calendar it is possible to represent an holiday

AnirudhG07 commented 7 months ago

Yes I saw the Chinese one. I will see how I can use it. Thank you.

joaomatossilva commented 7 months ago

is it the most approximate calendar this one? https://learn.microsoft.com/en-us/dotnet/api/system.globalization.eastasianlunisolarcalendar?view=net-8.0

AnirudhG07 commented 7 months ago

Yes actually. Even Chinese is also I think lunisolar. It is similar. it is dependant on moon and astronomical object positioning. So I think only the event dates are different rest are similar.

AnirudhG07 commented 7 months ago

I want to ask, do you change the dates for every year? I am asking this because the Chinese code which I had checked had dates back of yr 2016 ish. or it is automated?

joaomatossilva commented 7 months ago

It's automated. The idea is to write the formula that calculates an holiday for any given year. If the days are chosen by the government on a year basis, it's not really ideal... but can be done.

Just define a start year, (there is no much point on going much further back than previous year) and add each day with a lambda condition matching the year it applies.