public virtual void ShouldFormatDateTimeAccordingToTimeFormat() { OverriddenTimeGlobalizationInfo strategy = new OverriddenTimeGlobalizationInfo(); CultureInfo currentCulture = Thread.CurrentThread.CurrentCulture; try { Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US"); Assert.AreEqual("8:03 AM", strategy.FormatTime(new DateTime(1900, 2, 3, 8, 3, 12), new ShortTimeFormat())); Assert.AreEqual("8:03:12 AM", strategy.FormatTime(new DateTime(1900, 2, 3, 8, 3, 12), new LongTimeFormat())); } finally { Thread.CurrentThread.CurrentCulture = currentCulture; } Assert.AreEqual("08.03.12", strategy.FormatTime(new DateTime(1900, 2, 3, 8, 3, 12), new CustomTimeFormat("HH.mm.ss"))); }
public virtual void ShouldFormatDateTimeWithFilter() { OverriddenTimeGlobalizationInfo strategy = new OverriddenTimeGlobalizationInfo(); CultureInfo currentCulture = Thread.CurrentThread.CurrentCulture; try { Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US"); Assert.AreEqual("8 AM", strategy.FormatTime(new DateTime(1900, 2, 3, 8, 3, 12), new ShortTimeFormat(), 'H', 'h', 't', ' ')); Assert.AreEqual("03", strategy.FormatTime(new DateTime(1900, 2, 3, 8, 3, 12), new LongTimeFormat(), 'm')); Thread.CurrentThread.CurrentCulture = new CultureInfo("nl-NL"); Assert.IsTrue(strategy.FormatTime(new DateTime(1900, 2, 3, 8, 3, 12), new ShortTimeFormat(), 'H', 'h', 't', ' ').EndsWith("8", StringComparison.Ordinal)); Assert.AreEqual("03", strategy.FormatTime(new DateTime(1900, 2, 3, 8, 3, 12), new LongTimeFormat(), 'm')); } finally { Thread.CurrentThread.CurrentCulture = currentCulture; } }
public virtual void ShouldUseCultureDuringFormatting() { OverriddenTimeGlobalizationInfo strategy = new OverriddenTimeGlobalizationInfo(); CultureInfo currentCulture = Thread.CurrentThread.CurrentCulture; try { Thread.CurrentThread.CurrentCulture = new CultureInfo("ko-KR"); string formatted = strategy.FormatTime(new DateTime(1900, 1, 1, 5, 5, 5), new ShortTimeFormat()); Assert.AreEqual("오전 5:05", formatted); } finally { Thread.CurrentThread.CurrentCulture = currentCulture; } }
public virtual void ShouldValidateTimeFormatWhenFormatting() { OverriddenTimeGlobalizationInfo strategy = new OverriddenTimeGlobalizationInfo(); strategy.FormatTime(DateTime.Now, null); }