Ejemplo n.º 1
0
        public void Validate_ToJavaMilliseconds(DateTime testValue)
        {
            Int64      javaMillisecondsModulo;
            HdDateTime d1 = new HdDateTime(testValue);
            Int64      javaMilliseconds = DateConverter.ToEpochMilliseconds(testValue, out javaMillisecondsModulo);
            DateTime   timestamp        = HdDateTime.FromEpochMilliseconds(javaMilliseconds, javaMillisecondsModulo).DateTime;

            Assert.AreEqual(testValue, d1.DateTime);
            //Assert.AreEqual(timestamp.Ticks, testValue.Ticks, String.Format("{0} != {1}", timestamp.Ticks, testValue.Ticks));
            Assert.AreEqual(testValue, timestamp, String.Format("{0} != {1}", timestamp.Ticks, testValue.Ticks));
        }
Ejemplo n.º 2
0
        public void Validate_PreciseTimestamp(DateTime testTimestamp, Byte testTimestampModulo)
        {
            HdDateTime testTime = new HdDateTime(testTimestamp, testTimestampModulo);
            HdDateTime testTimeFromNanoseconds  = new HdDateTime(testTime.EpochNanoseconds);
            HdDateTime testTimeFromMilliseconds =
                HdDateTime.FromEpochMilliseconds(testTime.EpochMilliseconds, testTime.EpochMillisecondsModulo);
            HdDateTime testTimeFromTimestamp =
                new HdDateTime(testTime.DateTime, testTime.TimestampModulo);

            Assert.AreEqual(testTime.EpochNanoseconds, testTimeFromNanoseconds.EpochNanoseconds);
            Assert.AreEqual(testTime.EpochNanoseconds, testTimeFromMilliseconds.EpochNanoseconds);
            Assert.AreEqual(testTime.EpochNanoseconds, testTimeFromTimestamp.EpochNanoseconds);
            Assert.AreEqual(testTime, testTimeFromNanoseconds);
            Assert.AreEqual(testTime, testTimeFromMilliseconds);
            Assert.AreEqual(testTime, testTimeFromTimestamp);
        }
Ejemplo n.º 3
0
        public void TestMinMaxConstantsExtra()
        {
            HdDateTime maxValue = HdDateTime.MaxValue;
            HdDateTime minValue = HdDateTime.MinValue;

            var nanosMin = 100 - ((DateTime)minValue.AddTicks(1) - minValue).TotalNanoseconds;
            var nanosMax = (maxValue.AddTicks(-1) - (DateTime)(maxValue.AddTicks(-1))).TotalNanoseconds;

            var secondNanosMin = 1000000000 + minValue.AddSeconds(1).EpochNanoseconds % 1000000000;
            var secondNanosMax = maxValue.EpochNanoseconds % 1000000000;

            Assert.True(nanosMax == maxValue.AddTicks(-1).TimestampModulo);
            Assert.True(nanosMin == minValue.AddTicks(1).TimestampModulo);

            Assert.True(nanosMax == secondNanosMax % 100);
            Assert.True(nanosMin == secondNanosMin % 100);

            Assert.AreEqual(minValue.EpochNanoseconds, new HdDateTime((DateTime)minValue.AddTicks(1), (Byte)nanosMin).AddTicks(-1).EpochNanoseconds);
            Assert.True(minValue == new HdDateTime((DateTime)minValue.AddTicks(1), (Byte)nanosMin).AddTicks(-1));
            Assert.AreEqual(maxValue.EpochNanoseconds, new HdDateTime((DateTime)maxValue.AddTicks(-1), (Byte)nanosMax).AddTicks(1).EpochNanoseconds);
            Assert.True(maxValue == new HdDateTime((DateTime)maxValue.AddTicks(-1), (Byte)nanosMax).AddTicks(1));

            Assert.AreEqual(maxValue.EpochNanoseconds, HdDateTime.FromEpochMilliseconds(maxValue.EpochNanoseconds / 1000000000 * 1000, secondNanosMax).EpochNanoseconds);
        }
