コード例 #1
0
        public void SecondsAreCorrectlyFormattedToDifferentNumbersOfDigits()
        {
            GregorianDate first = new GregorianDate(2009, 2, 7, 5, 41, 44.408);

            Assert.AreEqual("44.408", first.ToString("ss.fff", m_cultureInfo));
            Assert.AreEqual("44.4080", first.ToString("ss.ffff", m_cultureInfo));
            Assert.AreEqual("44.40800", first.ToString("ss.fffff", m_cultureInfo));
        }
コード例 #2
0
        public void SecondsAreCorrectlyFormattedInTurkey()
        {
            var           cultureInfo = new CultureInfo("tr-TR");
            GregorianDate first       = new GregorianDate(2009, 2, 7, 5, 41, 44.408);

            Assert.AreEqual("44,408", first.ToString("ss.fff", cultureInfo));
            Assert.AreEqual("44,4080", first.ToString("ss.ffff", cultureInfo));
            Assert.AreEqual("44,40800", first.ToString("ss.fffff", cultureInfo));
        }
コード例 #3
0
        public void FractionalSecondsCloseToZeroAreFormattedCorrectly()
        {
            // Based on BUG71966: GregorianDate.ToString(format) produces incorrect value for fractional seconds
            var date = new GregorianDate(2012, 2, 25, 0, 15, 0.000000000014551915228366852);

            Assert.AreEqual("001500.0000000", date.ToString("HHmmss.fffffff", m_cultureInfo));
        }
コード例 #4
0
ファイル: TestGregorianDate.cs プロジェクト: pxyn/czml-writer
        public void TestToStringThreadFormatProvider()
        {
            CultureInfo originalCulture = Thread.CurrentThread.CurrentCulture;

            try
            {
                Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
                GregorianDate gd1 = new GregorianDate(2001, 1, 1, 6, 3, 14);
                Assert.AreEqual("1/1/2001 6:03:14 AM", gd1.ToString());

                // Windows 8 changed to no longer use a two digit day.  Either is ok.
                Assert.IsTrue(gd1.ToLongDateString() == "Monday, January 01, 2001" || gd1.ToLongDateString() == "Monday, January 1, 2001");

                Assert.AreEqual("6:03:14 AM", gd1.ToLongTimeString());
                Assert.AreEqual("1/1/2001", gd1.ToShortDateString());
                Assert.AreEqual("6:03 AM", gd1.ToShortTimeString());

                gd1 = new GregorianDate(2003, 3, 4, 16, 43, 23.23452);
                Assert.AreEqual("3/4/2003 4:43:23 PM", gd1.ToString());
                Assert.IsTrue(gd1.ToLongDateString() == "Tuesday, March 04, 2003" || gd1.ToLongDateString() == "Tuesday, March 4, 2003");
                Assert.AreEqual("4:43:23 PM", gd1.ToLongTimeString());
                Assert.AreEqual("3/4/2003", gd1.ToShortDateString());
                Assert.AreEqual("4:43 PM", gd1.ToShortTimeString());
            }
            finally
            {
                Thread.CurrentThread.CurrentCulture = originalCulture;
            }
        }
コード例 #5
0
        public void TestToStringThreadFormatProvider()
        {
            CultureInfo originalCulture = Thread.CurrentThread.CurrentCulture;

            try
            {
                Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
                GregorianDate gd1 = new GregorianDate(2001, 1, 1, 6, 3, 14);
                Assert.AreEqual("01/01/2001 06:03:14", gd1.ToString());
                Assert.AreEqual("Monday, 01 January 2001", gd1.ToLongDateString());
                Assert.AreEqual("06:03:14", gd1.ToLongTimeString());
                Assert.AreEqual("01/01/2001", gd1.ToShortDateString());
                Assert.AreEqual("06:03", gd1.ToShortTimeString());

                gd1 = new GregorianDate(2003, 3, 4, 16, 43, 23.23452);
                Assert.AreEqual("03/04/2003 16:43:23", gd1.ToString());
                Assert.AreEqual("Tuesday, 04 March 2003", gd1.ToLongDateString());
                Assert.AreEqual("16:43:23", gd1.ToLongTimeString());
                Assert.AreEqual("03/04/2003", gd1.ToShortDateString());
                Assert.AreEqual("16:43", gd1.ToShortTimeString());
            }
            finally
            {
                Thread.CurrentThread.CurrentCulture = originalCulture;
            }
        }
コード例 #6
0
        public void TestToStringThreadFormatProvider()
        {
            CultureInfo originalCulture = Thread.CurrentThread.CurrentCulture;

            try
            {
                Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
                GregorianDate gd1 = new GregorianDate(2001, 1, 1, 6, 3, 14);
                Assert.AreEqual("1/1/2001 6:03:14 AM", gd1.ToString());
                Assert.AreEqual("Monday, January 01, 2001", gd1.ToLongDateString());
                Assert.AreEqual("6:03:14 AM", gd1.ToLongTimeString());
                Assert.AreEqual("1/1/2001", gd1.ToShortDateString());
                Assert.AreEqual("6:03 AM", gd1.ToShortTimeString());

                gd1 = new GregorianDate(2003, 3, 4, 16, 43, 23.23452);
                Assert.AreEqual("3/4/2003 4:43:23 PM", gd1.ToString());
                Assert.AreEqual("Tuesday, March 04, 2003", gd1.ToLongDateString());
                Assert.AreEqual("4:43:23 PM", gd1.ToLongTimeString());
                Assert.AreEqual("3/4/2003", gd1.ToShortDateString());
                Assert.AreEqual("4:43 PM", gd1.ToShortTimeString());
            }
            finally
            {
                Thread.CurrentThread.CurrentCulture = originalCulture;
            }
        }
