public void ToStringDisplaySeconds() { NhsTime time = new NhsTime(); string formattedTime = time.ToString(false, CultureInfo.CurrentCulture, true, false, false); TimeSpan parsedTimeSpan = TimeSpan.Parse(formattedTime); Assert.AreEqual <int>(parsedTimeSpan.Seconds, time.TimeValue.Second, "NhsTime DisplaySeconds incorrect"); }
public void ParseNotApproximateTruePassedToToString() { System.DateTime baseDateTime = System.DateTime.Now; NhsTime time = new NhsTime(baseDateTime); Assert.AreEqual <TimeType>(time.TimeType, TimeType.Exact, "TimeType should be Exact when set to a date"); NhsTime.ParseExact(time.ToString(true), CultureInfo.CurrentCulture); }
public void ToStringDisplay12Hour() { int hours = 14; DateTime dateTime = new DateTime(2006, 1, 1, hours, 20, 11); NhsTime time = new NhsTime(dateTime); string formattedTime = time.ToString(false, CultureInfo.CurrentCulture, false, true, false); DateTime parsedDateTime = DateTime.Parse(formattedTime, CultureInfo.CurrentCulture); Assert.AreEqual <int>(parsedDateTime.Hour, hours - 12, "NhsTime Display12Hour incorrect"); }
public void ToStringDisplayAMPM() { NhsTime morningTime = NhsTime.ParseExact("10:00:00", CultureInfo.CurrentCulture); NhsTime afternoonTime = NhsTime.ParseExact("15:00:00", CultureInfo.CurrentCulture); string formattedMorningTime = morningTime.ToString(false, CultureInfo.CurrentCulture, false, true, true); string formattedAfternoonTime = afternoonTime.ToString(false, CultureInfo.CurrentCulture, false, true, true); string morningDesignator = CultureInfo.CurrentCulture.DateTimeFormat.AMDesignator.ToLower(CultureInfo.CurrentCulture); string afternoonDesignator = CultureInfo.CurrentCulture.DateTimeFormat.PMDesignator.ToLower(CultureInfo.CurrentCulture); Assert.IsTrue(formattedMorningTime.Contains(morningDesignator)); Assert.IsTrue(formattedAfternoonTime.Contains(afternoonDesignator)); }
public void ParseNullIndex() { NhsTime time = new NhsTime(); time.TimeType = TimeType.NullIndex; time.NullIndex = 4; NhsTime parsedTime; Assert.IsTrue(NhsTime.TryParseExact(time.ToString(), out parsedTime, CultureInfo.CurrentCulture), string.Format(CultureInfo.InvariantCulture, "TryParse failed with time, {0}", time.ToString())); Assert.AreEqual <TimeType>(time.TimeType, parsedTime.TimeType, "Parse did not error but TimeType does not match"); Assert.AreEqual(time.NullIndex, parsedTime.NullIndex, "Parse did not error but NullIndex does not match"); }
public void ParseApproximate() { System.DateTime baseDateTime = System.DateTime.Now; NhsTime time = new NhsTime(baseDateTime, true); Assert.AreEqual <TimeType>(time.TimeType, TimeType.Approximate, "TimeType should be Approxinmate when set to a date"); NhsTime parsedTime; Assert.IsTrue(NhsTime.TryParseExact(time.ToString(), out parsedTime, CultureInfo.CurrentCulture), string.Format(CultureInfo.InvariantCulture, "TryParse failed with time, {0}", time.ToString())); Assert.AreEqual(time.TimeType, parsedTime.TimeType, "Parse did not error but TimeType does not match"); Assert.AreEqual <string>(time.TimeValue.ToString("HH:mm", CultureInfo.InvariantCulture), parsedTime.TimeValue.ToString("HH:mm", CultureInfo.InvariantCulture), "Parse did not error but TimeValue does not match"); }
/// <summary> /// Refresh the text displayed in the text box. /// </summary> private void RefreshDisplayText() { NhsTime value = this.Value; string[] nullStrings = this.NullStrings; if (value.TimeType != TimeType.NullIndex || nullStrings == null || value.NullIndex < 0 || value.NullIndex >= nullStrings.Length) { this.TextBox.Text = value.ToString( false, CultureInfo.CurrentCulture, this.DisplaySeconds, this.Display12Hour, this.DisplayAMPM); } else { this.TextBox.Text = nullStrings[value.NullIndex]; } }
public void ParseNullIndex() { NhsTime time = new NhsTime(); time.TimeType = TimeType.NullIndex; time.NullIndex = 4; NhsTime parsedTime; Assert.IsTrue(NhsTime.TryParseExact(time.ToString(), out parsedTime, CultureInfo.CurrentCulture), string.Format(CultureInfo.InvariantCulture, "TryParse failed with time, {0}", time.ToString())); Assert.AreEqual<TimeType>(time.TimeType, parsedTime.TimeType, "Parse did not error but TimeType does not match"); Assert.AreEqual(time.NullIndex, parsedTime.NullIndex, "Parse did not error but NullIndex does not match"); }
public void ToStringApproximate() { DateTime baseDateTime = System.DateTime.Now; GlobalizationService gc = new GlobalizationService(); NhsTime time = new NhsTime(baseDateTime, true); Assert.AreEqual(string.Format(CultureInfo.CurrentCulture, "{0} {1}", NhsCui.Toolkit.Test.NhsCui_Toolkit_DateAndTime_Resources_NhsTimeResourcesAccessor.Approximate, baseDateTime.ToString(gc.ShortTimePattern, CultureInfo.CurrentCulture)), time.ToString()); Assert.AreEqual(string.Format(CultureInfo.CurrentCulture, "{0} {1}", NhsCui.Toolkit.Test.NhsCui_Toolkit_DateAndTime_Resources_NhsTimeResourcesAccessor.Approximate, baseDateTime.ToString(gc.ShortTimePattern, CultureInfo.CurrentCulture)), time.ToString(true)); time = new NhsTime(baseDateTime); time.TimeType = TimeType.Approximate; Assert.AreEqual(string.Format(CultureInfo.CurrentCulture, "{0} {1}", NhsCui.Toolkit.Test.NhsCui_Toolkit_DateAndTime_Resources_NhsTimeResourcesAccessor.Approximate, baseDateTime.ToString(gc.ShortTimePattern, CultureInfo.CurrentCulture)), time.ToString()); Assert.AreEqual(string.Format(CultureInfo.CurrentCulture, "{0} {1}", NhsCui.Toolkit.Test.NhsCui_Toolkit_DateAndTime_Resources_NhsTimeResourcesAccessor.Approximate, baseDateTime.ToString(gc.ShortTimePattern, CultureInfo.CurrentCulture)), time.ToString(true)); }
public void ParseApproximate() { System.DateTime baseDateTime = System.DateTime.Now; NhsTime time = new NhsTime(baseDateTime, true); Assert.AreEqual<TimeType>(time.TimeType, TimeType.Approximate, "TimeType should be Approxinmate when set to a date"); NhsTime parsedTime; Assert.IsTrue(NhsTime.TryParseExact(time.ToString(), out parsedTime, CultureInfo.CurrentCulture), string.Format(CultureInfo.InvariantCulture, "TryParse failed with time, {0}", time.ToString())); Assert.AreEqual(time.TimeType, parsedTime.TimeType, "Parse did not error but TimeType does not match"); Assert.AreEqual<string>(time.TimeValue.ToString("HH:mm", CultureInfo.InvariantCulture), parsedTime.TimeValue.ToString("HH:mm", CultureInfo.InvariantCulture), "Parse did not error but TimeValue does not match"); }
public void ParseNotApproximateTruePassedToToString() { System.DateTime baseDateTime = System.DateTime.Now; NhsTime time = new NhsTime(baseDateTime); Assert.AreEqual<TimeType>(time.TimeType, TimeType.Exact, "TimeType should be Exact when set to a date"); NhsTime.ParseExact(time.ToString(true), CultureInfo.CurrentCulture); }
public void ToStringDisplay12Hour() { int hours = 14; DateTime dateTime = new DateTime(2006, 1, 1, hours, 20, 11); NhsTime time = new NhsTime(dateTime); string formattedTime = time.ToString(false, CultureInfo.CurrentCulture, false, true, false); DateTime parsedDateTime = DateTime.Parse(formattedTime, CultureInfo.CurrentCulture); Assert.AreEqual<int>(parsedDateTime.Hour, hours - 12, "NhsTime Display12Hour incorrect"); }
public void ToStringDisplaySeconds() { NhsTime time = new NhsTime(); string formattedTime = time.ToString(false, CultureInfo.CurrentCulture, true, false, false); TimeSpan parsedTimeSpan = TimeSpan.Parse(formattedTime); Assert.AreEqual<int>(parsedTimeSpan.Seconds, time.TimeValue.Second, "NhsTime DisplaySeconds incorrect"); }
public void ToStringApproximate() { DateTime baseDateTime = System.DateTime.Now; GlobalizationService gc = new GlobalizationService(); NhsTime time = new NhsTime(baseDateTime, true); Assert.AreEqual(string.Format(CultureInfo.CurrentCulture, "{0} {1}", NhsCui.Toolkit.Test.NhsCui_Toolkit_DateAndTime_Resources_NhsTimeResourcesAccessor.Approximate, baseDateTime.ToString(gc.ShortTimePattern, CultureInfo.CurrentCulture)), time.ToString()); Assert.AreEqual(string.Format(CultureInfo.CurrentCulture, "{0} {1}", NhsCui.Toolkit.Test.NhsCui_Toolkit_DateAndTime_Resources_NhsTimeResourcesAccessor.Approximate, baseDateTime.ToString(gc.ShortTimePattern, CultureInfo.CurrentCulture)), time.ToString(true)); time = new NhsTime(baseDateTime); time.TimeType = TimeType.Approximate; Assert.AreEqual(string.Format(CultureInfo.CurrentCulture, "{0} {1}", NhsCui.Toolkit.Test.NhsCui_Toolkit_DateAndTime_Resources_NhsTimeResourcesAccessor.Approximate, baseDateTime.ToString(gc.ShortTimePattern, CultureInfo.CurrentCulture)), time.ToString()); Assert.AreEqual(string.Format(CultureInfo.CurrentCulture, "{0} {1}", NhsCui.Toolkit.Test.NhsCui_Toolkit_DateAndTime_Resources_NhsTimeResourcesAccessor.Approximate, baseDateTime.ToString(gc.ShortTimePattern, CultureInfo.CurrentCulture)), time.ToString(true)); }