Ejemplo n.º 1
0
        private static void CheckToUniversalTime(TzTimeZone zone, string year)
        {
            // 2007-3-11 @ 2am
            Assert.IsFalse(zone.IsDaylightSavingTime(DateTime.Parse(year + "-03-10")));
            Assert.IsFalse(zone.IsDaylightSavingTime(DateTime.Parse(year + "-03-11")));
            Assert.IsTrue(zone.IsDaylightSavingTime(DateTime.Parse(year + "-03-12")));
            Assert.IsFalse(zone.IsDaylightSavingTime(DateTime.Parse(year + "-03-11 01:00")));
            Assert.IsFalse(zone.IsDaylightSavingTime(DateTime.Parse(year + "-03-11 01:59")));
            Assert.IsTrue(zone.IsDaylightSavingTime(DateTime.Parse(year + "-03-11 02:00")));
            Assert.IsTrue(zone.IsDaylightSavingTime(DateTime.Parse(year + "-03-11 02:01")));
            Console.WriteLine("DST on rule >= " + year + " for America/Chicago: Mar Sun>=8 2:00 (2am (8:00 UTC) becomes 3am)");
            Console.WriteLine("zone.ToUniversalTime('" + year + "-03-11 01:00'): '" + zone.ToUniversalTime(DateTime.Parse(year + "-03-11 01:00")) + "'");
            Assert.AreEqual(7, zone.ToUniversalTime(DateTime.Parse(year + "-03-11 01:00")).Hour);
            Console.WriteLine("zone.ToUniversalTime('" + year + "-03-11 01:30'): '" + zone.ToUniversalTime(DateTime.Parse(year + "-03-11 01:30")) + "'");
            Assert.AreEqual(7, zone.ToUniversalTime(DateTime.Parse(year + "-03-11 01:30")).Hour);
            Console.WriteLine("zone.ToUniversalTime('" + year + "-03-11 02:00'): '" + zone.ToUniversalTime(DateTime.Parse(year + "-03-11 02:00")) + "'");
            Assert.AreEqual(7, zone.ToUniversalTime(DateTime.Parse(year + "-03-11 02:00")).Hour);
            Console.WriteLine("zone.ToUniversalTime('" + year + "-03-11 02:30'): '" + zone.ToUniversalTime(DateTime.Parse(year + "-03-11 02:30")) + "'");
            Assert.AreEqual(7, zone.ToUniversalTime(DateTime.Parse(year + "-03-11 02:30")).Hour);
            Console.WriteLine("zone.ToUniversalTime('" + year + "-03-11 03:00'): '" + zone.ToUniversalTime(DateTime.Parse(year + "-03-11 03:00")) + "'");
            Assert.AreEqual(8, zone.ToUniversalTime(DateTime.Parse(year + "-03-11 03:00")).Hour);
            Console.WriteLine("zone.ToUniversalTime('" + year + "-03-11 03:30'): '" + zone.ToUniversalTime(DateTime.Parse(year + "-03-11 03:30")) + "'");
            Assert.AreEqual(8, zone.ToUniversalTime(DateTime.Parse(year + "-03-11 03:30")).Hour);
            Console.WriteLine("zone.ToUniversalTime('" + year + "-03-11 04:00'): '" + zone.ToUniversalTime(DateTime.Parse(year + "-03-11 04:00")) + "'");
            Assert.AreEqual(9, zone.ToUniversalTime(DateTime.Parse(year + "-03-11 04:00")).Hour);
            Console.WriteLine("zone.ToUniversalTime('" + year + "-05-10 03:00'): '" + zone.ToUniversalTime(DateTime.Parse(year + "-05-10 03:00")) + "'");
            Assert.AreEqual(8, zone.ToUniversalTime(DateTime.Parse(year + "-05-11 03:00")).Hour);

            // 2007-11-4 @ 2 am
            Assert.IsTrue(zone.IsDaylightSavingTime(DateTime.Parse(year + "-11-4")));
            Assert.IsTrue(zone.IsDaylightSavingTime(DateTime.Parse(year + "-11-4")));
            Assert.IsFalse(zone.IsDaylightSavingTime(DateTime.Parse(year + "-11-5")));
            Assert.IsTrue(zone.IsDaylightSavingTime(DateTime.Parse(year + "-11-4 01:00")));
            Assert.IsTrue(zone.IsDaylightSavingTime(DateTime.Parse(year + "-11-4 01:59")));
            Assert.IsFalse(zone.IsDaylightSavingTime(DateTime.Parse(year + "-11-4 02:00")));
            Assert.IsFalse(zone.IsDaylightSavingTime(DateTime.Parse(year + "-11-4 02:01")));
            Console.WriteLine("DST off rule >= " + year + " for America/Chicago: Nov Sun>=1 2:00 (2am (7:00 UTC) becomes 1am)");
            Console.WriteLine("zone.ToUniversalTime('" + year + "-11-04 00:00'): '" + zone.ToUniversalTime(DateTime.Parse(year + "-11-04 00:00")) + "'");
            Assert.AreEqual(5, zone.ToUniversalTime(DateTime.Parse(year + "-11-04 00:00")).Hour);
            Console.WriteLine("zone.ToUniversalTime('" + year + "-11-04 01:00'): '" + zone.ToUniversalTime(DateTime.Parse(year + "-11-04 01:00")) + "'");
            Assert.AreEqual(6, zone.ToUniversalTime(DateTime.Parse(year + "-11-04 01:00")).Hour);
            Console.WriteLine("zone.ToUniversalTime('" + year + "-11-04 01:30'): '" + zone.ToUniversalTime(DateTime.Parse(year + "-11-04 01:30")) + "'");
            Assert.AreEqual(6, zone.ToUniversalTime(DateTime.Parse(year + "-11-04 01:30")).Hour);
            Console.WriteLine("zone.ToUniversalTime('" + year + "-11-04 02:00'): '" + zone.ToUniversalTime(DateTime.Parse(year + "-11-04 02:00")) + "'");
            Assert.AreEqual(8, zone.ToUniversalTime(DateTime.Parse(year + "-11-04 02:00")).Hour);
            Console.WriteLine("zone.ToUniversalTime('" + year + "-11-04 02:30'): '" + zone.ToUniversalTime(DateTime.Parse(year + "-11-04 02:30")) + "'");
            Assert.AreEqual(8, zone.ToUniversalTime(DateTime.Parse(year + "-11-04 02:30")).Hour);
            Console.WriteLine("zone.ToUniversalTime('" + year + "-11-04 03:00'): '" + zone.ToUniversalTime(DateTime.Parse(year + "-11-04 03:00")) + "'");
            Assert.AreEqual(9, zone.ToUniversalTime(DateTime.Parse(year + "-11-04 03:00")).Hour);
            Console.WriteLine("zone.ToUniversalTime('" + year + "-11-04 03:30'): '" + zone.ToUniversalTime(DateTime.Parse(year + "-11-04 03:30")) + "'");
            Assert.AreEqual(9, zone.ToUniversalTime(DateTime.Parse(year + "-11-04 03:30")).Hour);
            Console.WriteLine("zone.ToUniversalTime('" + year + "-12-12 03:00'): '" + zone.ToUniversalTime(DateTime.Parse(year + "-12-12 03:00")) + "'");
            Assert.AreEqual(9, zone.ToUniversalTime(DateTime.Parse(year + "-12-04 03:00")).Hour);
        }
Ejemplo n.º 2
0
 private static void AssertIsDaylightSavingsTime(TzTimeZone zone, string dt, bool expectIsDaylightSavingsTime)
 {
     Assert.AreEqual(expectIsDaylightSavingsTime, zone.IsDaylightSavingTime(DateTime.Parse(dt)));
 }