コード例 #7
0
        public void TestToStringFormatProvider()
        {
            GregorianDate gd1 = new GregorianDate(2001, 1, 1, 6, 3, 14);

            Assert.AreEqual("1/1/2001 6:03:14 AM", gd1.ToString(new CultureInfo("en-US")));

            gd1 = new GregorianDate(2003, 3, 4, 16, 43, 23.23452);
            Assert.AreEqual("3/4/2003 4:43:23 PM", gd1.ToString(new CultureInfo("en-US")));
        }
コード例 #8
0
        public void TestToStringStandardFormats(string format)
        {
            var dateTime      = new DateTime(2002, 02, 25, 05, 25, 13);
            var gregorianDate = new GregorianDate(dateTime);

            // .NET Core on Linux uses different standard formats, so we compare against what DateTime does
            // rather than specific known strings.
            Assert.AreEqual(dateTime.ToString(format, m_cultureInfo), gregorianDate.ToString(format, m_cultureInfo));
        }
コード例 #9
0
        public void WholeNumberSecondsIsFormattedCorrectly()
        {
            var gregorianDate = new GregorianDate(2012, 8, 7, 13, 59, 55.0);

            Assert.AreEqual("2012-08-07 13:59:55.000000", gregorianDate.ToString("yyyy-MM-dd HH:mm:ss.ffffff", m_cultureInfo));

            gregorianDate = new GregorianDate(2012, 8, 7, 13, 59, 55.0);
            Assert.AreEqual("2012-08-07 13:59:55", gregorianDate.ToString("yyyy-MM-dd HH:mm:ss", m_cultureInfo));

            gregorianDate = new GregorianDate(2012, 8, 7, 13, 59, 55.0);
            Assert.AreEqual("2012-08-07 13:59:55", gregorianDate.ToString("yyyy-MM-dd HH:mm:ss.FFFFFF", m_cultureInfo));
        }
コード例 #10
0
        public void TestToStringFormatProvider()
        {
            var cultureInfo = new CultureInfo("en-US");

            var date          = new DateTime(2001, 1, 1, 6, 3, 14, DateTimeKind.Utc);
            var gregorianDate = new GregorianDate(date);

            Assert.AreEqual(date.ToString(cultureInfo), gregorianDate.ToString(cultureInfo));

            date          = new DateTime(2003, 3, 4, 16, 43, 23, 234, DateTimeKind.Utc);
            gregorianDate = new GregorianDate(date);
            Assert.AreEqual(date.ToString(cultureInfo), gregorianDate.ToString(cultureInfo));
        }
コード例 #11
0
            public void TestToStringThreadFormatProvider()
            {
                var date          = new DateTime(2001, 1, 1, 6, 3, 14, DateTimeKind.Utc);
                var gregorianDate = new GregorianDate(date);

                Assert.AreEqual(date.ToString(), gregorianDate.ToString());
                Assert.AreEqual(date.ToLongDateString(), gregorianDate.ToLongDateString());
                Assert.AreEqual(date.ToLongTimeString(), gregorianDate.ToLongTimeString());
                Assert.AreEqual(date.ToShortDateString(), gregorianDate.ToShortDateString());
                Assert.AreEqual(date.ToShortTimeString(), gregorianDate.ToShortTimeString());

                date          = new DateTime(2003, 3, 4, 16, 43, 23, 234, DateTimeKind.Utc);
                gregorianDate = new GregorianDate(date);
                Assert.AreEqual(date.ToString(), gregorianDate.ToString());
                Assert.AreEqual(date.ToLongDateString(), gregorianDate.ToLongDateString());
                Assert.AreEqual(date.ToLongTimeString(), gregorianDate.ToLongTimeString());
                Assert.AreEqual(date.ToShortDateString(), gregorianDate.ToShortDateString());
                Assert.AreEqual(date.ToShortTimeString(), gregorianDate.ToShortTimeString());
            }
コード例 #12
0
 public void TestFormattingLeapSecond()
 {
     GregorianDate date = new GregorianDate(2008, 12, 31, 23, 59, 60.444);
     Assert.AreEqual("31 Dec 2008 23:59:60.444", date.ToString("d MMM yyyy H:mm:ss.fff", m_cultureInfo));
 }
コード例 #13
0
        public void ToStringTruncatesSeconds()
        {
            var gregorianDate = new GregorianDate(2012, 8, 7, 13, 59, 59.9999999);

            Assert.AreEqual("2012-08-07 13:59:59.999999", gregorianDate.ToString("yyyy-MM-dd HH:mm:ss.ffffff", m_cultureInfo));
        }
