public virtual void ShouldDetermineTextPositionInDateTime() { OverriddenTimeGlobalizationInfo strategy = new OverriddenTimeGlobalizationInfo(); CultureInfo currentCulture = Thread.CurrentThread.CurrentCulture; string date = "04:12:22"; ITimeFormat military = new CustomTimeFormat("HH:mm:ss"); Assert.AreEqual(0, strategy.GetTextPositionForTimeUnit(date, TimeSpan.FromHours(1), military)); Assert.AreEqual(3, strategy.GetTextPositionForTimeUnit(date, TimeSpan.FromMinutes(10), military)); Assert.AreEqual(4, strategy.GetTextPositionForTimeUnit(date, TimeSpan.FromMinutes(1), military)); Assert.AreEqual(6, strategy.GetTextPositionForTimeUnit(date, TimeSpan.FromSeconds(10), military)); Assert.AreEqual(7, strategy.GetTextPositionForTimeUnit(date, TimeSpan.FromSeconds(1), military)); try { Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US"); date = "4:12:22 PM"; ITimeFormat longFormat = new LongTimeFormat(); Assert.AreEqual(0, strategy.GetTextPositionForTimeUnit(date, TimeSpan.FromHours(1), longFormat)); Assert.AreEqual(8, strategy.GetTextPositionForTimeUnit(date, TimeSpan.FromHours(12), longFormat)); Assert.AreEqual(8, strategy.GetTextPositionForTimeUnit(date, TimeSpan.FromHours(12), longFormat)); } finally { Thread.CurrentThread.CurrentCulture = currentCulture; } }
public virtual void ShouldDetermineTimeUnitAtPositionsInString() { OverriddenTimeGlobalizationInfo strategy = new OverriddenTimeGlobalizationInfo(); CultureInfo currentCulture = Thread.CurrentThread.CurrentCulture; string date = "04:12:22"; ITimeFormat military = new CustomTimeFormat("HH:mm:ss"); Assert.AreEqual(TimeSpan.FromHours(1), strategy.GetTimeUnitAtTextPosition(date, 0, military)); Assert.AreEqual(TimeSpan.FromHours(1), strategy.GetTimeUnitAtTextPosition(date, 1, military)); Assert.AreEqual(TimeSpan.FromHours(1), strategy.GetTimeUnitAtTextPosition(date, 2, military)); Assert.AreEqual(TimeSpan.FromMinutes(10), strategy.GetTimeUnitAtTextPosition(date, 3, military)); Assert.AreEqual(TimeSpan.FromMinutes(1), strategy.GetTimeUnitAtTextPosition(date, 4, military)); Assert.AreEqual(TimeSpan.FromMinutes(1), strategy.GetTimeUnitAtTextPosition(date, 5, military)); Assert.AreEqual(TimeSpan.FromSeconds(10), strategy.GetTimeUnitAtTextPosition(date, 6, military)); Assert.AreEqual(TimeSpan.FromSeconds(1), strategy.GetTimeUnitAtTextPosition(date, 7, military)); Assert.AreEqual(TimeSpan.FromSeconds(1), strategy.GetTimeUnitAtTextPosition(date, 8, military)); try { Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US"); date = "4:12:22 PM"; ITimeFormat longFormat = new LongTimeFormat(); Assert.AreEqual(TimeSpan.FromHours(1), strategy.GetTimeUnitAtTextPosition(date, 0, longFormat)); Assert.AreEqual(TimeSpan.FromSeconds(1), strategy.GetTimeUnitAtTextPosition(date, 7, longFormat)); Assert.AreEqual(TimeSpan.FromHours(12), strategy.GetTimeUnitAtTextPosition(date, 8, longFormat)); Assert.AreEqual(TimeSpan.FromHours(12), strategy.GetTimeUnitAtTextPosition(date, 9, longFormat)); Assert.AreEqual(TimeSpan.FromHours(12), strategy.GetTimeUnitAtTextPosition(date, 10, longFormat)); } finally { Thread.CurrentThread.CurrentCulture = currentCulture; } }
/// <summary> /// <paramref name="dateTime"/>을 Long Time 형식의 문자열로 표현합니다. /// </summary> public string GetLongTime(DateTime dateTime) { return(LongTimeFormat.IsNotWhiteSpace() ? dateTime.ToString(LongTimeFormat) : dateTime.ToLongTimeString()); }