public void PlusTicks_CrossingDay()
        {
            LocalDateTime start            = new LocalDateTime(2011, 4, 2, 12, 15, 8);
            LocalDateTime expectedForward  = new LocalDateTime(2011, 4, 3, 12, 15, 8);
            LocalDateTime expectedBackward = new LocalDateTime(2011, 4, 1, 12, 15, 8);

            Assert.AreEqual(expectedForward, start.PlusNanoseconds(NodaConstants.NanosecondsPerDay));
            Assert.AreEqual(expectedBackward, start.PlusNanoseconds(-NodaConstants.NanosecondsPerDay));
        }
        public void PlusNanoseconds_Simple()
        {
            // Just use the ticks values
            LocalDateTime start            = new LocalDateTime(2011, 4, 2, 12, 15, 8, 300, 7500);
            LocalDateTime expectedForward  = new LocalDateTime(2011, 4, 2, 12, 15, 8, 300, 7540);
            LocalDateTime expectedBackward = new LocalDateTime(2011, 4, 2, 12, 15, 8, 300, 7460);

            Assert.AreEqual(expectedForward, start.PlusNanoseconds(4000));
            Assert.AreEqual(expectedBackward, start.PlusNanoseconds(-4000));
        }
Ejemplo n.º 3
0
        public void Addition_Duration()
        {
            const int  minutes      = 23;
            const int  hours        = 3;
            const int  milliseconds = 40000;
            const long seconds      = 321;
            const long nanoseconds  = 12345;
            const long ticks        = 5432112345;

            // Test all three approaches... not bothering to check a different calendar,
            // but we'll use two different offsets.
            OffsetDateTime start    = new LocalDateTime(2014, 08, 14, 6, 51).WithOffset(Offset.FromHours(1));
            Duration       duration = Duration.FromHours(8) + Duration.FromMinutes(9);
            OffsetDateTime expected = new LocalDateTime(2014, 08, 14, 15, 0).WithOffset(Offset.FromHours(1));

            Assert.AreEqual(expected, start + duration);
            Assert.AreEqual(expected, start.Plus(duration));
            Assert.AreEqual(expected, OffsetDateTime.Add(start, duration));

            Assert.AreEqual(start + Duration.FromHours(hours), start.PlusHours(hours));
            Assert.AreEqual(start + Duration.FromHours(-hours), start.PlusHours(-hours));

            Assert.AreEqual(start + Duration.FromMinutes(minutes), start.PlusMinutes(minutes));
            Assert.AreEqual(start + Duration.FromMinutes(-minutes), start.PlusMinutes(-minutes));

            Assert.AreEqual(start + Duration.FromSeconds(seconds), start.PlusSeconds(seconds));
            Assert.AreEqual(start + Duration.FromSeconds(-seconds), start.PlusSeconds(-seconds));

            Assert.AreEqual(start + Duration.FromMilliseconds(milliseconds), start.PlusMilliseconds(milliseconds));
            Assert.AreEqual(start + Duration.FromMilliseconds(-milliseconds), start.PlusMilliseconds(-milliseconds));

            Assert.AreEqual(start + Duration.FromTicks(ticks), start.PlusTicks(ticks));
            Assert.AreEqual(start + Duration.FromTicks(-ticks), start.PlusTicks(-ticks));

            Assert.AreEqual(start + Duration.FromNanoseconds(nanoseconds), start.PlusNanoseconds(nanoseconds));
            Assert.AreEqual(start + Duration.FromNanoseconds(-nanoseconds), start.PlusNanoseconds(-nanoseconds));
        }
        public void ZoneWithAmbiguity_JustAfterTransition()
        {
            var mapping = ZoneWithAmbiguity.MapLocal(TransitionPlus10.PlusNanoseconds(1));

            CheckMapping(mapping, IntervalAfterAmbiguity, IntervalAfterAmbiguity, 1);
        }
        public void ZoneWithAmbiguity_JustBeforeAmbiguity()
        {
            var mapping = ZoneWithAmbiguity.MapLocal(TransitionMinus5.PlusNanoseconds(-1));

            CheckMapping(mapping, IntervalBeforeAmbiguity, IntervalBeforeAmbiguity, 1);
        }
