I'm incensed that any web-application programmer would consider subjecting their end-users to a date-entry form which allows the entry of an invalid date, such as 'February 29, 2003', or 'April 31, 2003'. Forget about validating the date and having the user go back to correct his mistake - it's just plain poor practice to allow the wrong choice in the first place.
Some years ago, I had to code a date-entry web form element. I went hunting on the web. I wanted a selector for year, month, and date, with the proper number of days in a month, with leap years properly handled. I thought that this must be such a basic, common requirement that there would be dozens, perhaps hundreds of implementations to choose from.
Perhaps they are out there, but I haven't been able to find an existing solution, and apparently neither have my banks, or any of the dozens of elaborate, expensive, polished, and otherwise finely designed and crafted websites I visit that still subject me and millions of other users to this kind of bad UI design every day. Sigh.
So, here is what I came up with. I hope that this leap-year aware date-entry widget will find more common use out there.
You can shift-click here to download a sample page with the embedded JavaScript and form.
Comments
Update
yyyy(example, 1984) is a leap year ifyyyy is divisible by 4 unless yyyy is divisible by 100 unless yyyy is divisible by 400So, for example, 1994 is not divisible by 4, so it's not a leap year. 1984 is divisible by 4 (there's no remainder when you divide 1984 by 4). It's not divisible by 100, so 1984 is a leap year. 1900 is divisible by 4, and by 100, so it is not a leap year. 2000 is divisible by 4, 100, and 400, so it is a leap year.C'mon, folks. It's been 426 years since the Gregorian calendar first took effect. It's not hard... try to get it right!
Post new comment