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; } }
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; } }
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; } }
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()); }