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

Atsushi Eno atsushi at ximian.com
Tue Sep 6 03:06:00 EDT 2005


Hi,

Thanks for cool tests :)

Brion Vibber wrote:
> 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

Looks good. I'll commit your patch later when I converted the tests
to NUnit tests.

> 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... ;)

Agreed. But it seems possible to avoid that problem. Can you please
try attached patch? I don't have sane Unix environment and I'm
not in such region that has summer time ;-) It would be even nicer
if you try the entire corlib Nunit tests as well.

Atsushi Eno
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: 75985.patch
Url: http://lists.ximian.com/pipermail/mono-devel-list/attachments/20050906/fcac17ad/attachment.pl 


More information about the Mono-devel-list mailing list