public void With()
        {
            LocalTime start    = LocalTime.FromHourMinuteSecondMillisecondTick(12, 15, 8, 100, 1234);
            LocalTime expected = new LocalTime(12, 15, 8);

            Assert.AreEqual(expected, start.With(TimeAdjusters.TruncateToSecond));
        }
Esempio n. 2
0
        public void TruncateToHour()
        {
            var start = LocalTime.FromHourMinuteSecondMillisecondTick(7, 4, 30, 123, 4567);
            var end   = new LocalTime(7, 0, 0);

            Assert.AreEqual(end, TimeAdjusters.TruncateToHour(start));
        }
        public void LocalTimeConverter()
        {
            var value = LocalTime.FromHourMinuteSecondMillisecondTick(1, 2, 3, 4, 5).PlusNanoseconds(67);
            var json  = "\"01:02:03.004000567\"";

            AssertConversions(value, json, NodaConverters.LocalTimeConverter);
        }
Esempio n. 4
0
        public void BetweenLocalTimes_MovingBackwards()
        {
            LocalTime t1 = LocalTime.FromHourMinuteSecondMillisecondTick(15, 30, 45, 20, 5);
            LocalTime t2 = new LocalTime(10, 0);

            Assert.AreEqual(Period.FromHours(-5) + Period.FromMinutes(-30) + Period.FromSeconds(-45) +
                            Period.FromMilliseconds(-20) + Period.FromTicks(-5),
                            Period.Between(t1, t2));
        }
        public void PlusTicks_Simple()
        {
            LocalTime start            = LocalTime.FromHourMinuteSecondMillisecondTick(12, 15, 8, 300, 7500);
            LocalTime expectedForward  = LocalTime.FromHourMinuteSecondMillisecondTick(12, 15, 8, 301, 1500);
            LocalTime expectedBackward = LocalTime.FromHourMinuteSecondMillisecondTick(12, 15, 8, 300, 3500);

            Assert.AreEqual(expectedForward, start.PlusTicks(4000));
            Assert.AreEqual(expectedBackward, start.PlusTicks(-4000));
        }
Esempio n. 6
0
 public static LocalTime PegasusTimeToLocalTime(TimeSpan time)
 {
     return(LocalTime.FromHourMinuteSecondMillisecondTick(
                time.Hours,
                time.Minutes,
                0,
                0,
                0));
 }
Esempio n. 7
0
        public void BetweenLocalTimes_InvalidUnits()
        {
            LocalTime t1 = new LocalTime(10, 0);
            LocalTime t2 = LocalTime.FromHourMinuteSecondMillisecondTick(15, 30, 45, 20, 5);

            Assert.Throws <ArgumentException>(() => Period.Between(t1, t2, 0));
            Assert.Throws <ArgumentException>(() => Period.Between(t1, t2, (PeriodUnits)(-1)));
            Assert.Throws <ArgumentException>(() => Period.Between(t1, t2, PeriodUnits.YearMonthDay));
            Assert.Throws <ArgumentException>(() => Period.Between(t1, t2, PeriodUnits.Years | PeriodUnits.Hours));
        }
Esempio n. 8
0
        public void PlusTicks_Simple()
        {
            LocalDate date                 = new LocalDate(2011, 4, 2);
            LocalTime startTime            = LocalTime.FromHourMinuteSecondMillisecondTick(12, 15, 8, 300, 7500);
            LocalTime expectedForwardTime  = LocalTime.FromHourMinuteSecondMillisecondTick(12, 15, 8, 301, 1500);
            LocalTime expectedBackwardTime = LocalTime.FromHourMinuteSecondMillisecondTick(12, 15, 8, 300, 3500);

            Assert.AreEqual(date + expectedForwardTime, (date + startTime).PlusTicks(4000));
            Assert.AreEqual(date + expectedBackwardTime, (date + startTime).PlusTicks(-4000));
        }
Esempio n. 9
0
        public void PlusNanoseconds_Simple()
        {
            // Just use the ticks values
            LocalDate date                 = new LocalDate(2011, 4, 2);
            LocalTime startTime            = LocalTime.FromHourMinuteSecondMillisecondTick(12, 15, 8, 300, 7500);
            LocalTime expectedForwardTime  = LocalTime.FromHourMinuteSecondMillisecondTick(12, 15, 8, 300, 7540);
            LocalTime expectedBackwardTime = LocalTime.FromHourMinuteSecondMillisecondTick(12, 15, 8, 300, 7460);

            Assert.AreEqual(date + expectedForwardTime, (date + startTime).PlusNanoseconds(4000));
            Assert.AreEqual(date + expectedBackwardTime, (date + startTime).PlusNanoseconds(-4000));
        }
            public void ShouldSerializeAndDeserialize()
            {
                // Arrange
                var value = LocalTime.FromHourMinuteSecondMillisecondTick(1, 2, 3, 4, 5).PlusNanoseconds(67);
                var json  = "\"01:02:03.004000567\"";

                var options = new JsonSerializerOptions();

                options.Converters.Add(NodaConverters.LocalTimeConverter);

                // Act
                var seri   = JsonSerializer.Serialize(value, options);
                var deseri = JsonSerializer.Deserialize <LocalTime>(seri, options);

                // Assert
                Assert.AreEqual(json, seri);
                Assert.AreEqual(value, deseri);
            }
Esempio n. 11
0
 public LocalTime ConstructionToTick() => LocalTime.FromHourMinuteSecondMillisecondTick(15, 10, 25, 500, 1234);
 public void FromHourMinuteSecondMillisecondTick_Invalid(int hour, int minute, int second, int millisecond, int tick)
 {
     Assert.Throws <ArgumentOutOfRangeException>(
         () => LocalTime.FromHourMinuteSecondMillisecondTick(hour, minute, second, millisecond, tick));
 }
Esempio n. 13
0
        public void XmlSerialization()
        {
            var value = LocalTime.FromHourMinuteSecondMillisecondTick(17, 53, 23, 123, 4567);

            TestHelper.AssertXmlRoundtrip(value, "<value>17:53:23.1234567</value>");
        }
Esempio n. 14
0
 public void BinarySerialization()
 {
     TestHelper.AssertBinaryRoundtrip(LocalTime.FromHourMinuteSecondMillisecondTick(12, 34, 56, 123, 4567));
 }