Ejemplo n.º 6
0
        public void Addition_Duration()
        {
            const int minutes = 23;
            const int hours = 3;
            const int milliseconds = 40000;
            const long seconds = 321;
            const long nanoseconds = 12345;
            const long ticks = 5432112345;

            // Test all three approaches... not bothering to check a different calendar,
            // but we'll use two different offsets.
            OffsetDateTime start = new LocalDateTime(2014, 08, 14, 6, 51).WithOffset(Offset.FromHours(1));
            Duration duration = Duration.FromHours(8) + Duration.FromMinutes(9);
            OffsetDateTime expected = new LocalDateTime(2014, 08, 14, 15, 0).WithOffset(Offset.FromHours(1));
            Assert.AreEqual(expected, start + duration);
            Assert.AreEqual(expected, start.Plus(duration));
            Assert.AreEqual(expected, OffsetDateTime.Add(start, duration));

            Assert.AreEqual(start + Duration.FromHours(hours), start.PlusHours(hours));
            Assert.AreEqual(start + Duration.FromHours(-hours), start.PlusHours(-hours));

            Assert.AreEqual(start + Duration.FromMinutes(minutes), start.PlusMinutes(minutes));
            Assert.AreEqual(start + Duration.FromMinutes(-minutes), start.PlusMinutes(-minutes));

            Assert.AreEqual(start + Duration.FromSeconds(seconds), start.PlusSeconds(seconds));
            Assert.AreEqual(start + Duration.FromSeconds(-seconds), start.PlusSeconds(-seconds));

            Assert.AreEqual(start + Duration.FromMilliseconds(milliseconds), start.PlusMilliseconds(milliseconds));
            Assert.AreEqual(start + Duration.FromMilliseconds(-milliseconds), start.PlusMilliseconds(-milliseconds));

            Assert.AreEqual(start + Duration.FromTicks(ticks), start.PlusTicks(ticks));
            Assert.AreEqual(start + Duration.FromTicks(-ticks), start.PlusTicks(-ticks));

            Assert.AreEqual(start + Duration.FromNanoseconds(nanoseconds), start.PlusNanoseconds(nanoseconds));
            Assert.AreEqual(start + Duration.FromNanoseconds(-nanoseconds), start.PlusNanoseconds(-nanoseconds));
        }
 public void PlusTicks_CrossingDay()
 {
     LocalDateTime start = new LocalDateTime(2011, 4, 2, 12, 15, 8);
     LocalDateTime expectedForward = new LocalDateTime(2011, 4, 3, 12, 15, 8);
     LocalDateTime expectedBackward = new LocalDateTime(2011, 4, 1, 12, 15, 8);
     Assert.AreEqual(expectedForward, start.PlusNanoseconds(NodaConstants.NanosecondsPerDay));
     Assert.AreEqual(expectedBackward, start.PlusNanoseconds(-NodaConstants.NanosecondsPerDay));
 }
 public void PlusNanoseconds_Simple()
 {
     // Just use the ticks values
     LocalDateTime start = new LocalDateTime(2011, 4, 2, 12, 15, 8, 300, 7500);
     LocalDateTime expectedForward = new LocalDateTime(2011, 4, 2, 12, 15, 8, 300, 7540);
     LocalDateTime expectedBackward = new LocalDateTime(2011, 4, 2, 12, 15, 8, 300, 7460);
     Assert.AreEqual(expectedForward, start.PlusNanoseconds(4000));
     Assert.AreEqual(expectedBackward, start.PlusNanoseconds(-4000));
 }
 /// <summary>
 /// Add nanoseconds
 /// </summary>
 /// <param name="lt"></param>
 /// <param name="nanoseconds"></param>
 /// <returns></returns>
 public static LocalDateTime AddNanoseconds(this LocalDateTime lt, long nanoseconds) => lt.PlusNanoseconds(nanoseconds);