コード例 #14
0
        public void TestToString()
        {
            GregorianDate date = new GregorianDate(2002, 02, 25, 05, 25, 13);

            Assert.AreEqual("2/25/2002", date.ToString("d", m_cultureInfo));
            Assert.AreEqual("Monday, February 25, 2002", date.ToString("D", m_cultureInfo));
            Assert.AreEqual("Monday, February 25, 2002 5:25 AM", date.ToString("f", m_cultureInfo));
            Assert.AreEqual("Monday, February 25, 2002 5:25:13 AM", date.ToString("F", m_cultureInfo));
            Assert.AreEqual("2/25/2002 5:25 AM", date.ToString("g", m_cultureInfo));
            Assert.AreEqual("2/25/2002 5:25:13 AM", date.ToString("G", m_cultureInfo));
            Assert.AreEqual("February 25", date.ToString("m", m_cultureInfo));
            Assert.AreEqual("February 25", date.ToString("M", m_cultureInfo));
            Assert.AreEqual("Mon, 25 Feb 2002 05:25:13 GMT", date.ToString("r", m_cultureInfo));
            Assert.AreEqual("Mon, 25 Feb 2002 05:25:13 GMT", date.ToString("R", m_cultureInfo));
            Assert.AreEqual("2002-02-25T05:25:13", date.ToString("s", m_cultureInfo));
            Assert.AreEqual("5:25 AM", date.ToString("t", m_cultureInfo));
            Assert.AreEqual("5:25:13 AM", date.ToString("T", m_cultureInfo));
            Assert.AreEqual("2002-02-25 05:25:13Z", date.ToString("u", m_cultureInfo));
            Assert.AreEqual("February, 2002", date.ToString("y", m_cultureInfo));
            Assert.AreEqual("February, 2002", date.ToString("Y", m_cultureInfo));
            Assert.AreEqual("2/25/2002 5:25:13 AM", date.ToString("", m_cultureInfo));
            Assert.AreEqual("25", date.ToString("%d", m_cultureInfo));
            Assert.AreEqual("25", date.ToString("dd", m_cultureInfo));
            Assert.AreEqual("Mon", date.ToString("ddd", m_cultureInfo));
            Assert.AreEqual("Monday", date.ToString("dddd", m_cultureInfo));
            Assert.AreEqual("2", date.ToString("%M", m_cultureInfo));
            Assert.AreEqual("02", date.ToString("MM", m_cultureInfo));
            Assert.AreEqual("Feb", date.ToString("MMM", m_cultureInfo));
            Assert.AreEqual("February", date.ToString("MMMM", m_cultureInfo));
            Assert.AreEqual("2", date.ToString("%y", m_cultureInfo));
            Assert.AreEqual("02", date.ToString("yy", m_cultureInfo));
            Assert.AreEqual("2002", date.ToString("yyyy", m_cultureInfo));
            Assert.AreEqual("5", date.ToString("%h", m_cultureInfo));
            Assert.AreEqual("05", date.ToString("hh", m_cultureInfo));
            Assert.AreEqual("A", date.ToString("%t", m_cultureInfo));
            Assert.AreEqual("AM", date.ToString("tt", m_cultureInfo));

            date = new GregorianDate(2009, 06, 10, 00, 30, 00);
            Assert.AreEqual("12", date.ToString("%h", m_cultureInfo));
            Assert.AreEqual("0", date.ToString("%H", m_cultureInfo));

            date = new GregorianDate(2002, 02, 25, 15, 25, 13);
            Assert.AreEqual("3", date.ToString("%h", m_cultureInfo));
            Assert.AreEqual("03", date.ToString("hh", m_cultureInfo));
            Assert.AreEqual("15", date.ToString("%H", m_cultureInfo));
            Assert.AreEqual("15", date.ToString("HH", m_cultureInfo));
            Assert.AreEqual("25", date.ToString("%m", m_cultureInfo));
            Assert.AreEqual("25", date.ToString("mm", m_cultureInfo));
            Assert.AreEqual("13", date.ToString("%s", m_cultureInfo));
            Assert.AreEqual("13", date.ToString("ss", m_cultureInfo));
            Assert.AreEqual("P", date.ToString("%t", m_cultureInfo));
            Assert.AreEqual("PM", date.ToString("tt", m_cultureInfo));
            Assert.AreEqual("A.D.", date.ToString("%g", m_cultureInfo));

            Assert.AreEqual(" : ", date.ToString(" : ", m_cultureInfo));
            Assert.AreEqual(" / ", date.ToString(" / ", m_cultureInfo));
            Assert.AreEqual(" yyy ", date.ToString(" 'yyy' ", m_cultureInfo));
            Assert.AreEqual(" d", date.ToString(" \\d", m_cultureInfo));
            Assert.AreEqual("2002", date.ToString("yyy", m_cultureInfo));
            Assert.AreEqual("0002002", date.ToString("yyyyyyy", m_cultureInfo));

            date = new GregorianDate(999, 1, 2, 3, 4, 5);
            Assert.AreEqual("999", date.ToString("yyy", m_cultureInfo));
            Assert.AreEqual("0999", date.ToString("yyyy", m_cultureInfo));

            date = new GregorianDate(2009, 06, 10, 15, 0, 13.012345678912345);
            Assert.AreEqual("13.012345678912345", date.ToString("ss.fffffffffffffff"));

            date = new GregorianDate(2009, 06, 10, 15, 0, 13.012);
            Assert.AreEqual("13.012000000000000", date.ToString("ss.fffffffffffffff"));
            Assert.AreEqual("13.012", date.ToString("ss.FFFFFFFFFFFFFFF"));
        }
コード例 #15
0
        public void TestFormattingLeapSecond()
        {
            GregorianDate date = new GregorianDate(2008, 12, 31, 23, 59, 60.444);

            Assert.AreEqual("31 Dec 2008 23:59:60.444", date.ToString("d MMM yyyy H:mm:ss.fff", m_cultureInfo));
        }
