Friday, January 25, 2008

The miscoloring problem caused by time zone difference

We got this miscoloring problem several days ago that for some specific dates, some stations are colored as red on some machines, but yellow on others.

The reason for this is relevant to the way we record the status change dates in javascript code. The dates were previously stored as a millisecond count of the local time since 1970-01-01-0:0:0:000.
Since it is only the date that matters to our application, the specific time of all dates are set to 12:0:0:000.
The initial dates are setup at the server side by analyzing the xml file containing status change information of all stations, so the time used is the local time of the machine where the web server is running. Then when a user chooses a date from the portal, a time according to the chosen date is generated with client side javascript and used for coloring the stations. The color of each station is decided by comparing this time with each stored time that has been initialized at the server side.
As a result, if the client and server have different time zone configuration, the two millisecond time counts for the same date will be different, and this will lead to miscoloring of the station.

To solve this problem, we just use standard UTC time for generating both the initialized status change time and the dynamic date time chosen by portal user. Moreover, since only the date matters, we use day count instead of milliseconds since 1970-01-01.

No comments: