Mac OS X Custom Dates Gone Bad...

2004-05-07

Seems John Gruber over at Daring Fireball had a bizarre problem with his Energy Saver Prefs Panel that he traced to a custom date format setting. here is my own similar tale:

About a year ago I had a bizarre problem in iPhoto: Every time the date field for a photo would become the active field, eight hours would be subtracted from it when the field became inactive. For example: If I edited the name of the photo, then tabbed down into the comments field, passing through the date field, the date would loose eight hours. Even just clicking in the date field and choosing another photo (causing the date field for the old photo to become inactive) would loose eight hours.

Turns out the culprit was a custom date preference. I had set the short dates to look like 2004-04-07 (as a programmer, this style appeals to my sensibilities). The separator of '-' was the killer.

I even traced it down to the Cocoa routine that handles user input conversion to dates: While it correctly used the user preference of '-' to separate the year, month and date, the time portion of the code takes the first minus sign as the start of the time zone, then sees something like "-04-07", decides it is an invalid time-zone, gives up and uses GMT as the time zone. Since my time zone is really eight hours earlier, the time looses eight hours as it is re-interpreted as GMT. Since the newly set value is immediately displayed in my time zone, I see an eight hour loss. Of course, every time this routine gets invoked, another eight hours goes.

The bug fix is that the conversion routine needs to look for time zones only after the parsed portion of the date-time string. I submitted a bug to Apple... but I wouldn't hold my breath.