Exemplo n.º 1
0
 public void UnixTimestamp_DateIs13OfJune1984_VerifyResult()
 {
     using (TimeReseter.Set(13.June(1984).At(Time.Noon).InUtc()))
     {
         Assert.That(Time.UnixTimestamp, Is.EqualTo(455976000d));
     }
 }
Exemplo n.º 2
0
 public void UnixTimestamp_DateIsFirstOfJanuary1970_VerifyResult()
 {
     using (TimeReseter.Set(Time.UnixEpoch))
     {
         Assert.That(Time.UnixTimestamp, Is.EqualTo(0d));
     }
 }
Exemplo n.º 3
0
 public void UnixTimestamp_DateIsSecondOfJanuary1970_VerifyResult()
 {
     using (TimeReseter.Set(new DateTimeOffset(2.January(1970), TimeSpan.Zero)))
     {
         Assert.That(Time.UnixTimestamp, Is.EqualTo(3600d * 24));
     }
 }
Exemplo n.º 4
0
 public void FromNow_2Days_2Days()
 {
     using (TimeReseter.Set(14.February(2007).In(2.Hours())))
     {
         Assert.That(2.Days().FromNow(), Is.EqualTo(16.February(2007).In(2.Hours())));
     }
 }
Exemplo n.º 5
0
 public void Ago_TimeNowMinusTimeSpan()
 {
     using (TimeReseter.Set(10.February(2000).InUtc()))
     {
         Assert.That(2.Days().Ago(), Is.EqualTo(8.February(2000).InUtc()));
     }
 }
Exemplo n.º 6
0
 public void Elapsed_1DayFromNow_1Days()
 {
     using (TimeReseter.Set(10.February(2000).InUtc()))
     {
         TimeSpan passed = 11.February(2000).InUtc().Elapsed();
         Assert.That(passed, Is.EqualTo(1.Days()));
     }
 }
Exemplo n.º 7
0
        public void Set_DoesNotSetUtcNow()
        {
            var born = 11.March(1977);

            using (TimeReseter.Set(born))
            {
                Assert.That(Time.UtcNow.DateTime, Is.Not.EqualTo(born));
            }
        }
Exemplo n.º 8
0
        public void Set_SetsTimeNow()
        {
            var born = 11.March(1977);

            using (TimeReseter.Set(born))
            {
                Assert.That(Time.Now.DateTime, Is.EqualTo(born));
            }
        }
Exemplo n.º 9
0
        public void Set_SetsBackTimeWhenDisposed()
        {
            var born    = 11.March(1977);
            var reseter = TimeReseter.Set(born);

            reseter.Dispose();
            DateTimeOffset timeNow = Time.Now, dtNow = DateTime.Now;

            Assert.That(timeNow - dtNow, Is.LessThan(Time.OneSecond));
        }
