public void PlusMilliseconds_Simple()
        {
            LocalDateTime start            = new LocalDateTime(2011, 4, 2, 12, 15, 8, 300);
            LocalDateTime expectedForward  = new LocalDateTime(2011, 4, 2, 12, 15, 8, 700);
            LocalDateTime expectedBackward = new LocalDateTime(2011, 4, 2, 12, 15, 7, 900);

            Assert.AreEqual(expectedForward, start.PlusMilliseconds(400));
            Assert.AreEqual(expectedBackward, start.PlusMilliseconds(-400));
        }
示例#2
0
 public static LocalDateTime WithMillisOfSecond(this LocalDateTime instance, int milliSeconds)
 {
     if (milliSeconds < 0 || milliSeconds > 999)
     {
         throw new ArgumentException(nameof(milliSeconds));
     }
     return(instance.PlusMilliseconds(milliSeconds - instance.Millisecond));
 }
示例#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));
        }
示例#4
0
 public void PlusMilliseconds()
 {
     SampleStartDateTime.PlusMilliseconds(3);
 }
示例#5
0
 public LocalDateTime PlusMilliseconds() => Sample.PlusMilliseconds(3);
 public void PlusMilliseconds()
 {
     Sample.PlusMilliseconds(3).Consume();
 }
示例#7
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 PlusMilliseconds_Simple()
 {
     LocalDateTime start = new LocalDateTime(2011, 4, 2, 12, 15, 8, 300);
     LocalDateTime expectedForward = new LocalDateTime(2011, 4, 2, 12, 15, 8, 700);
     LocalDateTime expectedBackward = new LocalDateTime(2011, 4, 2, 12, 15, 7, 900);
     Assert.AreEqual(expectedForward, start.PlusMilliseconds(400));
     Assert.AreEqual(expectedBackward, start.PlusMilliseconds(-400));
 }
 public LocalDateTime PlusMilliseconds()
 {
     return(Sample.PlusMilliseconds(3));
 }
 /// <summary>
 /// Add milliseconds
 /// </summary>
 /// <param name="lt"></param>
 /// <param name="milliseconds"></param>
 /// <returns></returns>
 public static LocalDateTime AddMilliseconds(this LocalDateTime lt, long milliseconds) => lt.PlusMilliseconds(milliseconds);