This is Xamarin's bug tracking system. For product support, please use the support links listed in your Xamarin Account.
Bug 33471 - onoTests.System.TimeZoneInfoTest+ConvertTimeTests.ConvertFromToLocal fails when machine is in UTC
Summary: onoTests.System.TimeZoneInfoTest+ConvertTimeTests.ConvertFromToLocal fails wh...
Status: RESOLVED FIXED
Alias: None
Product: Class Libraries
Classification: Mono
Component: System (show other bugs)
Version: Trunk
Hardware: PC Other
: --- normal
Target Milestone: ---
Assignee: marcos.henrich
URL:
Depends on:
Blocks:
 
Reported: 2015-08-28 12:49 UTC by Marcin Cieślak
Modified: 2015-09-16 02:06 UTC (History)
2 users (show)

See Also:
Tags:
Is this bug a regression?: ---
Last known good build:


Attachments

Description Marcin Cieślak 2015-08-28 12:49:12 UTC
9) MonoTests.System.TimeZoneInfoTest+ConvertTimeTests.ConvertFromToLoc
al :   Expected: Local
  But was:  Utc

at MonoTests.System.TimeZoneInfoTest+ConvertTimeTests.ConvertFromToLoc
al () [0x00029] in /home/saper/sw/mono/mcs/class/corlib/Test/System/Ti
meZoneInfoTest.cs:454
at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalIn
voke (System.Reflection.MonoMethod,object,object[],System.Exception&)
at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlag
s invokeAttr, System.Reflection.Binder binder, System.Object[] paramet
ers, System.Globalization.CultureInfo culture) [0x00038] in /home/sape
r/sw/mono/mcs/class/corlib/System.Reflection/MonoMethod.cs:295


after https://github.com/mono/mono/pull/1860 we now assume the machine
runs UTC if there is no $TZ set or /etc/localtime (this is my setup).

But the test above fails here:

                DateTime utc = DateTime.UtcNow;
                Assert.AreEqual(utc.Kind, DateTimeKind.Utc);
                DateTime converted = TimeZoneInfo.ConvertTimeFromUtc(utc, TimeZoneInfo.Local);
                Assert.AreEqual(DateTimeKind.Local, converted.Kind);

becase local time *is* UTC... should the DateTimeKind be different
or should we skip that test?
Comment 1 marcos.henrich 2015-09-14 11:14:59 UTC
Hi Marcin,

Thank you for the bug report.

The issue should be fixed by the following pull request:
https://github.com/mono/mono/pull/2052
Comment 2 marcos.henrich 2015-09-15 06:41:00 UTC
Fixed in master 99915fc6c339e35d3cec560e7e2774becea5c662.
https://github.com/mono/mono/commit/99915fc6c339e35d3cec560e7e2774becea5c662
Comment 3 Marcin Cieślak 2015-09-15 08:05:03 UTC
Those are my test failures right now:

6) MonoTests.System.TimeZoneInfoTest+ConvertTimeTests.ConvertFromToUtc_Utc :   Expected: Utc
  But was:  Local

at MonoTests.System.TimeZoneInfoTest+ConvertTimeTests.ConvertFromToUtc_Utc () [0x00029] in /home/saper/sw/mono/mcs/class/corlib/Test/System/TimeZoneInfoTest.cs:486
at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&)
at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00038] in /home/saper/sw/mono/mcs/class/corlib/System.Reflection/MonoMethod.cs:295

7) MonoTests.System.TimeZoneInfoTest+ConvertTimeTests.ConvertTime_AjustmentConvertTimeWithSourceTimeZone : System.TimeZoneNotFoundException : Exception of type 'System.TimeZoneNotFoundException' was thrown.
at System.TimeZoneInfo.FindSystemTimeZoneByFileName (System.String id, System.String filepath) [0x00018] in /home/saper/sw/mono/mcs/class/corlib/System/TimeZoneInfo.cs:551
at System.TimeZoneInfo.FindSystemTimeZoneByIdCore (System.String id) [0x0000c] in /home/saper/sw/mono/mcs/class/corlib/System/TimeZoneInfo.cs:192
at System.TimeZoneInfo.FindSystemTimeZoneById (System.String id) [0x00069] in /home/saper/sw/mono/mcs/class/corlib/System/TimeZoneInfo.cs:541
at MonoTests.System.TimeZoneInfoTest+ConvertTimeTests.ConvertTime_AjustmentConvertTimeWithSourceTimeZone () [0x00010] in /home/saper/sw/mono/mcs/class/corlib/Test/System/TimeZoneInfoTest.cs:623
at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&)
at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00038] in /home/saper/sw/mono/mcs/class/corlib/System.Reflection/MonoMethod.cs:295

8) MonoTests.System.TimeZoneInfoTest+ConvertTimeTests.ConvertTime_DateTime_TimeZoneInfo_DateTimeKindMatch :   #3.1
  Expected: Utc
  But was:  Unspecified

at MonoTests.System.TimeZoneInfoTest+ConvertTimeTests.ConvertTime_DateTime_TimeZoneInfo_DateTimeKindMatch () [0x000db] in /home/saper/sw/mono/mcs/class/corlib/Test/System/TimeZoneInfoTest.cs:554
at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&)
at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00038] in /home/saper/sw/mono/mcs/class/corlib/System.Reflection/MonoMethod.cs:295

9) MonoTests.System.TimeZoneTest.FindSystemTimeZoneById : System.TimeZoneNotFoundException : Exception of type 'System.TimeZoneNotFoundException' was thrown.
at System.TimeZoneInfo.FindSystemTimeZoneByFileName (System.String id, System.String filepath) [0x00018] in /home/saper/sw/mono/mcs/class/corlib/System/TimeZoneInfo.cs:551
at System.TimeZoneInfo.FindSystemTimeZoneByIdCore (System.String id) [0x0000c] in /home/saper/sw/mono/mcs/class/corlib/System/TimeZoneInfo.cs:192
at System.TimeZoneInfo.FindSystemTimeZoneById (System.String id) [0x00069] in /home/saper/sw/mono/mcs/class/corlib/System/TimeZoneInfo.cs:541
at MonoTests.System.TimeZoneTest.FindSystemTimeZoneById () [0x00000] in /home/saper/sw/mono/mcs/class/corlib/Test/System/TimeZoneTest.cs:323
at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&)
at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00038] in /home/saper/sw/mono/mcs/class/corlib/System.Reflection/MonoMethod.cs:295
Comment 4 marcos.henrich 2015-09-15 12:40:58 UTC
Marcin thank you for the update.

After some research on how .NET behaves if TimeZoneInfo.Local is set to TimeZoneInfo.Utc and I observed that TimeZoneInfo.ConvertTimeFromUtc (DateTime.UtcNow, TimeZoneInfo.Local).Kind is equal to DateTimeKind.Utc instead of DateTimeKind.Local.

Thus I reverted changes in TimeZoneInfo.cs and updates the tests.

The new pull request fixes and tests all tests in System.TimeZoneInfoTest+ConvertTimeTests with TimeZoneInfo.Local set to TimeZoneInfo.Utc.

https://github.com/mono/mono/pull/2056

I did not look into fixing the System.TimeZoneNotFoundException failures as they are related with missing timezone tables in the machine and not an issue on mono itself.
Comment 5 marcos.henrich 2015-09-16 02:06:41 UTC
Fixed in master 6caca3256b14a51ca209e35204b3e4ed28d88da5.
https://github.com/mono/mono/commit/6caca3256b14a51ca209e35204b3e4ed28d88da5

Note You need to log in before you can comment on or make changes to this bug.