Managing Your TimeZone with TimeZone.cfc
Way back during my first professional, “on my own”, ColdFusion project, I was using ColdFusion 5.0. It was not too long after its release, and I found myself developing for users over multiple time zones. Not really something I had thought of before, I realized I was a bit stuck.
A day of reading newsgroups, best practices, and miscellaneous code snippets didn’t help much, but I did get to learn a ton about time zones. What I wound up doing was just building a profile for each of my users that included their time zone, and then using DateAdd to move the hours back and forth from what they were in my database. Daylight savings didn’t worry me much until I realized that DST varied not only in the US, but globally. Some locations didn’t use it at all, some locations offset was not in whole hour increments, and some cities in some places didn’t embrace it, while the rest of the country did. It grew into quite the large project. I’m sure there was a custom solution out there somewhere, but it wasn’t easy to find, and for what I needed time zones for, my solution worked.
Years later, the same application has gone through a few upgrades, and is now running on ColdFusion MX 7.x. The files I’ve used to manage time zones have upgraded over time, but are still a huge kluge.
Enter timeZone.cfc. This is not the horrific bundle of functions that I wrote for my original project, but instead a very well written CFC by Paul Hastings. Paul has done something, in my opinion, incredible with this one file. As the name implies, timeZone.cfc helps you manage time zones in your ColdFusion application. Instead of relying on databases or configuration files to manage time zone locations and offsets, Paul uses something only available with MX: Java. Letting Java remember all of that means that you no longer have to manage countries, time zones, DST, offsets, partial offsets, time zone names, etc. If something in the “real world” changes, just install the upgraded JVM on the server, and you know what everyone else knows.
The CFC came with a good set of instructions for the methods it exposes to you, all stored as a commented section within the CFC. Using this one CFC, you can now take any date and time, and without knowing anything about the source or destination time (except for the names), you can convert the time effortlessly. I urge anyone running ColdFusion MX and worried about globalization to seriously consider timeZone.cfc.
