public void FormatDateValue_ReturnsDate() { var formatter = new DateTimeFormatter(); using (new CultureScope("en-US")) { Assert.That(formatter.FormatDateValue(new DateTime(2013, 06, 20, 14, 30, 40)), Is.EqualTo("6/20/2013")); } }
/// <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; } }