Skip to content

Commit

Permalink
Merge pull request #783 from alistair/timezoneinfo_fix_for__convert_u…
Browse files Browse the repository at this point in the history
…tc_to_local

Bug 15373: Return Local DateTime instead of Unspecified for >net_4_0
  • Loading branch information
marek-safar committed Oct 19, 2013
2 parents a57f9ce + 98f1c8c commit 17d4130
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
@@ -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
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 17d4130

Please sign in to comment.