Ejemplo n.º 1
0
        public void TestParse()
        {
            CheckParse("-0000091024123456", "ddddddddddHHmmss", new HdTimeSpan(-91024, -12, -34, -56));

            CheckParse("5", "s", HdTimeSpan.FromSeconds(5));
            CheckParse("0", "s", HdTimeSpan.FromSeconds(0));
            CheckParse("005", "s", HdTimeSpan.FromSeconds(5));

            CheckParse("12:34:56", "H:m:s", new HdTimeSpan(12, 34, 56));
            CheckParse("12:34:56", "HH:mm:ss", new HdTimeSpan(12, 34, 56));

            CheckParse("1024T12:34:56", "dTH:m:s", new HdTimeSpan(1024, 12, 34, 56));
            CheckParse("1024T12:34:56", "d'T'H:m:s", new HdTimeSpan(1024, 12, 34, 56));

            // Unseparated fixed width fields
            CheckParse("123", "ss", HdTimeSpan.FromSeconds(12));
            CheckParse("123456", "HHmmss", new HdTimeSpan(12, 34, 56));
            CheckParse("1024123456", "ddddHHmmss", new HdTimeSpan(1024, 12, 34, 56));
            CheckParse("91024123456", "dddddHHmmss", new HdTimeSpan(91024, 12, 34, 56));
            CheckParse("0000091024123456", "ddddddddddHHmmss", new HdTimeSpan(91024, 12, 34, 56));
            CheckParse("101024123456", "ddddddHHmmss", new HdTimeSpan(101024, 12, 34, 56));

            // Sign
            CheckParse("-5", "s", HdTimeSpan.FromSeconds(-5));
            CheckParse("-1024T12:34:56", "dTH:m:s", new HdTimeSpan(-1024, -12, -34, -56));
            CheckParse("-123456", "HHmmss", new HdTimeSpan(-12, -34, -56));
            CheckParse("-0000091024123456", "ddddddddddHHmmss", new HdTimeSpan(-91024, -12, -34, -56));

            // Fractions (Only fixed length patterns supported)
            CheckParse("4.2", "s.f", HdTimeSpan.FromMilliseconds(4200));
            CheckParse("4.200000", "s.ffffff", HdTimeSpan.FromMilliseconds(4200));
            CheckParse("4.020", "s.ff", HdTimeSpan.FromMilliseconds(4020));
            CheckParse("4.200000000", "s.fffffffff", HdTimeSpan.FromMilliseconds(4200));
            CheckParse("4.000000002", "s.fffffffff", HdTimeSpan.FromNanoseconds(4000000002L));

            CheckParse("4.2", "s.S", HdTimeSpan.FromMilliseconds(4200));
            CheckParse("4.123", "s.SSS", HdTimeSpan.FromMilliseconds(4123));
        }
Ejemplo n.º 2
0
        public void TestFormat()
        {
            // Plain numbers
            CheckPrint("34627623,.45634", "34627623,.45634", HdTimeSpan.FromSeconds(12), false);

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

            // Seconds
            CheckPrint("12", "s", HdTimeSpan.FromSeconds(12));
            CheckPrint("0", "s", HdTimeSpan.FromSeconds(0));
            CheckPrint("00", "ss", HdTimeSpan.FromSeconds(0));
            CheckPrint("005", "0ss", HdTimeSpan.FromSeconds(65));
            CheckPrint("000005", "ssssss", HdTimeSpan.FromSeconds(65));

            // Seconds & Fractions of Second. 'S' and 'f' are now synonyms
            CheckPrint("12.3", "s.S", HdTimeSpan.FromMilliseconds(12_300));
            CheckPrint("0.345", "s.SSS", HdTimeSpan.FromMicroseconds(345_000));
            CheckPrint("00.023", "ss.SSS", HdTimeSpan.FromMilliseconds(600_023));
            CheckPrint("05.123", "ss.SSS", HdTimeSpan.FromMilliseconds(65_123));
            CheckPrint("05.123000", "ss.SSSSSS", HdTimeSpan.FromMilliseconds(65_123));

            CheckPrint("05.0001", "ss.ffff", HdTimeSpan.FromMicroseconds(65_000_123));
            CheckPrint("05.00012", "ss.fffff", HdTimeSpan.FromMicroseconds(65_000_123));
            CheckPrint("05.000123", "ss.ffffff", HdTimeSpan.FromMicroseconds(65_000_123));
            CheckPrint("05.123000", "ss.ffffff", HdTimeSpan.FromNanoseconds(65_123_000_123L));
            CheckPrint("05.123000", "ss.ffffff", HdTimeSpan.FromNanoseconds(65_123_000_999L));
            CheckPrint("05.123000", "ss.ffffff", HdTimeSpan.FromNanoseconds(65_123_000_999L));
            CheckPrint("05.1230009", "ss.fffffff", HdTimeSpan.FromNanoseconds(65_123_000_999L));
            CheckPrint("05.12300012", "ss.ffffffff", HdTimeSpan.FromNanoseconds(65_123_000_123L));
            CheckPrint("05.123000123", "ss.fffffffff", HdTimeSpan.FromNanoseconds(65_123_000_123L));
            CheckPrint("05.000000123", "ss.fffffffff", HdTimeSpan.FromNanoseconds(65_000_000_123L));
            CheckPrint("5.000123000", "s.fffffffff", HdTimeSpan.FromNanoseconds(65_000_123_000L));

            // Minutes
            CheckPrint("5", "m", HdTimeSpan.FromMinutes(425));
            CheckPrint("7", "m", HdTimeSpan.FromSeconds(425));
            CheckPrint("05", "mm", HdTimeSpan.FromMinutes(425));
            CheckPrint("00005", "0mmmm", HdTimeSpan.FromMinutes(425));

            // Hours
            CheckPrint("5", "H", HdTimeSpan.FromHours(48 + 5));
            CheckPrint("4", "H", HdTimeSpan.FromMinutes(245));
            CheckPrint("07", "HH", HdTimeSpan.FromMinutes(425));
            CheckPrint("0007005", "0HHHmmm", HdTimeSpan.FromMinutes(425));
            CheckPrint("07:5.789", "HH:m.SSS", HdTimeSpan.FromMinutes(425).Add(HdTimeSpan.FromMilliseconds(789)));

            // Sign insertion
            CheckPrint("-12", "s", HdTimeSpan.FromSeconds(-12));
            CheckPrint("-0", "s", HdTimeSpan.FromMilliseconds(-1));
            CheckPrint("-05", "ss", HdTimeSpan.FromSeconds(-425));

            // "Advanced" sign insertion
            CheckPrint("-000005", "ssssss", HdTimeSpan.FromSeconds(-425));
            CheckPrint("-00000005", "00ssssss", HdTimeSpan.FromSeconds(-425));
            CheckPrint("Abc-00000005", "Abc00ssssss", HdTimeSpan.FromSeconds(-425));
            CheckPrint("Abcmsy-00000005", "'Abcmsy'00ssssss", HdTimeSpan.FromSeconds(-425));
            CheckPrint(";.:-000005", ";.:ssssss", HdTimeSpan.FromSeconds(-425));
            CheckPrint(";.:-00000005", ";.:00ssssss", HdTimeSpan.FromSeconds(-425));
        }