AJAX WEB Methods and Daylight Saving Settings
As most of you know, although our computer displayed time moves forward
by an hour on DST period, It's time isn't changing actually, it just moves to
it's neighboring time zone.
This is in order not to change the computer UTC so different DST setting on different
countries won't cause actual time difference between computers.
However, many system administrators doesn't know how to configure correctly
the time zone shift and instead they simply setting the clock forward / backwards by
In an hours reporting system which I've developed I came across a side effect of the
phenomenon mentioned above. When reporting a working day hour one of my colleague
has discovered that his report was "shifted" one hour sooner. The cause of it was
combination of wrong DST settings on the customer's site along with right settings on
our company's site.
Well, In order to solve this problem we cannot change the customer's settings (It's a bank,
they cannot change something so fundamental so rapidly…) and we also can't (and won't)
change our company's settings to the wrong ones, what we can do is sending the client's
current date as a parameter so we can "fix" the dates being sent back to it, if needed.
What we basically need to do is send is the current date from our client.
For that meter we will simply call the new Date() function in our client side.
The server, from it's side, will receive it as a UTC date (you can check it by reading it's Kind
property on the server side or simply by checking the date itself while your client and server
are on the same computer.
Now, all you have to do is compare the date received with the server's UTC date and
correct the dates being sent back to the client if needed..
var hoursToAdd = clientDate.Subtract(DateTime.Now.ToUniversalTime()).Hours;
//Correct the hour "Gap"
The MoveHour method implementation simply "shift" all the dates sending
back to the client by the "gap" needed. I did not post the implementation
because it differs from one structure to another and it is very simple.
I know I could use the TimeSpan object itself (without it Hours property)
to correct the gap but this was an example for work around the DST
miss-configuration and I used the Hour property to make it clearer.
Note: This solution contains security risk. If you sent sensitive
data and you relay on time stamp, you
Moreover, if you're using your web service with another system
(not a browser to service like in AJAX) and you're
implementing WS security this solution is not enough.
To sum up: This solution can go where you have no other choice.
We use it simply because we cannot force large organizations to correctly
configure their DST settings. The date being sent from the client is the
client's machine current UTC time and therefore it is easy to compare
with the server's current UTC time. The rest is too easy to write about…