コード例 #16
0
        public void TestParseExact()
        {
            GregorianDate expected = new GregorianDate(2002, 02, 25);

            Assert.AreEqual(expected, GregorianDate.ParseExact(expected.ToString("d", m_cultureInfo), "d", m_cultureInfo));
            Assert.AreEqual(expected, GregorianDate.ParseExact(expected.ToString("D", m_cultureInfo), "D", m_cultureInfo));

            expected = new GregorianDate(2002, 02, 25, 05, 25, 00);
            Assert.AreEqual(expected, GregorianDate.ParseExact(expected.ToString("f", m_cultureInfo), "f", m_cultureInfo));
            Assert.AreEqual(expected, GregorianDate.ParseExact(expected.ToString("g", m_cultureInfo), "g", m_cultureInfo));

            expected = new GregorianDate(2002, 02, 25, 05, 25, 13);
            Assert.AreEqual(expected, GregorianDate.ParseExact(expected.ToString("F", m_cultureInfo), "F", m_cultureInfo));
            Assert.AreEqual(expected, GregorianDate.ParseExact(expected.ToString("G", m_cultureInfo), "G", m_cultureInfo));
            Assert.AreEqual(expected, GregorianDate.ParseExact(expected.ToString("s", m_cultureInfo), "s", m_cultureInfo));
            Assert.AreEqual(expected, GregorianDate.ParseExact("Monday, 25 February 2002 05:25:13", "dddd, dd MMMM yyyy HH:mm:ss", m_cultureInfo));

            expected = new GregorianDate(2002, 02, 25, 04, 25, 13);
            Assert.AreEqual(expected, GregorianDate.ParseExact(expected.ToString("U", m_cultureInfo), "U", m_cultureInfo));
            Assert.AreEqual(expected, GregorianDate.ParseExact(expected.ToString("u", m_cultureInfo), "u", m_cultureInfo));
            Assert.AreEqual(expected, GregorianDate.ParseExact(expected.ToString("r", m_cultureInfo), "r", m_cultureInfo));
            Assert.AreEqual(expected, GregorianDate.ParseExact(expected.ToString("R", m_cultureInfo), "R", m_cultureInfo));

            expected = new GregorianDate(DateTime.Today.Year, 02, 25);
            Assert.AreEqual(expected, GregorianDate.ParseExact(expected.ToString("m", m_cultureInfo), "m", m_cultureInfo));
            Assert.AreEqual(expected, GregorianDate.ParseExact(expected.ToString("M", m_cultureInfo), "M", m_cultureInfo));

            expected = new GregorianDate(DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day, 05, 25, 00);
            Assert.AreEqual(expected, GregorianDate.ParseExact(expected.ToString("t", m_cultureInfo), "t", m_cultureInfo));

            expected = new GregorianDate(DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day, 05, 25, 13);
            Assert.AreEqual(expected, GregorianDate.ParseExact(expected.ToString("T", m_cultureInfo), "T", m_cultureInfo));

            expected = new GregorianDate(2002, 02, 1);
            Assert.AreEqual(expected, GregorianDate.ParseExact(expected.ToString("y", m_cultureInfo), "y", m_cultureInfo));
            Assert.AreEqual(expected, GregorianDate.ParseExact(expected.ToString("Y", m_cultureInfo), "Y", m_cultureInfo));

            expected = new GregorianDate(DateTime.Today.Year, 1, 25);
            Assert.AreEqual(expected, GregorianDate.ParseExact("25", "%d", m_cultureInfo));
            Assert.AreEqual(expected, GregorianDate.ParseExact("25", "dd", m_cultureInfo));

            expected = new GregorianDate(DateTime.Today.Year, 2, 1);
            Assert.AreEqual(expected, GregorianDate.ParseExact("2", "%M", m_cultureInfo));
            Assert.AreEqual(expected, GregorianDate.ParseExact("02", "MM", m_cultureInfo));
            Assert.AreEqual(expected, GregorianDate.ParseExact("Feb", "MMM", m_cultureInfo));
            Assert.AreEqual(expected, GregorianDate.ParseExact("February", "MMMM", m_cultureInfo));

            expected = new GregorianDate(2005, 1, 1);
            Assert.AreEqual(expected, GregorianDate.ParseExact("5", "%y", m_cultureInfo));
            Assert.AreEqual(expected, GregorianDate.ParseExact("05", "yy", m_cultureInfo));
            Assert.AreEqual(expected, GregorianDate.ParseExact("2005", "yyyy", m_cultureInfo));

            expected = new GregorianDate(DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day, 5, 0, 0);
            Assert.AreEqual(expected, GregorianDate.ParseExact("5A", "ht", m_cultureInfo));
            Assert.AreEqual(expected, GregorianDate.ParseExact("05A", "hht", m_cultureInfo));
            Assert.AreEqual(expected, GregorianDate.ParseExact("5", "%H", m_cultureInfo));
            Assert.AreEqual(expected, GregorianDate.ParseExact("05", "HH", m_cultureInfo));

            expected = new GregorianDate(DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day, 15, 0, 0);
            Assert.AreEqual(expected, GregorianDate.ParseExact("3P", "ht", m_cultureInfo));
            Assert.AreEqual(expected, GregorianDate.ParseExact("03P", "hht", m_cultureInfo));
            Assert.AreEqual(expected, GregorianDate.ParseExact("15", "%H", m_cultureInfo));
            Assert.AreEqual(expected, GregorianDate.ParseExact("15", "HH", m_cultureInfo));

            expected = new GregorianDate(2002, 02, 25, 05, 25, 13.444);
            Assert.AreEqual(expected, GregorianDate.ParseExact("Monday, 25 February 2002 05:25:13.444", "dddd, dd MMMM yyyy HH:mm:ss.fff", m_cultureInfo));

            expected = new GregorianDate(DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day, 05, 25, 13.4444444);
            Assert.AreEqual(expected, GregorianDate.ParseExact("05:25:13.4444444", "HH:mm:ss.fffffff", m_cultureInfo));

            expected = new GregorianDate(DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day, 05, 25, 13.1234567);
            Assert.AreEqual(expected, GregorianDate.ParseExact("05:25:13.1234567", "HH:mm:ss.fffffff", m_cultureInfo));

            expected = new GregorianDate(2009, 06, 30, 05, 25, 13.1234567890);
            Assert.AreEqual(expected, GregorianDate.ParseExact("06/30/2009 05:25:13.1234567890", "MM/dd/yyyy HH:mm:ss.ffffffffff", m_cultureInfo));

            expected = new GregorianDate(2009, 06, 30, 05, 25, 13.44444444444444);
            Assert.AreEqual(expected, GregorianDate.ParseExact("06/30/2009 05:25:13.44444444444444", "MM/dd/yyyy HH:mm:ss.ffffffffffffff", m_cultureInfo));

            expected = new GregorianDate(2009, 06, 30, 05, 25, 13.12345678901234);
            Assert.AreEqual(expected, GregorianDate.ParseExact("06/30/2009 05:25:13.12345678901234", "MM/dd/yyyy HH:mm:ss.ffffffffffffff", m_cultureInfo));
            Assert.AreNotEqual(expected, GregorianDate.ParseExact("06/30/2009 05:25:13.123456789012345", "MM/dd/yyyy HH:mm:ss.fffffffffffffff", m_cultureInfo));

            expected = new GregorianDate(2009, 06, 30, 05, 25, 13.444444444444444);
            Assert.AreEqual(expected, GregorianDate.ParseExact("06/30/2009 05:25:13.444444444444444", "MM/dd/yyyy HH:mm:ss.fffffffffffffff", m_cultureInfo));
            Assert.AreNotEqual(expected, GregorianDate.ParseExact("06/30/2009 05:25:13.444444444444446", "MM/dd/yyyy HH:mm:ss.fffffffffffffff", m_cultureInfo));

            expected = new GregorianDate(2009, 06, 30, 05, 25, 0.1234567890123456);
            Assert.AreEqual(expected, GregorianDate.ParseExact("06/30/2009 05:25:00.1234567890123456", "MM/dd/yyyy HH:mm:ss.ffffffffffffffff", m_cultureInfo));
            Assert.AreNotEqual(expected, GregorianDate.ParseExact("06/30/2009 05:25:00.1234567890123459", "MM/dd/yyyy HH:mm:ss.ffffffffffffffff", m_cultureInfo));
        }
