«« Page Caching and Personalized Content Closing Discussion Threads »»
blog header image
Page Caching and Time Zones

Speaking of page caching on FanConcert another interesting problem with caching exists: dates!

Right now, FanConcert operates in GMT. That was fine because no one really noticed times that much. Now that discussion forums and blogs are in FanConcert, times are more obvious. It's becoming much more important to represent time properly, especially to the user's local time zone.

A user should be able to set a timezone in their preferences and all of the times they see on FanConcert should be shown in this time. This can be a problem if the forum pages are cached! Or is it? Maybe not...

What if all of FanConcert's cached pages had times stored in GMT and I took advantage of Javascript support on browsers to convert the GMT time to whatever time zone the user is in. Then I could insert the converted time into the page and all of the times would seem local to the user.

I'd like to do this on FanConcert ASAP. I wonder how much support Javascript has for time zones already? How well is it supported by the major browsers?

Posted at February 25, 2006 at 01:04 AM EST
Last updated February 25, 2006 at 01:04 AM EST
Comments

Depending on how you accomplish your caching, it may be possible to output times with a special tag around them, then, before they are sent out, search for the tags, and replace all the times as applicable.

» Posted by: Kibbee at February 25, 2006 02:51 PM

On the server side you mean? I was thinking of doing the same thing, just on the client side -- letting the browser replace the times with the converted local time.

As far as I understand it, Ruby on Rails will store the cached page as a file. I'm not 100% sure the cached page can't be modified before it is sent but if I had to guess I'd say that it can't be modified.

» Posted by: Ryan at February 25, 2006 02:56 PM

It might be too good to be true but I didn't seem to have any problems with this. Browsers come with a function called Date.UTC() which takes a UTC time which you can just put into the browser's date constructor:

localDate = new Date(Date.UTC(y,m,d,hr,mn));

When you output that date it's in the browser's local time.

I just output the UTC time from the server into the middle of some Javascript code that does document.write() to put the local date there. You can dig into FanConcert's Javascript if you're really interested.

» Posted by: Ryan at February 25, 2006 10:33 PM

yeah, I just have pissues using javascript implementations where I could do something server side. It's comes from the old days of doing Javascript for Netscape 4 vs. IE 4. There are still some times when Javascript is nice, but I always like to keep it to a minimum. It's a nice little JS hack you did, and probably the simplest way to fix the problem. But what about the half of the population who either have their time set incorrectly or just clicked continue when windows asked about their time zone, and therefore picked PST, event though they live in EST, or England.

» Posted by: Kibbee at February 26, 2006 09:53 PM
Google
 
Search scope: Web ryanlowe.ca