public void XsdDuration_ToTimespan() { var duration = new XsdDuration(negative: false, years: 1, months: 2, days: 3, hours: 4, minutes: 5, seconds: 6, nanoseconds: 1000000); duration.ToTimeSpan().Should().Be( new TimeSpan(365 * 1 + 2 * 30 + 3, 4, 5, 6, 1)); }
public void XsdDuration_ToTimespanNegative() { var duration = new XsdDuration(negative: true, years: 6, months: 5, days: 4, hours: 3, minutes: 2, seconds: 1, nanoseconds: 100000000); duration.ToTimeSpan().Should().Be( new TimeSpan(365 * 6 + 5 * 30 + 4, 3, 2, 1, 100).Negate()); }
///<include file='doc\XmlConvert.uex' path='docs/doc[@for="XmlConvert.ToTimeSpan"]/*' /> /// <devdoc> /// <para>[To be supplied.]</para> /// </devdoc> public static TimeSpan ToTimeSpan(string s) { XsdDuration duration; TimeSpan timeSpan; try { duration = new XsdDuration(s); } catch (Exception) { // Remap exception for v1 compatibility throw new FormatException(SR.Format(SR.XmlConvert_BadFormat, s, "TimeSpan")); } timeSpan = duration.ToTimeSpan(); return(timeSpan); }