ICU4J-based Implementation of the Persian Calendar

IBM's International Components for Unicode (Java version) or ICU4J enhances the I18n capabilities of Java in many ways. Since it is based on the Common Locale Data Repository (CLDR), it is especially useful for Persian-language applications (noting that the support for Persian is rudimentary in Java's native locales). But there is another important reason for using ICU4J for implementing a Persian calendar: The newer releases of ICU4J have reworked the calendar framework, so that, contrary to the Calendar class in the java.util package, much of the functionality has been embedded in the base class. For example, no longer should we worry about DST or weekdays. They are already worked out. The only thing one should implement is the peculiarities of the specific kind of calendar at hand -- here the Persian calendar.

The version 2.0 of my prersiancalendar Java program contains an implementation of the Persian calendar based on ICU4J, version 3.2. It formats and parses dates for many locales besides Persian.

A new update will be released in the near future, containing a bug fix for the SimplePersianCalendar class (which is, in fact, a deprecated class now) and some more locales for the ICU4J-based PersianCalendar class.

One important note is indispensable here: I have used an arithmetic algorithm for calculation of the leap years, which was apparently devised by the late Ahmad Birashk. Although this algorithm is valid for many hundreds of years, the formal definition of the Persian calendar is astronomical. To implement the calendar astronomically, we must be able to calculate the accurate time of the vernal equinox (the time when the solar longitude is 0). The current version of the class com.ibm.icu.impl.CalendarAstronomer is not very accurate, since it only considers the Keplerian gravitational effect of Sun and Earth and ignores the disturbances caused by other celestial bodies (of course there may be other things as well, but I am not particularly knowledgeable in astronomy). I used this class to calculate the time of the spring equinox in the next Persian year (1384) and it had a discrepancy with the magnitude order of many minutes with what has been announced by the Geophysics Institute of the Tehran University. Currently I am working on this.

I would like to thank Mr. Paul Hastings from Sustainable GIS Co. for his valuable suggestions and contributions. He has added the new Persian calendar to their calendar test bed. He has also promised to provide me with a Thai localization of the Persian month names, which will be a great enhancement to this program.

1 comment:

m said...

hi mr.kiani

you have powerful and

useful weblog....

i'm put link of your

weblog into wy weblog...