예제 #1
0
        public void SimpleProperties()
        {
            var value = SampleZone.AtStrictly(new LocalDateTime(2012, 2, 10, 8, 9, 10).PlusNanoseconds(123456789));

            Assert.AreEqual(new LocalDate(2012, 2, 10), value.Date);
            Assert.AreEqual(LocalTime.FromHourMinuteSecondNanosecond(8, 9, 10, 123456789), value.TimeOfDay);
            Assert.AreEqual(Era.Common, value.Era);
            Assert.AreEqual(2012, value.Year);
            Assert.AreEqual(2012, value.YearOfEra);
            Assert.AreEqual(2, value.Month);
            Assert.AreEqual(10, value.Day);
            Assert.AreEqual(IsoDayOfWeek.Friday, value.DayOfWeek);
            Assert.AreEqual(41, value.DayOfYear);
            Assert.AreEqual(8, value.ClockHourOfHalfDay);
            Assert.AreEqual(8, value.Hour);
            Assert.AreEqual(9, value.Minute);
            Assert.AreEqual(10, value.Second);
            Assert.AreEqual(123, value.Millisecond);
            Assert.AreEqual(1234567, value.TickOfSecond);
            Assert.AreEqual(8 * NodaConstants.TicksPerHour +
                            9 * NodaConstants.TicksPerMinute +
                            10 * NodaConstants.TicksPerSecond +
                            1234567,
                            value.TickOfDay);
            Assert.AreEqual(8 * NodaConstants.NanosecondsPerHour +
                            9 * NodaConstants.NanosecondsPerMinute +
                            10 * NodaConstants.NanosecondsPerSecond +
                            123456789,
                            value.NanosecondOfDay);
        }
예제 #2
0
        public static LocalTime CreateLocalTime(decimal hours, decimal mins, decimal secs)
        {
            long nsecs          = 0;
            var  xsecsfractions = secs - Math.Truncate(secs);

            if (xsecsfractions > 0)
            {
                nsecs = (long)(xsecsfractions * 1000000000);
            }

            if (nsecs > 0)
            {
                return(LocalTime.FromHourMinuteSecondNanosecond((int)hours, (int)mins, (int)secs, nsecs));
            }

            return(new LocalTime((int)hours, (int)mins, (int)secs));
        }
예제 #3
0
        public void XmlSerialization()
        {
            var value = LocalTime.FromHourMinuteSecondNanosecond(17, 53, 23, 123456789);

            TestHelper.AssertXmlRoundtrip(value, "<value>17:53:23.123456789</value>");
        }
예제 #4
0
 public void BinarySerialization()
 {
     TestHelper.AssertBinaryRoundtrip(LocalTime.FromHourMinuteSecondNanosecond(12, 34, 56, 123456789));
 }
예제 #5
0
 public void GenerateCodeLiteral_returns_local_time_literal()
 {
     Assert.Equal("new NodaTime.LocalTime(9, 30)", CodeLiteral(new LocalTime(9, 30)));
     Assert.Equal("new NodaTime.LocalTime(9, 30, 15)", CodeLiteral(new LocalTime(9, 30, 15)));
     Assert.Equal("NodaTime.LocalTime.FromHourMinuteSecondNanosecond(9, 30, 15, 500000000L)", CodeLiteral(new LocalTime(9, 30, 15, 500)));
     Assert.Equal("NodaTime.LocalTime.FromHourMinuteSecondNanosecond(9, 30, 15, 1L)", CodeLiteral(LocalTime.FromHourMinuteSecondNanosecond(9, 30, 15, 1)));
 }
 public void FromHourMinuteSecondNanosecond_Invalid(int hour, int minute, int second, long nanosecond)
 {
     Assert.Throws <ArgumentOutOfRangeException>(
         () => LocalTime.FromHourMinuteSecondNanosecond(hour, minute, second, nanosecond));
 }