Tuesday, September 21, 2010

WCF gotcha–DateTime

If your WCF service is going to be called across time-zone boundaries, then you need to make sure that you have a policy for handling date-time set by a client in a different time zone. (Process the dates as is, convert to local time before processing, or convert to UTC before processing are some strategies that you can use).

To unit test date time from different zones, use the DateTimeOffset struct.


DateTimeOffset doStart = new DateTimeOffset(2010, 10, 22, 0, 0, 0, new TimeSpan(-6, 0, 0)); //where –6 hours is the UTC offset for MST in the summer.

DateTime startDate = doStart.LocalDateTime; //use startdate in your unit test.

No comments: