[Mono-dev] Time zone problems with DateTime.Parse (patch and bug)

Brion Vibber brion at pobox.com
Mon Sep 5 22:23:39 EDT 2005


I've been having some fun problems with time zones when reading
timestamps from strings using DateTime.ParseExact and its wrappers.
Behavior of both of these bugs seems consistent between current SVN on
Linux (Ubuntu Hoary) and 1.1.8 on Windows XP SP2, set for US Pacific
time. My test cases work correctly on .NET 1.1 on the XP box.


First, The DateTimeStyles.AdjustToUniversal flag is ignored for times
formatted like '2005-09-05T22:29:00Z', so the return value is in local
time even though you asked for universal.

Test case and patch for that:
http://bugzilla.ximian.com/show_bug.cgi?id=75995


Second, conversion to local time seems to handle daylight saving time
transitions incorrectly. Here in PDT/PST, in the autumn we transition
from UTC-7 to UTC-8 at 2am local time, but reading in UTC timestamps
with Mono's DateTime.Parse I find it switches at 2am *UTC*, several
hours earlier.

Test case:
http://bugzilla.ximian.com/show_bug.cgi?id=75985

I think the problem here is that the internal DateTime(bool,long)
constructor calls tz.GetUtcOffset(this) with the UTC time to get the
timezone offset before applying it to get local time, but that function
expects a local time to determine if DST is active. A bit of a
chicken-and-egg problem, perhaps... ;)

(It's not actually possible to determine if an unmarked local time is in
daylight saving time or not for all cases. During the autumn transition
an entire hour occurs twice in the local time sequence: once in DST and
again in standard time. The second hour will end up aliased to the first
if you try to do round-trip conversions without keeping the local
timezone with the time.)

-- brion vibber (brion @ pobox.com)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 253 bytes
Desc: OpenPGP digital signature
Url : http://lists.ximian.com/pipermail/mono-devel-list/attachments/20050905/c5fea9b5/attachment.bin 


More information about the Mono-devel-list mailing list