public void ToIso8601StringWithFractionalSeconds(int year, int month, int day, int hour, int minute, double second, string expectedIsoString)
        {
            var    gregorianDate = new GregorianDate(year, month, day, hour, minute, second);
            string isoString     = gregorianDate.ToIso8601String(Iso8601Format.Extended, 6);

            Assert.AreEqual(expectedIsoString, isoString);
        }
        public void ToIso8601CompactStringProducesCorrectStrings(int year, int month, int day, int hour, int minute, double second, string expectedIsoString)
        {
            var    gregorianDate = new GregorianDate(year, month, day, hour, minute, second);
            string isoString     = gregorianDate.ToIso8601String(Iso8601Format.Compact);

            Assert.AreEqual(expectedIsoString, isoString);
        }
        public void ToIso8601StringWithFractionalSeconds()
        {
            GregorianDate gd = new GregorianDate(2012, 8, 7, 13, 59, 59.9999999);

            Assert.AreEqual("2012-08-07T13:59:59.999999Z", gd.ToIso8601String(Iso8601Format.Extended, 6));

            // Leap second test cases.
            gd = new GregorianDate(2012, 6, 30, 23, 59, 59.999999);
            Assert.AreEqual("2012-06-30T23:59:59.999999Z", gd.ToIso8601String(Iso8601Format.Extended, 6));

            gd = new GregorianDate(2012, 6, 30, 23, 59, 59.99999949999999);
            Assert.AreEqual("2012-06-30T23:59:59.999999Z", gd.ToIso8601String(Iso8601Format.Extended, 6));

            gd = new GregorianDate(2012, 6, 30, 23, 59, 59.99999950000000);
            Assert.AreEqual("2012-06-30T23:59:59.999999Z", gd.ToIso8601String(Iso8601Format.Extended, 6));

            gd = new GregorianDate(2012, 6, 30, 23, 59, 60.0);
            Assert.AreEqual("2012-06-30T23:59:60.000000Z", gd.ToIso8601String(Iso8601Format.Extended, 6));

            gd = new GregorianDate(2012, 6, 30, 23, 59, 60.99999949999999);
            Assert.AreEqual("2012-06-30T23:59:60.999999Z", gd.ToIso8601String(Iso8601Format.Extended, 6));

            gd = new GregorianDate(2012, 6, 30, 23, 59, 60.99999950000000);
            Assert.AreEqual("2012-06-30T23:59:60.999999Z", gd.ToIso8601String(Iso8601Format.Extended, 6));
        }
        public void TestParseIso8601FormatBasic()
        {
            GregorianDate date      = new GregorianDate(1985, 4, 12, 10, 15, 30);
            string        isoString = date.ToIso8601String(Iso8601Format.Basic);
            GregorianDate parsed    = GregorianDate.Parse(isoString);

            Assert.AreEqual(date, parsed);
        }
Пример #5
0
        public void TestParseIso8601FormatBasic()
        {
            GregorianDate g1  = new GregorianDate(1985, 4, 12, 10, 15, 30);
            string        s1  = g1.ToIso8601String(Iso8601Format.Basic);
            GregorianDate gp1 = GregorianDate.Parse(s1);

            Assert.AreEqual(g1, gp1);
        }
        public void ToIso8601Validation(GregorianDate date)
        {
            // found this regex online
            var regex = new Regex(@"^([\+-]?\d{4}(?!\d{2}\b))((-?)((0[1-9]|1[0-2])(\3([12]\d|0[1-9]|3[01]))?|W([0-4]\d|5[0-2])(-?[1-7])?|(00[1-9]|0[1-9]\d|[12]\d{2}|3([0-5]\d|6[1-6])))([T\s]((([01]\d|2[0-3])((:?)[0-5]\d)?|24\:?00)([\.,]\d+(?!:))?)?(\17[0-5]\d([\.,]\d+)?)?([zZ]|([\+-])([01]\d|2[0-3]):?([0-5]\d)?)?)?)?$");

            string s = date.ToIso8601String();

            Assert.IsTrue(regex.IsMatch(s));

            s = date.ToIso8601String(Iso8601Format.Basic);
            Assert.IsTrue(regex.IsMatch(s));
            s = date.ToIso8601String(Iso8601Format.Compact);
            Assert.IsTrue(regex.IsMatch(s));
            s = date.ToIso8601String(Iso8601Format.Extended);
            Assert.IsTrue(regex.IsMatch(s));

            for (int numDigits = 0; numDigits <= 15; ++numDigits)
            {
                s = date.ToIso8601String(Iso8601Format.Basic, numDigits);
                Assert.IsTrue(regex.IsMatch(s));
                s = date.ToIso8601String(Iso8601Format.Compact, numDigits);
                Assert.IsTrue(regex.IsMatch(s));
                s = date.ToIso8601String(Iso8601Format.Extended, numDigits);
                Assert.IsTrue(regex.IsMatch(s));
            }
        }
Пример #7
0
        public void MaxValueRoundTripsThroughJulianDate()
        {
            JulianDate    max      = GregorianDate.MaxValue.ToJulianDate();
            GregorianDate date     = max.ToGregorianDate();
            string        iso      = date.ToIso8601String(Iso8601Format.Extended, 6);
            string        expected = GregorianDate.MaxValue.ToIso8601String(Iso8601Format.Extended, 6);

            Assert.AreEqual(expected, iso);
        }
        public void TestToIso8601String()
        {
            // Full format
            const string  isoString = "1985-04-12T10:15:30Z";
            GregorianDate iso       = new GregorianDate(1985, 4, 12, 10, 15, 30);
            GregorianDate result    = GregorianDate.Parse(isoString);

            Assert.AreEqual(iso, result);
            string resultString = result.ToIso8601String();

            Assert.AreEqual(isoString, resultString);
            Assert.AreEqual(isoString, iso.ToIso8601String());
        }
Пример #9
0
        public void TestParseIso8601Formats(Iso8601Format format)
        {
            GregorianDate expected = new GregorianDate(1985, 4, 12, 10, 15, 30);

            Assert.AreEqual(expected, GregorianDate.Parse(expected.ToIso8601String(format)));

            expected = new GregorianDate(1985, 4, 12, 10, 15, 0);
            Assert.AreEqual(expected, GregorianDate.Parse(expected.ToIso8601String(format)));

            expected = new GregorianDate(1985, 4, 12, 10, 0, 0);
            Assert.AreEqual(expected, GregorianDate.Parse(expected.ToIso8601String(format)));

            expected = new GregorianDate(1985, 4, 12, 0, 0, 0);
            Assert.AreEqual(expected, GregorianDate.Parse(expected.ToIso8601String(format)));
        }
 public void TestToISO8601String()
 {
     // Full format
     string isoString = "1985-04-12T10:15:30Z";
     GregorianDate iso = new GregorianDate(1985, 4, 12, 10, 15, 30);
     GregorianDate result = GregorianDate.Parse(isoString);
     Assert.AreEqual(iso, result);
     string resultString = result.ToIso8601String();
     Assert.AreEqual(isoString, resultString);
     Assert.AreEqual(isoString, iso.ToIso8601String());
 }