using System;
using System.IO;
+using System.Runtime.InteropServices;
using System.Runtime.Serialization.Formatters.Binary;
using System.Collections;
+using System.Reflection;
+using System.Globalization;
using NUnit.Framework;
namespace MonoTests.System
Assert.IsNotNull (local);
Assert.IsTrue (true);
}
+
+ [DllImport ("libc")]
+ private static extern int readlink (string path, byte[] buffer, int buflen);
+
+ [Test] // Covers #24958
+ public void LocalId ()
+ {
+ byte[] buf = new byte [512];
+
+ var path = "/etc/localtime";
+ try {
+ var ret = readlink (path, buf, buf.Length);
+ if (ret == -1)
+ return; // path is not a symbolic link, nothing to test
+ } catch (DllNotFoundException e) {
+ return;
+ }
+
+ Assert.IsTrue (TimeZoneInfo.Local.Id != "Local", "Local timezone id should not be \"Local\"");
+ }
}
[TestFixture]
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);
[TestFixture]
public class GetSystemTimeZonesTests
{
+ [Test]
+ public void Identity ()
+ {
+ Assert.AreSame (TimeZoneInfo.GetSystemTimeZones (), TimeZoneInfo.GetSystemTimeZones ());
+ }
+
[Test]
public void NotEmpty ()
{
}
Assert.Fail ("Europe/Brussels not found in SystemTZ");
}
+
+ [Test]
+ public void ReflectionReturnsTheCorrectMethod ()
+ {
+ var method = (MethodInfo) typeof (TimeZoneInfo).GetMember ("GetSystemTimeZones", MemberTypes.Method, BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)[0];
+
+ var timeZones = (global::System.Collections.ObjectModel.ReadOnlyCollection<TimeZoneInfo>) method.Invoke (null, null);
+ Assert.IsTrue (timeZones.Count > 0, "GetSystemTimeZones should not return an empty collection.");
+ }
}
[TestFixture]
#endif
[Test]
- public void Dublin ()
+ public void SubminuteDSTOffsets ()
{
if (Environment.OSVersion.Platform != PlatformID.Unix)
Assert.Ignore ();
- // Europe/Dublin has a DST offset of 34 minutes and 39 seconds in 1916.
- TimeZoneInfo.FindSystemTimeZoneById ("Europe/Dublin");
- }
+ var subMinuteDSTs = new string [] {
+ "Europe/Dublin", // Europe/Dublin has a DST offset of 34 minutes and 39 seconds in 1916.
+ "Europe/Amsterdam",
+ "America/St_Johns",
+ "Canada/Newfoundland",
+ "Europe/Moscow",
+ "Europe/Riga",
+ "N/A", // testing that the test doesn't fail with inexistent TZs
+ };
+ foreach (var tz in subMinuteDSTs) {
+ try {
+ TimeZoneInfo.FindSystemTimeZoneById (tz);
+ } catch (TimeZoneNotFoundException) {
+ // ok;
+ } catch (Exception ex) {
+ Assert.Fail (string.Format ("Failed to load TZ {0}: {1}", tz, ex.ToString ()));
+ }
+ }
+ }
}
[TestFixture]
Assert.AreEqual(baseUtcOffset, cairo.GetUtcOffset (d.Add (new TimeSpan(0,0,0, 1))));
}
}
+
+ [TestFixture]
+ public class GetDaylightChanges
+ {
+ MethodInfo getChanges;
+
+ [SetUp]
+ public void Setup ()
+ {
+ var flags = BindingFlags.Instance | BindingFlags.NonPublic;
+ getChanges = typeof (TimeZoneInfo).GetMethod ("GetDaylightChanges", flags);
+ }
+
+ [Test]
+ public void TestSydneyDaylightChanges ()
+ {
+ TimeZoneInfo tz;
+ if (Environment.OSVersion.Platform == PlatformID.Unix)
+ tz = TimeZoneInfo.FindSystemTimeZoneById ("Australia/Sydney");
+ else
+ tz = TimeZoneInfo.FindSystemTimeZoneById ("W. Australia Standard Time");
+
+ var changes = (DaylightTime) getChanges.Invoke (tz, new object [] {2014});
+
+ Assert.AreEqual (new TimeSpan (1, 0, 0), changes.Delta);
+ Assert.AreEqual (new DateTime (2014, 10, 5, 2, 0, 0), changes.Start);
+ Assert.AreEqual (new DateTime (2014, 4, 6, 3, 0, 0), changes.End);
+ }
+ }
}
}