[mono/mono] [2 commits] 98f1c8c5: Return Local DateTime instead of Unspecified for >net_4_0

"Marek Safar ([email protected])" <[email protected]>
Newsgroups gmane.comp.gnome.mono.patches
Message-ID <00000141d15c5489-02fe7d04-ed88-4df1-a9e5-f02fd12de609-000000@email.amazonses.com>
   Branch: refs/heads/master
     Home: https://github.com/mono/mono
  Compare: https://github.com/mono/mono/compare/a57f9ce8a0c0...17d4130d1b86

   Commit: 98f1c8c58440fbb456d1f4e088c38dc5fd63cbe0
   Author: Alistair Bush <[email protected]> (alistair)
     Date: 2013-10-19 10:41:17 GMT
      URL: https://github.com/mono/mono/commit/98f1c8c58440fbb456d1f4e088c38dc5fd63cbe0

Return Local DateTime instead of Unspecified for >net_4_0

Changed paths:
  M mcs/class/System.Core/System/TimeZoneInfo.cs
  M mcs/class/System.Core/Test/System/TimeZoneInfoTest.cs

Modified: mcs/class/System.Core/System/TimeZoneInfo.cs
===================================================================
@@ -1,3 +1,4 @@
+
 /*
  * System.TimeZoneInfo
  *
@@ -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);
 		

Modified: mcs/class/System.Core/Test/System/TimeZoneInfoTest.cs
===================================================================
@@ -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 ()
 			{

   Commit: 17d4130d1b8671507a61d2e9f154017356cc7597
   Author: Marek Safar <[email protected]> (marek-safar)
     Date: 2013-10-19 15:34:26 GMT
      URL: https://github.com/mono/mono/commit/17d4130d1b8671507a61d2e9f154017356cc7597

Merge pull request #783 from alistair/timezoneinfo_fix_for__convert_utc_to_local

Bug 15373: Return Local DateTime instead of Unspecified for >net_4_0

Changed paths:
  M mcs/class/System.Core/System/TimeZoneInfo.cs
  M mcs/class/System.Core/Test/System/TimeZoneInfoTest.cs

Modified: mcs/class/System.Core/System/TimeZoneInfo.cs
===================================================================
@@ -1,3 +1,4 @@
+
 /*
  * System.TimeZoneInfo
  *
@@ -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);
 		

Modified: mcs/class/System.Core/Test/System/TimeZoneInfoTest.cs
===================================================================
@@ -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 ()
 			{


_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.