Java Calendar Conversions
The applet on this page does conversions between various calendar formats. Most (if not all) of the information and formulæ come from Calendrical Calculations by Nachum Dershowitz and Edward M. Reingold, ISBN 0-521-56474-3 (the same folks who brought you M-x calendar in emacs).
Enter the month, day, and year and select the calendar in the fields at the top and select the target calendar in the menu at the bottom, and the equivalent date in the selected calendar with appear in the middle. More calendars will (with luck) be added soon. When you change "input" calendars, the input date automatically converts to the new one (which I guess sort of makes having an input and an output calendar redundant, but that was the model I had in mind when I started).
Note that there is no bounds-checking. The applet will quite happily convert the 72nd day of the 18th month of 1990 (namely, to August 13, 1991). Internally, it never actually normalizes such things, except when converting or recomputing a date object (which is why it appears to normalize in the applet, since the output date is recomputed from the input date). This is to be considered a feature, not a bug. Now that you enter months from a menu and not by number, you can no longer ask for the 18th month, but the comment is still valid when you consider the Hebrew calendar. It is perfectly acceptable to request a date in Adar II of a non-leap year (in which such a month does not occur). It's simply the thirteenth month counting from the previous Nisan, namely the next Nisan (so choosing Adar II or Nisan would behave identically). This can be handy in finding, say, the day 1000 days after 8 September 1995: just ask for 1008 September 1995. For days that really make no sense to convert, like excised dates in Hindu calendars, an error is returned.
Please be gentle with this applet and its author. It and the calendar classes it uses represent the first significant programming I've ever done in Java, so it's still extremely rough-edged. I'm planning to allow entering a date in any of the calendars supported (currently I only have machinery for calendars that have a month/day/year format), and generally to soup up the look and feel of the applet; the GUI part is the bit I'm having the most trouble with and the least interest, so it got the short end of the stick. So don't bother telling me the layout is lousy; I already know. When I get better at this it'll be slicker, I hope.
*Sigh*. It's always the way, isn't it? I bust my chops to bend my brain around Java 1.1's event-handling and whatnot, figuring why should I learn the method that's on its way out, and then I find that it won't run under any browser I try since they all have Java 1.0. So it's back to the source-code, trying to figure out how it goes again. So, yes, I'm using Java 1.0 event-handling now, but hope to be up to 1.1 specs as soon as they're widely supported. At least this works.
I know Java supports Unicode and by rights I should/could have the names in their proper orthographies for the various languages (well, maybe not the Mayan ones; they're in Plane 1), but very few platforms support Unicode and until I or they work out how to make that OK I'm sticking with Latin letters and English month-names. I18n can wait. Accents on the French month-names should be safe, but I found that at least on machines I've used it causes problems when they're displayed (though the accents in "Bahá'í" in the menu seem to work OK), so I'm writing like a clueless Anglophone who's allergic to diacritics. Cope. Hope to get new calendars in soon. When I get all (or most) of the ones out of the book done, I'm open to requests for adding more classes. Anyone with a spiff calendar?
Meanwhile, enjoy the program, and please let me know what you think!
Page by Mark E. Shoulson, last modified January 18, 2006.
- September 24, 1997
- First version of page and applet put online.
- September 25, 1997
- Fixed the page so it actually worked, backfitting the applet to Java 1.0, and fixed a bug in the Julian Calendar.
- September 28, 1997 (wee hours)
- Hurray! Got Hebrew calendar support in finally! Interface
still lousy, though.
- Thanks so much for the comments and letters you've sent so far. If you haven't received a response from me, it's due to email-backlog; I'll get to you. Once I work out the interface well there should be a nice jump in features. See, I already can convert from any calendar to any other, not just from Gregorian. But the interface I have coded so far only supports one input style (because I wanted to get something quickly that worked). So figuring out how to convert from other calendars isn't a problem; it's just getting the input right. I have all sorts of ideas for the finished product, many of which are likely a bit too much; we'll have to see what works out. At this point I'm still considering radically restructuring the names of the classes and making a proper package of them, that's how early things are.
- September 28, 1997 (later on)
- Reworked the names of all the classes, including the applet itself. Restructured the classes, splitting up the large (and improperly-designed) source file and making a true Java package. Added support for input in calendars other than Gregorian (any month/day/year calendar). Next trick: inputting the months from a menu.
- September 30, 1997
- Added a new class definition, and some internal methods to the month/day/year type calendars, in order to enable the new feature: entering months by name (selected from a list) as opposed to typing in a number. Also redid part of the layout to use the confusing GridBagLayout, which at least gives me more control over the way the input fields are organized. To my surprise it worked.
- October 7, 1997
- Added the About the Calendars page to provide some extra info. Switched from M/D/Y to D/M/Y since I'm using month names anyway, though internally the order is still usually M/D/Y. Added new class to deal with rational numbers (let me know if you want a copy; it's useful outside of calendars) and the Old Hindu Solar calendar (which uses the rationals).
- January 14, 1998
- Finally got around to uploading the Old Hindu Lunar calendar, which I'd had working for quite a while. This also introduces the first error-checking, in that invalid Hindu dates (leap months that aren't leap, excised days) actually do raise exceptions. Part of the delay was in trying to figure out how to explain why these raise exceptions and 32 October doesn't. There's just a difference, OK? Also changed things so that when you ask for a "weird" date, the input fields update also. So when you ask for 32 January, the conversion works fine, and also the input fields change to 1 February. Still working on the Modern Hindu calendars; I discovered that the rational approximations used overflow long numerators and denominators by a lot, and I don't feel like writing an arbitrary-precision rational-number library just now. Maybe soon. Meanwhile I'm working on using doubles instead, but the day values seem to be just a mite off. Also fixed an error in the Ethiopic calendar, caused by a mistake in the date of the epoch in the book. Way to go, errata reports!
- March 8, 1998
- Uploaded a few changes, many of them minor fixes. Still can't get Modern Hindu calendars working, even with an arbitrary-precision rational library. The applet now starts off at the current date; that's probably the most noticeable change.
- March 31, 1999
- Moved from former location to http://web.meson.org/calendars/.
- Added, after much effort and pain, support for Modern Hindu Lunar and Solar calendars, as well as for the original French Revolutionary calendar. The Modern Hindu calendars were actually implemented as described in the book, using a hand-made arbitrary-precision rational-number class, and that was a pain by itself. When finally working, it worked great, except S-L-O-W-L-Y! Much too slowly to be shown here. The implementations here use normal double-precision calculation instead. If you want to see the others, let me know. No input support for the Modern Hindu Lunar calendar yet, since it requires a special field.
- April 6, 1999
- At long last, after gut-busting effort, added support for the Chinese calendar! Took lots of nitpicking to get it Just So, but near as I can tell it's finally right. This means I now have everything in the Dershowitz & Reingold book! No input routines for it just yet, since it has its own special format. I don't know much about how the date should look, though, so the output may look stilted to someone who knows what this should be like. Any suggestions would be nice. Another important change: widened the applet by a bit. Sorry, just needed the space... in order to add input support for the Modern Hindu Lunar calendar! Also did a little work that isn't yet visible, starting to plan how to include more powerful Unicode support, for those whose platforms can handle it. I envision a button you click to enable Unicode support, which will start showing month names in all their native glory. Not much done with that yet. Also started thinking about finally upgrading to Java 1.1, now that it's more accepted.
- August 12, 1999
- Added a counter. OK, not much of a change.
- January 16, 2006
- Reworked to conform to new website style—but didn't update anything else!!