10424 : Time zones

Question

My application (a smart client) downloads data from a web service and displays it using GTP.NET. I’ve run into some difficulties regarding time zone. For example: if a business is using -7 (mountain standard time with DST) and someone connects to the web service using some other time zone setting in windows, all the times are messed up.

I was thinking about different approaches to dealing with this problem. Would it be possible to set an instance of a gantt to work off of a different time zone than the windows machine it is currently running on? The main thing I’m worried about is making daylight savings times correct in the gantt. Some users might not have their OS set to the “right” time zone for the data and it could cause a problem.

Answer

This can quickly become really nasty unless we make some clear definitions. I think i would do it this way: Store all date-data in the format of ONE defined TimeZone.

Lets say we choose UTC.

So when we get data from our DB we need to “convert” it to the User-time-zone; using the TimeZone.GetUtcOffset function will help us substract or add the correct value.

Later when we want to apply updates to the database we call the DateTime.ToUniversalTime method and store the result.

This way the user can have a setting that makes sense for him or her and we do not need to worry… If I were to use your app I would look at the Gantt in UTC+1 when planning my work at home and then switch to UTC-7 when planning what meetings I should attend to next time I’m in the US.

Leave a Reply