Exemplo n.º 10
0
        public void Explore()
        {
            using (CultureReseter.Set("da-DK"))
            {
                Assert.That(2001.IsLeapYear(), Is.False);
                Assert.That(25.October(2012).InUtc().Week(), Is.EqualTo(43));

                Assert.That(DayOfWeek.Monday.DaysTill(DayOfWeek.Thursday), Is.EqualTo(3));
                Assert.That(DayOfWeek.Monday.DaysSince(DayOfWeek.Friday), Is.EqualTo(3));
                Assert.That(/* Mon */ 16.June(2008).InUtc().Previous(DayOfWeek.Thursday),
                            Is.EqualTo(12.June(2008).InUtc() /* Thu */));
                Assert.That(/* Thu */ 12.June(2008).InUtc().Next(DayOfWeek.Monday), Is.EqualTo(16.June(2008).InUtc() /* Mon */));

                Assert.That(12.June(2008).At(15.Hours().Minutes(43).Seconds(10)).InUtc()
                            .BeginningOfDay(), Is.EqualTo(12.June(2008).At(Time.MidNight).InUtc()));
                Assert.That(12.June(2008).InUtc().BeginningOfWeek(), Is.EqualTo(9.June(2008).InUtc()));
                Assert.That(12.June(2008).InUtc().BeginningOf(Period.Year), Is.EqualTo(1.January(2008).InUtc()));
                Assert.That(12.June(2008).InUtc().EndOfWeek(), Is.EqualTo(15.June(2008).At(Time.EndOfDay).InUtc()));

                Assert.That(11.March(1977).InUtc().Difference(14.March(1977).InUtc()), Is.EqualTo(3.Days()));
                DateTimeOffset firstFebruary = 1.February(2008).InUtc(), fifthFebruary = 5.February(2008).InUtc();
                Assert.That(firstFebruary.DiffersFrom(fifthFebruary).InAtLeast(2.Days()), Is.True);
                Assert.That(firstFebruary.DiffersFrom(fifthFebruary).InAtMost(4.Days()), Is.True);
                Assert.That(firstFebruary.DiffersFrom(fifthFebruary).InLessThan(1.Weeks()), Is.True);
                Assert.That(firstFebruary.DiffersFrom(fifthFebruary).InMoreThan(Time.OneHour), Is.True);
                Assert.That(firstFebruary.DiffersFrom(firstFebruary).InNothing(), Is.True);
                Assert.That(firstFebruary.DiffersFrom(fifthFebruary).InSomething(), Is.True);

                using (TimeReseter.Set(10.February(2000).At(Time.Noon).In(1.Hours())))
                {
                    Assert.That(2.Days().Ago(), Is.EqualTo(8.February(2000).At(Time.Noon).In(Time.Offset)));
                    Assert.That(2.Days().FromNow(), Is.EqualTo(12.February(2000).At(Time.Noon).In(Time.Offset)));
                    Assert.That(9.February(2000).In(Time.Offset).Elapsed(), Is.EqualTo(1.Days().Hours(12)));
                }

                Assert.That(TimeSpan.Zero.Describe(), Is.EqualTo("now"));
                Assert.That(59.Seconds().Describe(), Is.EqualTo("59 seconds"));
                Assert.That(1.Minutes().Seconds(1).Describe(), Is.EqualTo("about 1 minute"));
                Assert.That(3.Minutes().Seconds(31).Describe(), Is.EqualTo("about 4 minutes"));
                Assert.That(3.Hours().Minutes(3).Seconds(1).Describe(), Is.EqualTo("about 3 hours"));
                Assert.That(2.Days().Minutes(1).Seconds(1).Describe(), Is.EqualTo("about 2 days"));
                Assert.That(2.Days().Minutes(1).Seconds(1).AsLapseDescription(), Is.EqualTo("about 2 days ago"));

                Assert.That(1.January(2008).At(15.Hours()).AsOffset(3.Hours()),
                            Is.EqualTo(new DateTimeOffset(2008, 1, 1, 15, 0, 0, 3.Hours())));
                Assert.That(1.January(2008).At(15.Hours()).AsUtcOffset(),
                            Is.EqualTo(new DateTimeOffset(2008, 1, 1, 15, 0, 0, 0.Hours())));

                Assert.That(25.October(2012).At(15.Hours().Minutes(55)).InUtc().SetTime(15, 56, 0),
                            Is.EqualTo(25.October(2012).At(15.Hours().Minutes(56)).InUtc()));
            }
        }
Exemplo n.º 11
0
        public void AdventConstructor_TwoMonthsThreeDaysAgo_PropertiesSet()
        {
            DateTime now = _keyDateInHistory;

            using (TimeReseter.Set(now))
            {
                DateTime twoMonthsThreeDaysAgo = now.AddMonths(-2).AddDays(-3);
                var      subject = new Age(twoMonthsThreeDaysAgo);
                Assert.That(subject, Must.Be.Age()
                            .WithBounds(twoMonthsThreeDaysAgo, now)
                            .Elapsed(now - twoMonthsThreeDaysAgo)
                            .WithComponents(days: 3, weeks: 0, months: 2, years: 0));
            }
        }
Exemplo n.º 12
0
        public void AdventConstructor_OneWeekAgo_SetsTimeProperties()
        {
            DateTime now = _keyDateInHistory;

            using (TimeReseter.Set(now))
            {
                var subject = new Age(1.Weeks().Ago().DateTime);

                Assert.That(subject.Years, Is.EqualTo(0));
                Assert.That(subject.Months, Is.EqualTo(0));
                Assert.That(subject.Weeks, Is.EqualTo(1));
                Assert.That(subject.Days, Is.EqualTo(0));
            }
        }
Exemplo n.º 13
0
        public void AdventConstructor_OneWeekAgo_PropertiesSetTo1WeekAgo()
        {
            DateTime now = _keyDateInHistory;

            using (TimeReseter.Set(now))
            {
                DateTime oneWeekAgo = now.AddDays(-7);
                var      subject    = new Age(oneWeekAgo);

                Assert.That(subject, Must.Be.Age()
                            .WithBounds(advent: oneWeekAgo, terminus: now)
                            .Elapsed(1.Weeks())
                            .WithComponents(days: 0, weeks: 1, months: 0, years: 0));
            }
        }
Exemplo n.º 14
0
        public void AdventConstructor_OneDayAgo_PropertiesSetTo1DayAgo()
        {
            DateTime now = _keyDateInHistory;

            using (TimeReseter.Set(now))
            {
                DateTime yesterday = Time.Yesterday.DateTime;
                var      subject   = new Age(yesterday);

                Assert.That(subject, Must.Be.Age()
                            .WithBounds(advent: yesterday, terminus: now)
                            .Elapsed(1.Days())
                            .WithComponents(days: 1, weeks: 0, months: 0, years: 0));
            }
        }