⇥ Dates, Times and Derick
As you may know, php|a just published Derick Rethans’ new book, php|architect’s Guide to Date and Time Programming. If you allow me a small amount of self-promotion, this is a great book—and not just because my company happens to be the publisher.
Date and time programming is one of those topics that almost everybody tends to think they’re doing well and almost nobody does correctly. Thus, the most challenging aspect of selling this book is the fact that almost all those who could benefit from it—and that’s just about everybody—will tend to think that they don’t need it.
As an aside on why this book is so important, let me tell you this little story. Like most, we paid relatively little attention to our date programming—for the most part, it just worked, but only because all our servers are set to the same timezone, so that date and time values are all automatically synchronized.
When we installed PHP 5.2, however, our machines kept crashing. I have had occasion in the past to mention that out software is written with Nixon-level paranoia in mind, so all warnings and strict notices turned on and anything amiss is cause enough for our software to throw a 500 error and let us deal with the consequences by hand.
It turns out that, starting with 5.2, PHP was much more anal about the way it handles dates, so that it now spits out warnings like these:
Strict Standards: strtotime(): It is not safe to rely on the system’s timezone settings. Please use the date.timezone setting, the TZ environment variable or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected ‘America/New_York’ for ‘EDT/-4.0/DST’ instead.
As you can see, Derick and the rest of the PHP team have gone to great lengths to make sure that date and time manipulation are as accurate as they can be—and, as anyone who has ever tried writing date-management code knows, that’s not a simple task.
That’s why I think Derick’s book should be on every PHP developer’s reading list—because you, too, could end up with a line like this in your code:
// Here, Derick--happy?
date_default_timezone_set('America/Toronto');