コード例 #17
0
        public void TestToStringThreadFormatProvider()
        {
            CultureInfo originalCulture = Thread.CurrentThread.CurrentCulture;
            try
            {
                Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
                GregorianDate gd1 = new GregorianDate(2001, 1, 1, 6, 3, 14);
                Assert.AreEqual("1/1/2001 6:03:14 AM", gd1.ToString());
                Assert.AreEqual("Monday, January 01, 2001", gd1.ToLongDateString());
                Assert.AreEqual("6:03:14 AM", gd1.ToLongTimeString());
                Assert.AreEqual("1/1/2001", gd1.ToShortDateString());
                Assert.AreEqual("6:03 AM", gd1.ToShortTimeString());

                gd1 = new GregorianDate(2003, 3, 4, 16, 43, 23.23452);
                Assert.AreEqual("3/4/2003 4:43:23 PM", gd1.ToString());
                Assert.AreEqual("Tuesday, March 04, 2003", gd1.ToLongDateString());
                Assert.AreEqual("4:43:23 PM", gd1.ToLongTimeString());
                Assert.AreEqual("3/4/2003", gd1.ToShortDateString());
                Assert.AreEqual("4:43 PM", gd1.ToShortTimeString());
            }
            finally
            {
                Thread.CurrentThread.CurrentCulture = originalCulture;
            }
        }
コード例 #18
0
        public void TestToStringFormatProvider()
        {
            GregorianDate gd1 = new GregorianDate(2001, 1, 1, 6, 3, 14);
            Assert.AreEqual("1/1/2001 6:03:14 AM", gd1.ToString(new CultureInfo("en-US")));

            gd1 = new GregorianDate(2003, 3, 4, 16, 43, 23.23452);
            Assert.AreEqual("3/4/2003 4:43:23 PM", gd1.ToString(new CultureInfo("en-US")));
        }
