[Mono-list] Possible bug in ConvertTimeToUtc(DateTime, TimeZoneInfo)?
Kevin Reay
kevintreay at gmail.com
Tue Sep 9 01:15:13 EDT 2008
Hi,
I'll throw together a NUnit test tomorrow. Also, I have a tweaked
version of my original patch (a little cleaner, fixes some function
flow that doesn't effect the final outcome) that I'll send as well.
Thanks!
Kevin Reay
On Mon, Sep 8, 2008 at 11:08 PM, Atsushi Eno <atsushi at ximian.com> wrote:
> Hi,
>
> (I was reviewing old emails and found it left as is.)
>
> Thanks for the patch. Can you please add a NUnit test case as well?
> Then I'll check in the patch.
>
> Atsushi Eno
>
>
> KevinReay wrote:
>>
>> Ok, I tested the proposed changes locally (with changes/corrections) and
>> they
>> seem to work, at least for me.
>>
>> I've attached a (unified) diff for the changes I made, if anyone is
>> interested (also attached inline). Diff seems to solve problem described
>> above, and includes minor spelling/grammar tweak.
>>
>> Thanks, Kevin
>>
>> --- TimeZoneInfo.cs.old 2008-07-25 10:48:16.000000000 -0500
>> +++ TimeZoneInfo.cs 2008-07-25 10:53:07.000000000 -0500
>> @@ -222,10 +222,7 @@
>> throw new ArgumentNullException
>> ("sourceTimeZone");
>>
>> if (dateTime.Kind == DateTimeKind.Utc &&
>> sourceTimeZone != TimeZoneInfo.Utc)
>> - throw new ArgumentException ("Kind propery
>> of dateTime is Utc but the sourceTimeZone does not equal
>> TimeZoneInfo.Utc");
>> -
>> - if (dateTime.Kind == DateTimeKind.Local &&
>> sourceTimeZone != TimeZoneInfo.Local)
>> - throw new ArgumentException ("Kind propery
>> of dateTime is Local but the sourceTimeZone does not equal
>> TimeZoneInfo.Local");
>> + throw new ArgumentException ("dateTime
>> Kind
>> value is Utc but sourceTimeZone is not Utc");
>>
>> if (sourceTimeZone.IsInvalidTime (dateTime))
>> throw new ArgumentException ("dateTime
>> parameter is an invalid time");
>> @@ -236,7 +233,7 @@
>> if (dateTime.Kind == DateTimeKind.Utc)
>> return dateTime;
>>
>> - if (dateTime.Kind == DateTimeKind.Local)
>> + if (dateTime.Kind == DateTimeKind.Local &&
>> sourceTimeZone == TimeZoneInfo.Utc)
>> return ConvertTimeToUtc (dateTime);
>>
>> if (sourceTimeZone.IsAmbiguousTime (dateTime) ||
>> !sourceTimeZone.IsDaylightSavingTime (dateTime))
>>
>> http://www.nabble.com/file/p18658416/TimeZoneInfo.cs.diff
>> TimeZoneInfo.cs.diff
>>
>> KevinReay wrote:
>>>
>>> Hi everyone,
>>>
>>> I think I may have spotted a bug in the
>>> System.TimeZoneInfo.ConvertTimeToUtc(DateTime, TimeZoneInfo) method. I
>>> could, of course, be wrong (clue-stick appreciated!).
>>>
>>> The following check appears to be wrong:
>>>
>>> if (dateTime.Kind == DateTimeKind.Local && sourceTimeZone !=
>>> TimeZoneInfo.Local)
>>> throw new ArgumentException ("Kind propery of dateTime is Local
>>> but the
>>> sourceTimeZone does not equal TimeZoneInfo.Local");
>>>
>>> Shouldn't this code only check that if sourceTimeZone ==
>>> TimeZoneInfo.Utc,
>>> as the sourceTimeZone could be represent a local timezone while still not
>>> being equal to TimeZoneInfo.Local (The system's local timezone)?
>>>
>>> As an example, the following code runs as expected under .Net/Windows:
>>>
>>> TimeZoneInfo _SpecifiedTimezone =
>>> TimeZoneInfo.FindSystemTimeZoneById(SpecifiedTimeZone);
>>> _NewMeeting.DateBegin =
>>> TimeZoneInfo.ConvertTimeToUtc(DateTime.Parse(SpecifiedDate),
>>> _SpecifiedTimezone);
>>>
>>> But fails with the following exception when run under mono:
>>>
>>> "Kind propery of dateTime is Local but the sourceTimeZone does not equal
>>> TimeZoneInfo.Local"
>>>
>>> Thanks,
>>> Kevin
>>>
>>
>
>
More information about the Mono-list
mailing list