MenoData / Time4J

Advanced date, time and interval library for Java with sun/moon-astronomy and calendars like Chinese, Coptic, Ethiopian, French Republican, Hebrew, Hijri, Historic Christian, Indian National, Japanese, Julian, Korean, Minguo, Persian, Thai, Vietnamese
GNU Lesser General Public License v2.1
439 stars 64 forks source link

Support Hindu calendars (modern) #851

Closed MenoData closed 4 years ago

MenoData commented 5 years ago

Links:

Dershovitz/Reingold also offers a valuable source of algorithms.

SiddharthaAnand commented 5 years ago

Hi @MenoData I would like to start working on this if no one else is working on it?

MenoData commented 5 years ago

@SiddharthaAnand Thanks for feedback. Well, during the last months I had no time. But I think I will soon start working. Helpful contributions can be either on the level of internationalization, especially hindi scripts of month names and era names are highly welcome. The other field of work is the calendar algorithm itself, technically represented by an implementation of the interface CalendarSystem. As far as I have understood the Hindu calendar, there are several variants. The source of Dershovitz/Reingold describes several variants. So the idea to realize the Hindu calendar as an implementation of the interface CalendarVariant as member of a CalendarFamily is suggesting itself.

What would you like to contribute? Personally I would start with enums or primitives of Hindu months and eras as first brick stones including translations. Latter one (translations) are important and harder to realize because the CLDR repository of unicode consortium has NO resources for the Hindu calendar.

SiddharthaAnand commented 5 years ago

Hi @MenoData Thanks for the description. I would like to first go over how the other calendar systems have been implemented and then suggest how we can go about the hindu calendar implementation and how it can be done. Do you have any other sources to see how and what variants of calendars are there in hindi.

MenoData commented 5 years ago

I have now created the new branch "hindu" and implemented the most important eras according to the book Dershovitz/Reingold ("Calendrical calculations", 5th ultimate edition). Latter one is also my main source for the implementation of the calendrical algorithms. Those 6 eras I have now introduced also describe the different variations of hindu calendar. Currently I tend to identify about 6 variants with a preferred era (according to what I have specified in the commit). That is: Kali Yuga (for an ancient old Hindu calendar variant), Vikrama Samvat (Northern India), Saka (for the rest), Kollam (Malayalam calendar), Bengal (West Bengal) and Nepalese.

The Hindu months can be based on the already existing enum IndianMonth, but must be enhanced for representing leap forms (using the term "adhika" etc.). So I have to commit more on this area, although the text forms of the months are fortunately already there.

About the general structure of the algorithms: We need - per variant - a bijective mapping from the count of days since 1972-01-01 to a quintuple: [year, month, leap-month, day, leap-day]. A new primitive called HinduMonth can encapsulate the two parts "month" (as IndianMonth) and "leap-month" (as boolean flag). About the "day-of-month": This is complex as some days can happen twice (with the same number) or be left out (with a gap in the numbering). But the book of Dershovitz/Reingold should be sufficient to model it.

Furthermore, for example the Nepalese calendar variant is also available as table driven mapping (so useable for test purposes although the range of dates is pretty small). Maybe I can also find a table of test data for the Vikrama Samvat calendar.

MenoData commented 5 years ago

Forgotten to mention that every era is associated with a solar and a lunisolar calendar so we really talk about 12 variants. Although the solar calendars only need triple state (year, month, day without leaps) we can use quintuples where the leap-flags are always set to false. This design allows to unify both solar and lunisolar calendar systems in one class.

SiddharthaAnand commented 4 years ago

@MenoData Do you have the soft copy of the book by Dershovitz/Reingold. I want to through it before implementing any of the algorithms.

MenoData commented 4 years ago

@SiddharthaAnand There is no (legal) soft copy of the book by Dershovitz/Reingold, so I had to buy it. However, there is an older version of the part related to modern hindu calendar present in internet, namely:

http://www.cs.tau.ac.il/~nachum/calendar-book/papers/hindu-paper.pdf

Meanwhile (just now) I have started the implementation. Please have a look at the hindu branch and especially the class HinduVariant with the method getCalendarSystem() whose implementation is not yet there. IMHO the most simple implementation would be the solar and the standard amanta calendar for the old Hindu rule ARYA_SIDDHANTA (the old Hindu calendar in the book of Dershovitz/Reingold).

It is not easy to keep the overview of the confusing complexity of Hindu calendar family but I think I have found a reasonable way to structure the different variants, see the class mentioned above. As side note for possible enhancements: I can imagine to add an extra member to the class HinduVariant describing the location as reference for the astronomical calculations (usually it should be Ujjain) and another boolean member which asks for modern astronomical calculations instead of the old rules of Surya Siddhanta.

MenoData commented 4 years ago

Finally the algorithmic variants of modern Hindu calendars are implemented.