public void FormatTimeValue_WithShowSecondsFalse_ReturnsTimeWithoutSeconds() { var formatter = new DateTimeFormatter(); using (new CultureScope("en-US")) { Assert.That(formatter.FormatTimeValue(new DateTime(2013, 06, 20, 5, 30, 40), false), Is.EqualTo("5:30 AM")); } }
public void FormatTimeValue_WithShowSecondsTrue_ReturnsTimeWithSeconds() { var formatter = new DateTimeFormatter(); using (new CultureScope("en-US")) { Assert.That(formatter.FormatTimeValue(new DateTime(2013, 06, 20, 14, 30, 40), true), Is.EqualTo("2:30:40 PM")); } }
/// <summary> /// Sets the value from the backing field. /// </summary> /// <remarks> /// <para>Setting the value via this method does not affect the control's dirty state.</para> /// </remarks> protected void SetValue(DateTime?value) { _savedDateTimeValue = value; if (!_savedDateTimeValue.HasValue) { InternalDateValue = null; InternalTimeValue = null; return; } try { InternalDateValue = DateTimeFormatter.FormatDateValue(_savedDateTimeValue.Value); } catch (InvalidCastException e) { throw new ArgumentException("Expected type '" + _actualValueType + "', but was '" + value.GetType().FullName + "'.", "value", e); } if (ActualValueType == BocDateTimeValueType.DateTime || ActualValueType == BocDateTimeValueType.Undefined) { try { InternalTimeValue = DateTimeFormatter.FormatTimeValue(_savedDateTimeValue.Value, ShowSeconds); } catch (InvalidCastException e) { throw new ArgumentException( "Expected type '" + _actualValueType + "', but was '" + value.GetType().FullName + "'.", "value", e); } } else { InternalTimeValue = null; } }