Any calendar nuts here? I've been looking for information on how to calculate the holidays of the current year that occur irregularly in the Gregorian Calendar. Typically this happens because the holiday is based on an older lunar calendar.
I've googled ad nauseum and made some progress but not able to finish. If anyone has sample code in a modern language that describes their calculation, I'd be very grateful. I'd prefer python or one of the C* languages.
My progress so far:
Complete:
- Easter: can be found with python-dateutil.
- Hanukkah, and other Hebrew calendar holidays can be found using holiday.py from python date_util*s* .
Close:
- Ramadan: date_utils has an islamic calendar function in a module, which I tried and get mostly correct, but not entirely accurate results. (It wants to convert everything to and from julian dates, I'm not sure why).
import calendar_util as cu # from date utils; no jokes from .br
#
# year = int(sys.argv1) or datetime.now().year
tj = cu.gregorian_to_jd(year, 1, 1) # this year in julian
ti = cu.jd_to_islamic(tj) # this year in islamic cal
rj = cu.islamic_to_jd(ti[0], 9, 1) # first day of ramadan in julian
#
print cu.jd_to_gregorian(rj) # first day of ramadan in greg
# output: (2011, 8, 1) # correct
I get results one-day-off in 2014, 2016, as confirmed by this site, although it mentions "North American sightings" a bit vague for my taste. Would appreciate pointers to increase accuracy, such as if Jan 1 hits some yearly cut off date. Islamic years are shorter and therefore arrive earlier every year.
Nada:
- Chinese New Year: I haven't found anything but this discussion where the answer is not revealed.
To SO's credit I've found a link to this book for $30, but would rather not pay and dig that much for a few lines of code. In the discussion on Amazon, it mentions that the routines are all in Emacs calendar. However I've never even installed Emacs, so if it is the only code available, hopefully someone can help me dig it out and simplify it to give me Ramadan/Chinese NY for the current year.
Not sure if it is useful here, but sun and moon events are available via pyephem, which I'm already using. Maybe it can be of use also.