Exemple #1
0
        public void Now_GivenUsEasternTimeZone_UsesCorrectOffset()
        {
            // note this is a date when daylight saving time is in effect
            var nowFunc = new Func <DateTime>(() => new DateTime(2014, 7, 23, 5, 0, 0, DateTimeKind.Utc));

            MyDomainTime.SetNow(nowFunc);
            var localTime = MyDomainTime.FromLocal("US/Eastern").Now();

            Assert.IsTrue(localTime.Offset == TimeSpan.FromHours(-4));
        }
Exemple #2
0
        public void IsExpired_GivenNoonAndItExpiredTodayAtMidnight_ReturnsTrue()
        {
            var nowFunc = new Func <DateTime>(() => new DateTime(2014, 7, 23, 19, 0, 0, DateTimeKind.Utc));

            MyDomainTime.SetNow(nowFunc);

            var expiresDate = new DateTime(2014, 7, 23);
            var expired     = MyDomainTime.FromLocal(TimeZoneHelper.UsPacific).IsExpired(expiresDate);

            Assert.IsFalse(expired);
            MyDomainTime.ResetNow();
        }
Exemple #3
0
        public void Now_DefaultNowFunction_ReturnsActualNow()
        {
            MyDomainTime.ResetNow();
            var now     = DateTime.UtcNow;
            var testNow = MyDomainTime.FromUniversal().Now();

            Assert.AreEqual(now.Year, testNow.Year);
            Assert.AreEqual(now.Month, testNow.Month);
            Assert.AreEqual(now.Day, testNow.Day);
            Assert.AreEqual(now.Hour, testNow.Hour);
            Assert.AreEqual(now.Minute, testNow.Minute);
        }
Exemple #4
0
        public void Now_FromUniversal_ChangesNowValueToSpecifiedDateTimeWithNoOffset()
        {
            MyDomainTime.SetNow(() => new DateTime(2015, 11, 4, 8, 45, 12, DateTimeKind.Utc));
            var now = MyDomainTime.FromUniversal().Now();

            Assert.AreEqual(2015, now.Year);
            Assert.AreEqual(11, now.Month);
            Assert.AreEqual(4, now.Day);
            Assert.AreEqual(8, now.Hour);
            Assert.AreEqual(45, now.Minute);
            Assert.AreEqual(12, now.Second);
            Assert.AreEqual(new TimeSpan(0, 0, 0), now.Offset);
            MyDomainTime.ResetNow();
        }
Exemple #5
0
        public void Now_FromLocal_ChangesNowValueToSpecifiedDateTimeWithLocalOffset()
        {
            MyDomainTime.SetNow(() => new DateTime(2015, 11, 4, 8, 45, 12, DateTimeKind.Utc));
            var now = MyDomainTime.FromLocal("US/Pacific").Now();

            Assert.AreEqual(2015, now.Year);
            Assert.AreEqual(11, now.Month);
            Assert.AreEqual(4, now.Day);
            Assert.AreEqual(0, now.Hour);             // should be the local hour, given the UTC -8 for this date
            Assert.AreEqual(45, now.Minute);
            Assert.AreEqual(12, now.Second);
            Assert.AreEqual(new TimeSpan(-8, 0, 0), now.Offset);
            MyDomainTime.ResetNow();
        }
Exemple #6
0
 public void Example3()
 {
     MyDomainTime.SetNow(() => new DateTime(2017, 6, 13, 19, 0, 0, DateTimeKind.Utc));
     while (true)
     {
         var domainTime = MyDomainTime.FromLocal(TimeZoneHelper.UsPacific);
         if (domainTime.IsLunchtime())
         {
             Console.WriteLine("Time for lunch!");
             SetCalendar("Back in 30 minutes.");
             MyDomainTime.ResetNow();
             return;
         }
         Thread.Sleep(1000);
     }
 }