コード例 #19
0
        public void TestToString()
        {
            GregorianDate date = new GregorianDate(2002, 02, 25, 05, 25, 13);

            Assert.AreEqual("2/25/2002", date.ToString("d", m_cultureInfo));
            Assert.AreEqual("Monday, February 25, 2002", date.ToString("D", m_cultureInfo));
            Assert.AreEqual("Monday, February 25, 2002 5:25 AM", date.ToString("f", m_cultureInfo));
            Assert.AreEqual("Monday, February 25, 2002 5:25:13 AM", date.ToString("F", m_cultureInfo));
            Assert.AreEqual("2/25/2002 5:25 AM", date.ToString("g", m_cultureInfo));
            Assert.AreEqual("2/25/2002 5:25:13 AM", date.ToString("G", m_cultureInfo));
            Assert.AreEqual("February 25", date.ToString("m", m_cultureInfo));
            Assert.AreEqual("February 25", date.ToString("M", m_cultureInfo));
            Assert.AreEqual("Mon, 25 Feb 2002 05:25:13 GMT", date.ToString("r", m_cultureInfo));
            Assert.AreEqual("Mon, 25 Feb 2002 05:25:13 GMT", date.ToString("R", m_cultureInfo));
            Assert.AreEqual("2002-02-25T05:25:13", date.ToString("s", m_cultureInfo));
            Assert.AreEqual("5:25 AM", date.ToString("t", m_cultureInfo));
            Assert.AreEqual("5:25:13 AM", date.ToString("T", m_cultureInfo));
            Assert.AreEqual("2002-02-25 05:25:13Z", date.ToString("u", m_cultureInfo));

            // Windows 8 changed to no longer include a comma after the month.  Either is ok.
            string smallY = date.ToString("y", m_cultureInfo);

            Assert.IsTrue(smallY == "February, 2002" || smallY == "February 2002");
            string bigY = date.ToString("Y", m_cultureInfo);

            Assert.IsTrue(bigY == "February, 2002" || bigY == "February 2002");

            Assert.AreEqual("2/25/2002 5:25:13 AM", date.ToString("", m_cultureInfo));
            Assert.AreEqual("25", date.ToString("%d", m_cultureInfo));
            Assert.AreEqual("25", date.ToString("dd", m_cultureInfo));
            Assert.AreEqual("Mon", date.ToString("ddd", m_cultureInfo));
            Assert.AreEqual("Monday", date.ToString("dddd", m_cultureInfo));
            Assert.AreEqual("2", date.ToString("%M", m_cultureInfo));
            Assert.AreEqual("02", date.ToString("MM", m_cultureInfo));
            Assert.AreEqual("Feb", date.ToString("MMM", m_cultureInfo));
            Assert.AreEqual("February", date.ToString("MMMM", m_cultureInfo));
            Assert.AreEqual("2", date.ToString("%y", m_cultureInfo));
            Assert.AreEqual("02", date.ToString("yy", m_cultureInfo));
            Assert.AreEqual("2002", date.ToString("yyyy", m_cultureInfo));
            Assert.AreEqual("5", date.ToString("%h", m_cultureInfo));
            Assert.AreEqual("05", date.ToString("hh", m_cultureInfo));
            Assert.AreEqual("A", date.ToString("%t", m_cultureInfo));
            Assert.AreEqual("AM", date.ToString("tt", m_cultureInfo));

            date = new GregorianDate(2009, 06, 10, 00, 30, 00);
            Assert.AreEqual("12", date.ToString("%h", m_cultureInfo));
            Assert.AreEqual("0", date.ToString("%H", m_cultureInfo));

            date = new GregorianDate(2002, 02, 25, 15, 25, 13);
            Assert.AreEqual("3", date.ToString("%h", m_cultureInfo));
            Assert.AreEqual("03", date.ToString("hh", m_cultureInfo));
            Assert.AreEqual("15", date.ToString("%H", m_cultureInfo));
            Assert.AreEqual("15", date.ToString("HH", m_cultureInfo));
            Assert.AreEqual("25", date.ToString("%m", m_cultureInfo));
            Assert.AreEqual("25", date.ToString("mm", m_cultureInfo));
            Assert.AreEqual("13", date.ToString("%s", m_cultureInfo));
            Assert.AreEqual("13", date.ToString("ss", m_cultureInfo));
            Assert.AreEqual("P", date.ToString("%t", m_cultureInfo));
            Assert.AreEqual("PM", date.ToString("tt", m_cultureInfo));
            Assert.AreEqual("A.D.", date.ToString("%g", m_cultureInfo));

            Assert.AreEqual(" : ", date.ToString(" : ", m_cultureInfo));
            Assert.AreEqual(" / ", date.ToString(" / ", m_cultureInfo));
            Assert.AreEqual(" yyy ", date.ToString(" 'yyy' ", m_cultureInfo));
            Assert.AreEqual(" d", date.ToString(" \\d", m_cultureInfo));
            Assert.AreEqual("2002", date.ToString("yyy", m_cultureInfo));
            Assert.AreEqual("0002002", date.ToString("yyyyyyy", m_cultureInfo));

            date = new GregorianDate(999, 1, 2, 3, 4, 5);
            Assert.AreEqual("999", date.ToString("yyy", m_cultureInfo));
            Assert.AreEqual("0999", date.ToString("yyyy", m_cultureInfo));

            // .NET's Double.ToString pads with zeros beyond 15 significant digits.
            // This is kind of obnoxious, but we get the guaranteed precision of
            // a GregorianDate (1e-10 seconds) even so, so it's not worth major
            // heroics to solve.
            date = new GregorianDate(2009, 06, 10, 15, 0, 13.012345678912345);
            string s = date.ToString("ss.fffffffffffffff", m_cultureInfo);

            Assert.AreEqual(18, s.Length);
            Assert.IsTrue(s.StartsWith("13.0123456789123"));

            date = new GregorianDate(2009, 06, 10, 15, 0, 13.012);
            Assert.AreEqual("13.012000000000000", date.ToString("ss.fffffffffffffff", m_cultureInfo));
            Assert.AreEqual("13.012", date.ToString("ss.FFFFFFFFFFFFFFF", m_cultureInfo));
        }
