30 September 2009

AnyDatePicker

Part of my job involves maintaining a Web application which I wrote almost entirely from scratch. I designed the database, wrote pretty much all of the PHP and HTML, and even put my toe in the water of CSS. A colleague now supports part of the application, but v1.0 was more or less entirely my own work.

Unless, that is, you count the date picker. You know what I mean: the little window which opens on a travel site, say, so you can say when you want to leave and when you want to come back. When I was writing the application, I hadn't yet learned Javascript, so I scoured the Internet looking for a date picker that could do times as well as days, have the week start on a Monday, was multilingual, and free software.

Well, 2 out of 4 ain't bad. I found one which did the first two, scraped together just enough Javascript to allow me to send the day name abbreviations (M, T, W, etc) to it in different languages, and ignored the word 'Copyright' because, well, er, we're non-profit and nobody will find out.

That was nearly four years ago. In the meantime, I've found some things I don't like about it, apart from the fact that I would like our application to go open source and then somebody might just notice that I stole the code. It uses Javascript's date objects, so you can't ask people for their date of birth with it unless you're running a school, because Javascript's dates start at 1/1/1970. And it opens a new document window, which often turns into a tab these days, depending on how the user has set up their browser. So we get support calls: "I can't see the calendar" (as most users call it), and when we look, they've got 35 copies, each in its own tab, as a result of frantic clicking.

Anyway, about a month ago I was on a hotel's site and I noticed that the date picker appeared and disappeared in an instant. (It certainly wasn't the first one I've seen like that, but presumably I was in a receptive mood.) It occurred to me that it was running in a DIV rather than a window. I thought this was brilliant and decided to write my own, so that my application could be "pure" (and people wouldn't open 35 tabs trying to specify a date).

Remembering how much of a hassle it was to use the one which I stole (OK, OK, if you break into someone's house and steal their DVD recorder, you don't get the instruction book), I decided to make my date picker as flexible as possible, so that other people could use it without having to touch the code (although you do need to write a couple of Javascript data declarations yourself).

The result is called AnyDatePicker. I don't know what this means, except that it does let you pick any date in any year from 1582 (the start of the Gregorian calendar) through 9999. It also has a lot of ways to allow you to control exactly which dates and times people can choose; for example, it would be pretty good for a system where people book 15-minute appointments and you have different opening hours for Fridays, weekends, and holidays.

Please feel free to check it out.