Ejemplo n.º 1
0
        public void TestTryParseISO8601DayOfYear()
        {
            GregorianDate iso = new GregorianDate(1985, 2, 11, 2, 0, 5.2134);
            GregorianDate result;

            if (!GregorianDate.TryParse("1985-042T02:00:05.2134", out result))
            {
                Assert.Fail();
            }
            Assert.AreEqual(iso, result);
            iso = new GregorianDate(1985, 2, 11, 2, 0, 5.21345);
            if (!GregorianDate.TryParse("1985-042T02:00:05.21345Z", out result))
            {
                Assert.Fail();
            }
            Assert.AreEqual(iso, result);
            iso = new GregorianDate(1985, 2, 11, 2, 0, 5);
            if (!GregorianDate.TryParse("1985-042T02:00:05", out result))
            {
                Assert.Fail();
            }
            Assert.AreEqual(iso, result);
            iso = new GregorianDate(1985, 2, 11);
            if (!GregorianDate.TryParse("1985-042", out result))
            {
                Assert.Fail();
            }
            Assert.AreEqual(iso, result);

            Assert.IsFalse(GregorianDate.TryParse("1985-367T02:00:05.2134", out result));
            Assert.IsFalse(GregorianDate.TryParse("1985-12#T02:00:05.2134", out result));
            Assert.IsFalse(GregorianDate.TryParse("21985-167T02:00:05.2134", out result));
        }
Ejemplo n.º 2
0
        private static TimeInterval GetTimeSpan(XElement timespan, XNamespace docNamespace)
        {
            XElement   beginElement = timespan.Element(docNamespace + "begin");
            JulianDate begin        = new JulianDate(GregorianDate.MinValue);
            JulianDate end          = new JulianDate(GregorianDate.MaxValue);

            if (beginElement != null)
            {
                GregorianDate beginDate;
                if (!GregorianDate.TryParse(beginElement.Value, out beginDate))
                {
                    beginDate = GregorianDate.ParseExact(beginElement.Value, ValidIso8601Formats, CultureInfo.CurrentCulture);
                }
                begin = new JulianDate(beginDate);
            }
            XElement endElement = timespan.Element(docNamespace + "end");

            if (endElement != null)
            {
                GregorianDate endDate;
                if (!GregorianDate.TryParse(endElement.Value, out endDate))
                {
                    endDate = GregorianDate.ParseExact(endElement.Value, ValidIso8601Formats, CultureInfo.CurrentCulture);
                }
                end = new JulianDate(endDate);
            }
            return(new TimeInterval(begin, end));
        }
        public void CannotParseInvalidDates()
        {
            GregorianDate result;

            Assert.IsFalse(GregorianDate.TryParse("02/29/2002", m_cultureInfo, out result));
            Assert.AreEqual(GregorianDate.MinValue, result);

            Assert.IsFalse(GregorianDate.TryParse("13/01/2002", m_cultureInfo, out result));
        }
Ejemplo n.º 4
0
        private JulianDate ToJulianDate(string when)
        {
            GregorianDate whenDate;

            if (!GregorianDate.TryParse(when, out whenDate))
            {
                whenDate = GregorianDate.ParseExact(when, Utility.ValidIso8601Formats, CultureInfo.CurrentCulture);
            }
            return(new JulianDate(whenDate));
        }
Ejemplo n.º 5
0
        public void TestTryParse()
        {
            GregorianDate expected = new GregorianDate(2002, 02, 25);
            GregorianDate result;

            Assert.AreEqual(true, GregorianDate.TryParse("02/25/2002", m_cultureInfo, out result));
            Assert.AreEqual(expected, result);

            Assert.AreEqual(false, GregorianDate.TryParse("02/q/2002", m_cultureInfo, out result));
            Assert.AreEqual(GregorianDate.MinValue, result);

            Assert.AreEqual(false, GregorianDate.TryParse(null, m_cultureInfo, out result));
            Assert.AreEqual(GregorianDate.MinValue, result);
        }
        public void TestTryParse()
        {
            GregorianDate expected = new GregorianDate(2002, 02, 25);
            GregorianDate result;

            Assert.IsTrue(GregorianDate.TryParse("02/25/2002", m_cultureInfo, out result));
            Assert.AreEqual(expected, result);

            Assert.IsFalse(GregorianDate.TryParse("02/q/2002", m_cultureInfo, out result));
            Assert.AreEqual(GregorianDate.MinValue, result);

            // ReSharper disable once ConditionIsAlwaysTrueOrFalse
            Assert.IsFalse(GregorianDate.TryParse(null, m_cultureInfo, out result));
            Assert.AreEqual(GregorianDate.MinValue, result);
        }
