Skip to content

Commit

Permalink
Return Local DateTime instead of Unspecified for >net_4_0
Browse files Browse the repository at this point in the history
  • Loading branch information
alistair committed Oct 19, 2013
1 parent 779127e commit 98f1c8c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
12 changes: 10 additions & 2 deletions mcs/class/System.Core/System/TimeZoneInfo.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

/*
* System.TimeZoneInfo
*
Expand Down Expand Up @@ -285,10 +286,17 @@ private DateTime ConvertTimeFromUtc (DateTime dateTime)

if (this == TimeZoneInfo.Utc)
return DateTime.SpecifyKind (dateTime, DateTimeKind.Utc);

//FIXME: do not rely on DateTime implementation !
if (this == TimeZoneInfo.Local)
if (this == TimeZoneInfo.Local)
{
#if NET_4_0
return dateTime.ToLocalTime ();
#else
return DateTime.SpecifyKind (dateTime.ToLocalTime (), DateTimeKind.Unspecified);
#endif
}


AdjustmentRule rule = GetApplicableRule (dateTime);

Expand Down
17 changes: 17 additions & 0 deletions mcs/class/System.Core/Test/System/TimeZoneInfoTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,23 @@ public void ConvertFromToUtc ()

}


[Test]
public void ConvertFromToLocal ()
{
DateTime utc = DateTime.UtcNow;
Assert.AreEqual(utc.Kind, DateTimeKind.Utc);
DateTime converted = TimeZoneInfo.ConvertTimeFromUtc(utc, TimeZoneInfo.Local);
#if NET_4_0
Assert.AreEqual(DateTimeKind.Local, converted.Kind);
#else
Assert.AreEqual(DateTimeKind.Unspecified, converted.Kind);
#endif
DateTime back = TimeZoneInfo.ConvertTimeToUtc(converted, TimeZoneInfo.Local);
Assert.AreEqual(back.Kind, DateTimeKind.Utc);
Assert.AreEqual(utc, back);
}

[Test]
public void ConvertToTimeZone ()
{
Expand Down

0 comments on commit 98f1c8c

Please sign in to comment.