Ejemplo n.º 4
0
        public void TestParse()
        {
            CheckParse("2109", "yyyy", new HdDateTime(2109, 1, 1));
            CheckParse("1864", "yyyy", new HdDateTime(1864, 1, 1));

            CheckParse("197005", "yyyyMM", new HdDateTime(1970, 5, 1));
            CheckParse("19700531 ", "yyyyMMdd ", new HdDateTime(1970, 5, 31));

            CheckParse("19700531 13", "yyyyMMdd HH",
                       new HdDateTime(1970, 5, 31, 13, 0, 0));

            CheckParse("19700531 1342", "yyyyMMdd HHmm",
                       new HdDateTime(1970, 5, 31, 13, 42, 0));

            CheckParse("19700531 134259", "yyyyMMdd HHmmss",
                       new HdDateTime(1970, 5, 31, 13, 42, 59));

            CheckParse("19700101000000", "yyyyMMddHHmmss", HdDateTime.FromEpochMilliseconds(0));
            CheckParse("197001010000000", "yyyyMMddHHmmssf", HdDateTime.FromEpochMilliseconds(0));
            CheckParse("1970010100000000", "yyyyMMddHHmmssff", HdDateTime.FromEpochMilliseconds(0));
            CheckParse("19700101000000000", "yyyyMMddHHmmssfff", HdDateTime.FromEpochMilliseconds(0));
            CheckParse("197001010000000000", "yyyyMMddHHmmssffff", HdDateTime.FromEpochMilliseconds(0));
            CheckParse("1970010100000000000", "yyyyMMddHHmmssfffff", HdDateTime.FromEpochMilliseconds(0));
            CheckParse("19700101000000000000", "yyyyMMddHHmmssffffff", HdDateTime.FromEpochMilliseconds(0));
            CheckParse("197001010000000000000", "yyyyMMddHHmmssfffffff", HdDateTime.FromEpochMilliseconds(0));
            CheckParse("1970010100000000000000", "yyyyMMddHHmmssffffffff", HdDateTime.FromEpochMilliseconds(0));
            CheckParse("19700101000000000000000", "yyyyMMddHHmmssfffffffff", HdDateTime.FromEpochMilliseconds(0));
            CheckParse("197012345678901010000000", "yyyyfffffffffMMddHHmmss",
                       HdDateTime.FromEpochNanoseconds(123456789));
            CheckParse("197012345678901010000000123456789", "yyyyfffffffffMMddHHmmss",
                       HdDateTime.FromEpochNanoseconds(123456789));

            CheckParse("197001010000 5", "yyyyMMddHHmm s", HdDateTime.FromEpochMilliseconds(5000));
            CheckParse("197001010000 0", "yyyyMMddHHmm s", HdDateTime.FromEpochMilliseconds(0));
            CheckParse("197001010000 005", "yyyyMMddHHmm s", HdDateTime.FromEpochMilliseconds(5000));

            CheckParse("19700101 12:34:56", "yyyyMMdd H:m:s",
                       new HdDateTime(1970, 1, 1, 12, 34, 56));

            CheckParse("19700101 9:8:7", "yyyyMMdd H:m:s",
                       new HdDateTime(1970, 1, 1, 9, 8, 7));

            CheckParse("19700101 12:34:56", "yyyyMMdd HH:mm:ss",
                       new HdDateTime(1970, 1, 1, 12, 34, 56));

            CheckParse("197001 24T12:34:56", "yyyyMM ddTH:m:s",
                       new HdDateTime(1970, 1, 24, 12, 34, 56));
            CheckParse("197001 24T12:34:56", "yyyyMM dd'T'H:m:s",
                       new HdDateTime(1970, 1, 24, 12, 34, 56));

            CheckParse("197001 0024123456", "yyyyMM ddddHHmmss",
                       new HdDateTime(1970, 1, 24, 12, 34, 56));
            CheckParse("197001 0000000024123456", "yyyyMM ddddddddddHHmmss",
                       new HdDateTime(1970, 1, 24, 12, 34, 56));

            CheckParse("1999-11-22 19:18:17", "y-M-d H:m:s",
                       new HdDateTime(1999, 11, 22, 19, 18, 17));

            // Fractions (Only fixed length patterns supported)
            CheckParse("197001010000 4.2", "yyyyMMddHHmm s.f", HdDateTime.FromEpochMilliseconds(4200));
            CheckParse("197001010000 4.200000", "yyyyMMddHHmm s.ffffff", HdDateTime.FromEpochMilliseconds(4200));
            CheckParse("197001010000 4.020", "yyyyMMddHHmm s.ff", HdDateTime.FromEpochMilliseconds(4020));
            CheckParse("197001010000 4.200000000", "yyyyMMddHHmm s.fffffffff", HdDateTime.FromEpochMilliseconds(4200));
            CheckParse("197001010000 4.000000002", "yyyyMMddHHmm s.fffffffff", HdDateTime.FromEpochNanoseconds(4000000002L));

            CheckParse("197001010000 4.2", "yyyyMMddHHmm s.S", HdDateTime.FromEpochMilliseconds(4200));
            CheckParse("197001010000 4.123", "yyyyMMddHHmm s.SSS", HdDateTime.FromEpochMilliseconds(4123));
        }
