Beispiel #1
0
            public void ConvertsTimeFromUtc_ToUtc()
            {
                // prepare
                var dateFrom = new DateTime(1234, 5, 6, 7, 8, 9, 123, DateTimeKind.Utc);
                var tzTo     = TimeZoneInfo.FindSystemTimeZoneById("UTC");

                // execute
                var result = SrkTimeZoneInfoExtensions.ConvertFromUtc(tzTo, dateFrom);

                // verify
                Assert.AreEqual(dateFrom.Year, result.Year);
                Assert.AreEqual(dateFrom.Month, result.Month);
                Assert.AreEqual(dateFrom.Day, result.Day);
                Assert.AreEqual(dateFrom.Hour, result.Hour);
                Assert.AreEqual(dateFrom.Minute, result.Minute);
                Assert.AreEqual(dateFrom.Second, result.Second);
                Assert.AreEqual(dateFrom.Millisecond, result.Millisecond);
                Assert.AreEqual(DateTimeKind.Utc, result.Kind);
            }
Beispiel #2
0
            public void ConvertsTimeFromUnspecified()
            {
                // prepare
                ////var tzFrom = TimeZoneInfo.FindSystemTimeZoneById("Romance Standard Time"); // assume Unknown is UTC
                var dateFrom = new DateTime(1234, 5, 6, 7, 8, 9, 123, DateTimeKind.Unspecified);
                var tzTo     = TimeZoneInfo.FindSystemTimeZoneById("Romance Standard Time");

                // execute
                var result = SrkTimeZoneInfoExtensions.ConvertFromUtc(tzTo, dateFrom);

                // verify
                Assert.AreEqual(dateFrom.Year, result.Year);
                Assert.AreEqual(dateFrom.Month, result.Month);
                Assert.AreEqual(dateFrom.Day, result.Day);
                Assert.AreEqual(dateFrom.Hour + 2, result.Hour);
                Assert.AreEqual(dateFrom.Minute, result.Minute);
                Assert.AreEqual(dateFrom.Second, result.Second);
                Assert.AreEqual(dateFrom.Millisecond, result.Millisecond);
                Assert.AreEqual(DateTimeKind.Unspecified, result.Kind);
            }
Beispiel #3
0
            public void ConvertsTimeFromLocal_ToUtc()
            {
                // prepare
                var tzFrom   = TimeZoneInfo.Local;
                var dateFrom = new DateTime(1234, 5, 6, 7, 8, 9, 123, DateTimeKind.Local);
                var tzTo     = TimeZoneInfo.FindSystemTimeZoneById("UTC");

                // execute
                var result = SrkTimeZoneInfoExtensions.ConvertFromUtc(tzTo, dateFrom);

                // verify
                Assert.AreEqual(dateFrom.Year, result.Year);
                Assert.AreEqual(dateFrom.Month, result.Month);
                Assert.AreEqual(dateFrom.Day, result.Day);
                var expectedHour = dateFrom.Hour - tzFrom.GetUtcOffset(dateFrom).TotalHours + tzTo.GetUtcOffset(dateFrom).TotalHours;

                Assert.AreEqual(expectedHour, result.Hour);
                Assert.AreEqual(dateFrom.Minute, result.Minute);
                Assert.AreEqual(dateFrom.Second, result.Second);
                Assert.AreEqual(dateFrom.Millisecond, result.Millisecond);
                Assert.AreEqual(DateTimeKind.Utc, result.Kind);
            }