Ejemplo n.º 7
0
        private static TimeInterval GetTimeStamp(XElement timestamp, XNamespace docNamespace)
        {
            XElement whenElement = timestamp.Element(docNamespace + "when");

            if (whenElement != null)
            {
                GregorianDate whenDate;
                if (!GregorianDate.TryParse(whenElement.Value, out whenDate))
                {
                    whenDate = GregorianDate.ParseExact(whenElement.Value, ValidIso8601Formats, CultureInfo.CurrentCulture);
                }
                return(new TimeInterval(new JulianDate(whenDate), new JulianDate(GregorianDate.MaxValue)));
            }
            return(null);
        }
        public void TestParse()
        {
            GregorianDate expected = new GregorianDate(2002, 02, 25);

            Assert.AreEqual(expected, GregorianDate.Parse("02/25/2002", m_cultureInfo));
            Assert.AreEqual(expected, GregorianDate.Parse("2/25/2002", m_cultureInfo));
            Assert.AreEqual(expected, GregorianDate.Parse("2002-02-25", m_cultureInfo));
            Assert.AreEqual(expected, GregorianDate.Parse("2002-2-25", m_cultureInfo));
            Assert.AreEqual(expected, GregorianDate.Parse("Monday, 25 February 2002", m_cultureInfo));
            Assert.AreEqual(expected, GregorianDate.Parse("Mon,02/25/2002", m_cultureInfo));
            Assert.AreEqual(expected, GregorianDate.Parse("Mon,2/25/2002", m_cultureInfo));

            expected = new GregorianDate(2002, 02, 25, 05, 25, 00);
            Assert.AreEqual(expected, GregorianDate.Parse("Monday, 25 February 2002 05:25", m_cultureInfo));
            Assert.AreEqual(expected, GregorianDate.Parse("02/25/2002 05:25", m_cultureInfo));
            Assert.AreEqual(expected, GregorianDate.Parse("2/25/2002 05:25", m_cultureInfo));
            Assert.AreEqual(expected, GregorianDate.Parse("2/25/2002 5:25", m_cultureInfo));
            Assert.AreEqual(expected, GregorianDate.Parse("2002-02-25T05:25", m_cultureInfo));
            Assert.AreEqual(expected, GregorianDate.Parse("2002-2-25T05:25", m_cultureInfo));
            Assert.AreEqual(expected, GregorianDate.Parse("02-2002-25 05:25", m_cultureInfo));
            Assert.AreEqual(expected, GregorianDate.Parse("2-2002-25 05:25", m_cultureInfo));
            Assert.AreEqual(expected, GregorianDate.Parse("2-2002-25 5:25", m_cultureInfo));

            expected = new GregorianDate(2002, 02, 25, 05, 25, 13);
            Assert.AreEqual(expected, GregorianDate.Parse("Monday, 25 February 2002 05:25:13", m_cultureInfo));
            Assert.AreEqual(expected, GregorianDate.Parse("02/25/2002 05:25:13", m_cultureInfo));
            Assert.AreEqual(expected, GregorianDate.Parse("02/25/2002 5:25:13", m_cultureInfo));
            Assert.AreEqual(expected, GregorianDate.Parse("2/25/2002 5:25:13", m_cultureInfo));
            Assert.AreEqual(expected, GregorianDate.Parse("2002-02-25T05:25:13", m_cultureInfo));
            Assert.AreEqual(expected, GregorianDate.Parse("02-2002-25T05:25:13", m_cultureInfo));
            Assert.AreEqual(expected, GregorianDate.Parse("02-2002-25 05:25:13", m_cultureInfo));
            Assert.AreEqual(expected, GregorianDate.Parse("02-2002-25 5:25:13", m_cultureInfo));
            Assert.AreEqual(expected, GregorianDate.Parse("02-2002-25 05:25:13 Mon", m_cultureInfo));
            Assert.AreEqual(expected, GregorianDate.Parse("02-2002-25 5:25:13 Mon", m_cultureInfo));
            Assert.AreEqual(expected, GregorianDate.Parse("02-2002-25 05:25:13 Monday", m_cultureInfo));
            Assert.AreEqual(expected, GregorianDate.Parse("02-2002-25 5:25:13 Monday", m_cultureInfo));

            expected = new GregorianDate(2002, 02, 25, 04, 25, 13);
            Assert.AreEqual(expected, GregorianDate.Parse("2002-02-25 04:25:13Z", m_cultureInfo));
            Assert.AreEqual(expected, GregorianDate.Parse("Mon, 25 Feb 2002 04:25:13 GMT", m_cultureInfo));

            expected = new GregorianDate(2002, 02, 25, 05, 25, 13.008);
            Assert.AreEqual(expected, GregorianDate.Parse("02/25/2002 05:25:13.008", m_cultureInfo));
            Assert.AreEqual(expected, GregorianDate.Parse("02/25/2002 5:25:13.008", m_cultureInfo));
            Assert.AreEqual(expected, GregorianDate.Parse("2002-02-25T05:25:13.008", m_cultureInfo));
            Assert.AreEqual(expected, GregorianDate.Parse("02-2002-25T05:25:13.008", m_cultureInfo));
            Assert.AreEqual(expected, GregorianDate.Parse("02-2002-25 05:25:13.008", m_cultureInfo));
            Assert.AreEqual(expected, GregorianDate.Parse("02-2002-25 5:25:13.008", m_cultureInfo));

            expected = new GregorianDate(DateTime.Today.Year, 02, 25);
            Assert.AreEqual(expected, GregorianDate.Parse("February 25", m_cultureInfo));

            expected = new GregorianDate(DateTime.Today.Year, 02, 8);
            Assert.AreEqual(expected, GregorianDate.Parse("February 08", m_cultureInfo));
            Assert.AreEqual(expected, GregorianDate.Parse("February 8", m_cultureInfo));

            expected = new GregorianDate(2002, 02, 1);
            Assert.AreEqual(expected, GregorianDate.Parse("2002 February", m_cultureInfo));

            expected = new GregorianDate(DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day, 05, 25, 13.4444444);
            Assert.AreEqual(expected, GregorianDate.Parse("05:25:13.4444444", m_cultureInfo));

            expected = new GregorianDate(DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day, 05, 25, 13.1234567);
            Assert.AreEqual(expected, GregorianDate.Parse("05:25:13.1234567", m_cultureInfo));

            expected = new GregorianDate(2009, 06, 30, 05, 25, 13.1234567890);
            Assert.AreEqual(expected, GregorianDate.Parse("06/30/2009 05:25:13.1234567890", m_cultureInfo));

            expected = new GregorianDate(2009, 06, 30, 05, 25, 13.44444444444444);
            Assert.AreEqual(expected, GregorianDate.Parse("06/30/2009 05:25:13.44444444444444", m_cultureInfo));

            expected = new GregorianDate(2009, 06, 30, 05, 25, 13.12345678901234);
            Assert.AreEqual(expected, GregorianDate.Parse("06/30/2009 05:25:13.12345678901234", m_cultureInfo));
            Assert.AreNotEqual(expected, GregorianDate.Parse("06/30/2009 05:25:13.12345678901239", m_cultureInfo));

            expected = new GregorianDate(2009, 06, 30, 05, 25, 13.444444444444444);
            Assert.AreEqual(expected, GregorianDate.Parse("06/30/2009 05:25:13.444444444444444", m_cultureInfo));
            Assert.AreNotEqual(expected, GregorianDate.Parse("06/30/2009 05:25:13.444444444444446", m_cultureInfo));

            expected = new GregorianDate(2009, 06, 30, 05, 25, 0.1234567890123456);
            Assert.AreEqual(expected, GregorianDate.Parse("06/30/2009 05:25:00.1234567890123456", m_cultureInfo));
            Assert.AreNotEqual(expected, GregorianDate.Parse("06/30/2009 05:25:00.1234567890123459", m_cultureInfo));

            expected = new GregorianDate(2009, 06, 30, 05, 25, 0.1234567890123456);

            GregorianDate parsed;

            GregorianDate.TryParse("06/30/2009 05:25:00.1234567890123456", out parsed);
            Assert.AreEqual(expected, parsed);
        }