September 10, 2011

PHP And The Aggravation Of Defined Weeks That Don't Follow The ISO-8601 Standard

The PHP logo displaying the Handel Gothic font.Image via Wikipedia
A few years ago I wrote some PHP code for entering data based on the results of a week defined by a well known U.S. government agency. Basically, it will detect what the current week number is and default the selected week number to the previous week number.

The annoying thing about this code is that I have to update it every year, because the defined week starts on a Sunday. The date function of PHP, however, follows the ISO-8601 standard, which considers Monday the start of a week. As a result, the defined week number does not match the ISO-8601 week number.

This becomes a real hassle when the calendar defined by the U.S. government agency has 53 weeks, but the ISO-8601 only has 52 weeks. Thankfully, I do not have to deal with it this year.

I suppose one way to deal with this would be to create my own date function that defines Sunday as the start of a week. That would be easy enough if being a programmer (or even a webmaster!) was a majority of my job. As such, trying to write such a thing for one application that only changes once a year will take up too much of my time.

Has anyone else dealt with this issue? Is there code out there somewhere that I could use?
Enhanced by Zemanta
Post a Comment