コード例 #20
0
        public void TestToStringCustomFormats()
        {
            var dateTime      = new DateTime(2002, 02, 25, 05, 25, 13);
            var gregorianDate = new GregorianDate(dateTime);

            Assert.AreEqual("25", gregorianDate.ToString("%d", m_cultureInfo));
            Assert.AreEqual("25", gregorianDate.ToString("dd", m_cultureInfo));
            Assert.AreEqual("Mon", gregorianDate.ToString("ddd", m_cultureInfo));
            Assert.AreEqual("Monday", gregorianDate.ToString("dddd", m_cultureInfo));
            Assert.AreEqual("2", gregorianDate.ToString("%M", m_cultureInfo));
            Assert.AreEqual("02", gregorianDate.ToString("MM", m_cultureInfo));
            Assert.AreEqual("Feb", gregorianDate.ToString("MMM", m_cultureInfo));
            Assert.AreEqual("February", gregorianDate.ToString("MMMM", m_cultureInfo));
            Assert.AreEqual("2", gregorianDate.ToString("%y", m_cultureInfo));
            Assert.AreEqual("02", gregorianDate.ToString("yy", m_cultureInfo));
            Assert.AreEqual("2002", gregorianDate.ToString("yyyy", m_cultureInfo));
            Assert.AreEqual("5", gregorianDate.ToString("%h", m_cultureInfo));
            Assert.AreEqual("05", gregorianDate.ToString("hh", m_cultureInfo));
            Assert.AreEqual("A", gregorianDate.ToString("%t", m_cultureInfo));
            Assert.AreEqual("AM", gregorianDate.ToString("tt", m_cultureInfo));

            dateTime      = new DateTime(2009, 06, 10, 00, 30, 00);
            gregorianDate = new GregorianDate(dateTime);
            Assert.AreEqual("12", gregorianDate.ToString("%h", m_cultureInfo));
            Assert.AreEqual("0", gregorianDate.ToString("%H", m_cultureInfo));

            dateTime      = new DateTime(2002, 02, 25, 15, 25, 13);
            gregorianDate = new GregorianDate(dateTime);
            Assert.AreEqual("3", gregorianDate.ToString("%h", m_cultureInfo));
            Assert.AreEqual("03", gregorianDate.ToString("hh", m_cultureInfo));
            Assert.AreEqual("15", gregorianDate.ToString("%H", m_cultureInfo));
            Assert.AreEqual("15", gregorianDate.ToString("HH", m_cultureInfo));
            Assert.AreEqual("25", gregorianDate.ToString("%m", m_cultureInfo));
            Assert.AreEqual("25", gregorianDate.ToString("mm", m_cultureInfo));
            Assert.AreEqual("13", gregorianDate.ToString("%s", m_cultureInfo));
            Assert.AreEqual("13", gregorianDate.ToString("ss", m_cultureInfo));
            Assert.AreEqual("P", gregorianDate.ToString("%t", m_cultureInfo));
            Assert.AreEqual("PM", gregorianDate.ToString("tt", m_cultureInfo));
#if !CSToJava
            Assert.AreEqual(dateTime.ToString("%g", m_cultureInfo), gregorianDate.ToString("%g", m_cultureInfo));
#endif
            Assert.AreEqual(" : ", gregorianDate.ToString(" : ", m_cultureInfo));
            Assert.AreEqual(" / ", gregorianDate.ToString(" / ", m_cultureInfo));
            Assert.AreEqual(" yyy ", gregorianDate.ToString(" 'yyy' ", m_cultureInfo));
            Assert.AreEqual(" d", gregorianDate.ToString(" \\d", m_cultureInfo));
            Assert.AreEqual("2002", gregorianDate.ToString("yyy", m_cultureInfo));
            Assert.AreEqual("0002002", gregorianDate.ToString("yyyyyyy", m_cultureInfo));

            gregorianDate = new GregorianDate(999, 1, 2, 3, 4, 5);
            Assert.AreEqual("999", gregorianDate.ToString("yyy", m_cultureInfo));
            Assert.AreEqual("0999", gregorianDate.ToString("yyyy", m_cultureInfo));

            // .NET's Double.ToString pads with zeros beyond 15 significant digits.
            // This is kind of obnoxious, but we get the guaranteed precision of
            // a GregorianDate (1e-10 seconds) even so, so it's not worth major
            // heroics to solve.
            gregorianDate = new GregorianDate(2009, 06, 10, 15, 0, 13.012345678912345);
            string s = gregorianDate.ToString("ss.fffffffffffffff", m_cultureInfo);
            Assert.AreEqual(18, s.Length);
            Assert.IsTrue(s.StartsWith("13.0123456789123"));

            gregorianDate = new GregorianDate(2009, 06, 10, 15, 0, 13.012);
            Assert.AreEqual("13.012000000000000", gregorianDate.ToString("ss.fffffffffffffff", m_cultureInfo));
            Assert.AreEqual("13.012", gregorianDate.ToString("ss.FFFFFFFFFFFFFFF", m_cultureInfo));
        }
