Warning: Parameter 1 to wp_default_scripts() expected to be a reference, value given in /home/public/blog/wp-includes/plugin.php on line 601
Home > WHATL > Gregorian-to-WHATL calendar conversion

Gregorian-to-WHATL calendar conversion

January 26th, 2008

So I tried to make a little program that would convert Gregorian dates to the equivalent WHATL dates.

The first version only used the current date; then I wrote one which would parse a date or a time_t value on the command line. After messing around with it, I eventually got it to work – and found that it gave wrong results in leap years.

Apparently, it was off by one. I had used code from Zefram’s Stardate program, and apparently that assumed that the epoch was 0001-01-01 rather than 0000-01-01.

What annoyed me, too, though was that it only worked during the time period where gmtime() and friends work – on my system, until early 2038.

And since WHATL years and Gregorian years are the same length nearly always (by a fortunate coincidence), you can simply convert from one to another by adding or subtracting four to the year and a certain bias to the date (which depends on the month and whether it’s a leap year or not, and varies between 6 and 9). So I wrote a second version which did that.

After a bit of playing around with that, I think it more or less works now. Pity that I can’t output month and day names in Greek, though (it’s a C command-line program and my command line is not Unicode-aware).

Perhaps I’ll write a Java program or something, though I’m not sure how to integrate it into Java’s existing i18n framework. Presumably a subclass of Calendar and one of DateFormatSymbols. But I don’t see any way to tell DateFormat to use a different calendar, and even SimpleDateFormat can only be passed separate DateFormatSymbols. Where does that leave people using different calendars? Somehow, I think that it’s only half-baked. Perhaps IBM’s ICU will be more amenable.

Or I could just forget about them and just write a little class of my own, which will not have as many features and may have a different interface, but does work with my dates.

Categories: WHATL Tags: ,
Comments are closed.