Ejemplo n.º 5
0
        public void TestFormat2()
        {
            // Plain numbers
            CheckPrint("34627623,.45634", "34627623,.45634", HdDateTime.FromEpochMilliseconds(12));

            // Check quoted text
            CheckPrint("Abcmsy", "'Abcmsy'", HdDateTime.FromEpochMilliseconds(0));
            CheckPrint("00Abcmsy000", "00'Abcmsy'000", HdDateTime.FromEpochMilliseconds(0));
            CheckPrint("'Abc'msy", "'''Abc''msy'", HdDateTime.FromEpochMilliseconds(0));
            CheckPrint("0'0Abc''msy00'0", "0''0'Abc''''msy'00''0", HdDateTime.FromEpochMilliseconds(0));

            // Seconds
            CheckPrint("12", "s", HdDateTime.FromEpochMilliseconds(12000));
            CheckPrint("0", "s", HdDateTime.FromEpochMilliseconds(0));
            CheckPrint("00", "ss", HdDateTime.FromEpochMilliseconds(0));
            CheckPrint("005", "0ss", HdDateTime.FromEpochMilliseconds(65000));
            CheckPrint("000005", "ssssss", HdDateTime.FromEpochMilliseconds(65000));

            // Seconds & Fractions of Second. 'S' and 'f' are now synonyms
            CheckPrint("05.0001", "ss.ffff", HdDateTime.FromEpochNanoseconds(65_000_123_000L));
            CheckPrint("05.00012", "ss.fffff", HdDateTime.FromEpochNanoseconds(65_000_123_000L));
            CheckPrint("05.000123", "ss.ffffff", HdDateTime.FromEpochNanoseconds(65_000_123_000L));
            CheckPrint("05.123000", "ss.ffffff", HdDateTime.FromEpochNanoseconds(65_123_000_123L));
            CheckPrint("05.123000", "ss.ffffff", HdDateTime.FromEpochNanoseconds(65_123_000_999L));
            CheckPrint("05.123000", "ss.ffffff", HdDateTime.FromEpochNanoseconds(65_123_000_999L));
            CheckPrint("05.1230009", "ss.fffffff", HdDateTime.FromEpochNanoseconds(65_123_000_999L));
            CheckPrint("05.12300012", "ss.ffffffff", HdDateTime.FromEpochNanoseconds(65_123_000_123L));
            CheckPrint("05.123000123", "ss.fffffffff", HdDateTime.FromEpochNanoseconds(65_123_000_123L));
            CheckPrint("05.000000123", "ss.fffffffff", HdDateTime.FromEpochNanoseconds(65_000_000_123L));
            CheckPrint("5.000123000", "s.fffffffff", HdDateTime.FromEpochNanoseconds(65_000_123_000L));

            CheckPrint("12.3", "s.S", HdDateTime.FromEpochMilliseconds(12_300));
            CheckPrint("0.345", "s.SSS", HdDateTime.FromEpochNanoseconds(345_000_000));
            CheckPrint("00.023", "ss.SSS", HdDateTime.FromEpochMilliseconds(600_023));
            CheckPrint("05.123", "ss.SSS", HdDateTime.FromEpochMilliseconds(65_123));
            CheckPrint("05.123000", "ss.SSSSSS", HdDateTime.FromEpochMilliseconds(65_123));

            // Minutes
            CheckPrint("5", "m", HdDateTime.Now.Date.AddMinutes(425));
            CheckPrint("7", "m", HdDateTime.FromEpochMilliseconds(425_000));
            CheckPrint("05", "mm", HdDateTime.Now.Date.AddMinutes(425));
            CheckPrint("00005", "0mmmm", HdDateTime.Now.Date.AddMinutes(425));

            // Hours
            CheckPrint("5", "H", HdDateTime.Now.Date.AddHours(48 + 5));
            CheckPrint("4", "H", HdDateTime.Now.Date.AddMinutes(245));
            CheckPrint("07", "HH", HdDateTime.Now.Date.AddMinutes(425));
            CheckPrint("0007005", "0HHHmmm", HdDateTime.Now.Date.AddMinutes(425));
            CheckPrint("07:5.789", "HH:m.SSS", HdDateTime.Now.Date.AddMinutes(425).AddMilliseconds(789));

            CheckPrint("0007005", "0HHHmmm", HdDateTime.Now.Date.AddMinutes(425));
            CheckPrint("1999-4-1 0:7:5.656789", "yyyy-M-d H:m:s.SSSSSS",
                       new HdDateTime(1999, 4, 1).AddSeconds(425).AddNanoseconds(656789000));

            CheckPrint("1999-4-1 0:7:5.656789", "yyyy-M-d H:m:s.SSSSSS",
                       new HdDateTime(1999, 4, 1, 0, 7, 5, 656789000));
            CheckPrint("990401000705656789", "yyMMddHHmmssSSSSSS",
                       new HdDateTime(1999, 4, 1).AddSeconds(425).AddNanoseconds(656789000));
            CheckPrint("1999Apr01000705656789999", "yyyMMMddHHmmssSSSSSSSSS",
                       new HdDateTime(1999, 4, 1).AddSeconds(425).AddNanoseconds(656789999));

            CheckPrint("2002-January-01", "y-MMMM-dd", new HdDateTime(2002, 1, 1));
            CheckPrint("31 May 2002", "d MMMM yyy", new HdDateTime(2002, 5, 31));
            CheckPrint("31       May 2002", "dMMMMMMMMMM yyy", new HdDateTime(2002, 5, 31));
            CheckPrint("31  December 2002", "dMMMMMMMMMM yyy", new HdDateTime(2002, 12, 31));

            CheckPrint("1910-4-1 0:7:5.656789", "yyyy-M-d H:m:s.ffffff",
                       new HdDateTime(1910, 4, 1).AddSeconds(425).AddNanoseconds(656789000));

            CheckPrint("1910-4-1 0:7:5.656789", "yyyy-M-d H:m:s.ffffff",
                       new HdDateTime(1910, 4, 1).AddSeconds(425).AddNanoseconds(656789000));

            CheckPrint("1866-1-22 20:40:40.123456789", "yyyy-M-d H:m:s.fffffffff",
                       new HdDateTime(1866, 1, 22, 20, 40, 40, 123456789));
        }