コード例 #21
0
        public void TestToString()
        {
            GregorianDate date = new GregorianDate(2002, 02, 25, 05, 25, 13);

            Assert.AreEqual("2/25/2002", date.ToString("d", m_cultureInfo));
            Assert.AreEqual("Monday, February 25, 2002", date.ToString("D", m_cultureInfo));
            Assert.AreEqual("Monday, February 25, 2002 5:25 AM", date.ToString("f", m_cultureInfo));
            Assert.AreEqual("Monday, February 25, 2002 5:25:13 AM", date.ToString("F", m_cultureInfo));
            Assert.AreEqual("2/25/2002 5:25 AM", date.ToString("g", m_cultureInfo));
            Assert.AreEqual("2/25/2002 5:25:13 AM", date.ToString("G", m_cultureInfo));
            Assert.AreEqual("February 25", date.ToString("m", m_cultureInfo));
            Assert.AreEqual("February 25", date.ToString("M", m_cultureInfo));
            Assert.AreEqual("Mon, 25 Feb 2002 05:25:13 GMT", date.ToString("r", m_cultureInfo));
            Assert.AreEqual("Mon, 25 Feb 2002 05:25:13 GMT", date.ToString("R", m_cultureInfo));
            Assert.AreEqual("2002-02-25T05:25:13", date.ToString("s", m_cultureInfo));
            Assert.AreEqual("5:25 AM", date.ToString("t", m_cultureInfo));
            Assert.AreEqual("5:25:13 AM", date.ToString("T", m_cultureInfo));
            Assert.AreEqual("2002-02-25 05:25:13Z", date.ToString("u", m_cultureInfo));
            Assert.AreEqual("February, 2002", date.ToString("y", m_cultureInfo));
            Assert.AreEqual("February, 2002", date.ToString("Y", m_cultureInfo));
            Assert.AreEqual("2/25/2002 5:25:13 AM", date.ToString("", m_cultureInfo));
            Assert.AreEqual("25", date.ToString("%d", m_cultureInfo));
            Assert.AreEqual("25", date.ToString("dd", m_cultureInfo));
            Assert.AreEqual("Mon", date.ToString("ddd", m_cultureInfo));
            Assert.AreEqual("Monday", date.ToString("dddd", m_cultureInfo));
            Assert.AreEqual("2", date.ToString("%M", m_cultureInfo));
            Assert.AreEqual("02", date.ToString("MM", m_cultureInfo));
            Assert.AreEqual("Feb", date.ToString("MMM", m_cultureInfo));
            Assert.AreEqual("February", date.ToString("MMMM", m_cultureInfo));
            Assert.AreEqual("2", date.ToString("%y", m_cultureInfo));
            Assert.AreEqual("02", date.ToString("yy", m_cultureInfo));
            Assert.AreEqual("2002", date.ToString("yyyy", m_cultureInfo));
            Assert.AreEqual("5", date.ToString("%h", m_cultureInfo));
            Assert.AreEqual("05", date.ToString("hh", m_cultureInfo));
            Assert.AreEqual("A", date.ToString("%t", m_cultureInfo));
            Assert.AreEqual("AM", date.ToString("tt", m_cultureInfo));

            date = new GregorianDate(2009, 06, 10, 00, 30, 00);
            Assert.AreEqual("12", date.ToString("%h", m_cultureInfo));
            Assert.AreEqual("0", date.ToString("%H", m_cultureInfo));

            date = new GregorianDate(2002, 02, 25, 15, 25, 13);
            Assert.AreEqual("3", date.ToString("%h", m_cultureInfo));
            Assert.AreEqual("03", date.ToString("hh", m_cultureInfo));
            Assert.AreEqual("15", date.ToString("%H", m_cultureInfo));
            Assert.AreEqual("15", date.ToString("HH", m_cultureInfo));
            Assert.AreEqual("25", date.ToString("%m", m_cultureInfo));
            Assert.AreEqual("25", date.ToString("mm", m_cultureInfo));
            Assert.AreEqual("13", date.ToString("%s", m_cultureInfo));
            Assert.AreEqual("13", date.ToString("ss", m_cultureInfo));
            Assert.AreEqual("P", date.ToString("%t", m_cultureInfo));
            Assert.AreEqual("PM", date.ToString("tt", m_cultureInfo));
            Assert.AreEqual("A.D.", date.ToString("%g", m_cultureInfo));

            Assert.AreEqual(" : ", date.ToString(" : ", m_cultureInfo));
            Assert.AreEqual(" / ", date.ToString(" / ", m_cultureInfo));
            Assert.AreEqual(" yyy ", date.ToString(" 'yyy' ", m_cultureInfo));
            Assert.AreEqual(" d", date.ToString(" \\d", m_cultureInfo));
            Assert.AreEqual("2002", date.ToString("yyy", m_cultureInfo));
            Assert.AreEqual("0002002", date.ToString("yyyyyyy", m_cultureInfo));

            date = new GregorianDate(999, 1, 2, 3, 4, 5);
            Assert.AreEqual("999", date.ToString("yyy", m_cultureInfo));
            Assert.AreEqual("0999", date.ToString("yyyy", m_cultureInfo));

            date = new GregorianDate(2009, 06, 10, 15, 0, 13.012345678912345);
            Assert.AreEqual("13.012345678912345", date.ToString("ss.fffffffffffffff"));

            date = new GregorianDate(2009, 06, 10, 15, 0, 13.012);
            Assert.AreEqual("13.012000000000000", date.ToString("ss.fffffffffffffff"));
            Assert.AreEqual("13.012", date.ToString("ss.FFFFFFFFFFFFFFF"));
        }