/// <summary> /// Creates a new instance of the <see cref="ApproximateDateTime"/> /// class with the specified date and time. /// </summary> /// /// <param name="approximateDate"> /// The approximation of the date. /// </param> /// /// <param name="approximateTime"> /// The approximation of the time. /// </param> /// /// <exception cref="ArgumentNullException"> /// If <paramref name="approximateDate"/> is <b>null</b>. /// </exception> /// public ApproximateDateTime( ApproximateDate approximateDate, ApproximateTime approximateTime) : this(approximateDate) { _approximateTime = approximateTime; }
/// <summary> /// Creates a new instance of the <see cref="ApproximateDateTime"/> /// class with the specified date. /// </summary> /// /// <param name="approximateDate"> /// The approximation of the date. /// </param> /// /// <exception cref="ArgumentNullException"> /// The <paramref name="approximateDate"/> parameter is <b>null</b>. /// </exception> /// public ApproximateDateTime(ApproximateDate approximateDate) { Validator.ThrowIfArgumentNull(approximateDate, nameof(approximateDate), Resources.ApproximateDateTimeDateNull); _approximateDate = approximateDate; _approximateTime = null; }
internal string ToString(IFormatProvider formatProvider) { StringBuilder result = new StringBuilder(50); if (string.IsNullOrEmpty(Description)) { result.Append(ApproximateDate.ToString(formatProvider)); if (ApproximateTime != null && ApproximateTime.HasValue) { string time = ApproximateTime.ToString(formatProvider); if (!string.IsNullOrEmpty(time)) { result.Append(" "); result.Append(time); } } if (TimeZone != null) { result.Append(" "); result.Append(TimeZone.Text); } } else { result.Append(Description); } return(result.ToString()); }
/// <summary> /// Creates a new instance of the <see cref="ApproximateDateTime"/> /// class with the specified date, time, and time zone. /// </summary> /// /// <param name="approximateDate"> /// The approximation of the date. /// </param> /// /// <param name="approximateTime"> /// The approximation of the time. /// </param> /// /// <param name="timeZone"> /// The time zone of the approximate time. /// </param> /// /// <exception cref="ArgumentNullException"> /// The <paramref name="approximateDate"/> parameter is <b>null</b>. /// </exception> /// public ApproximateDateTime( ApproximateDate approximateDate, ApproximateTime approximateTime, CodableValue timeZone) : this(approximateDate, approximateTime) { _timeZone = timeZone; }
/// <summary> /// Populates the data for the approximate date and time from the XML. /// </summary> /// /// <param name="navigator"> /// The XML node representing the approximate date and time. /// </param> /// /// <exception cref="ArgumentNullException"> /// The <paramref name="navigator"/> parameter is <b>null</b>. /// </exception> /// public override void ParseXml(XPathNavigator navigator) { Validator.ThrowIfNavigatorNull(navigator); XPathNavigator structuredNav = navigator.SelectSingleNode("structured"); if (structuredNav != null) { _approximateDate = new ApproximateDate(); _approximateDate.ParseXml( structuredNav.SelectSingleNode("date")); XPathNavigator timeNav = structuredNav.SelectSingleNode("time"); if (timeNav != null) { _approximateTime = new ApproximateTime(); _approximateTime.ParseXml(timeNav); } else { _approximateTime = null; } XPathNavigator tzNav = structuredNav.SelectSingleNode("tz"); if (tzNav != null) { _timeZone = new CodableValue(); _timeZone.ParseXml(tzNav); } } else { _description = navigator.SelectSingleNode("descriptive").Value; _approximateDate = null; } }
/// <summary> /// Compares the specified object to this <see cref="ApproximateDateTime"/> /// object. /// </summary> /// /// <param name="other"> /// The date to be compared. /// </param> /// /// <returns> /// A 32-bit signed integer that indicates the relative order of the /// objects being compared. If the result is less than zero, the /// instance is less than <paramref name="other"/>. If the result is zero, /// the instance is equal to <paramref name="other"/>. If the result is /// greater than zero, the instance is greater than /// <paramref name="other"/>. /// </returns> /// public int CompareTo(LocalDateTime other) { if (ApproximateDate == null) { return(-1); } int result = ApproximateDate.CompareTo(other.Date); if (result != 0) { return(result); } if (ApproximateTime == null) { return(-1); } return(ApproximateTime.CompareTo(other.TimeOfDay)); }
/// <summary> /// Compares the specified object to this <see cref="ApproximateDateTime"/> /// object. /// </summary> /// /// <param name="other"> /// The date to be compared. /// </param> /// /// <returns> /// A 32-bit signed integer that indicates the relative order of the /// objects being compared. If the result is less than zero, the /// instance is less than <paramref name="other"/>. If the result is zero /// the instance is equal to <paramref name="other"/>. If the result is /// greater than zero, the instance is greater than /// <paramref name="other"/>. /// </returns> /// public int CompareTo(ApproximateDateTime other) { if (other == null) { return(1); } if (ApproximateDate == null) { if (other.ApproximateDate != null) { return(-1); } return(Description.CompareTo(other.Description)); } int result = ApproximateDate.CompareTo(other.ApproximateDate); if (result != 0) { return(result); } if (ApproximateTime == null) { if (other.ApproximateTime != null) { return(-1); } return(0); } return(ApproximateTime.CompareTo(other.ApproximateTime)); }
/// <summary> /// Creates a new instance of the <see cref="ApproximateDateTime"/> /// class from a DateTime instance. /// </summary> /// <param name="dateTime">The local date/time to copy from.</param> /// <remarks> /// The time zone is not set by this constructor. /// </remarks> public ApproximateDateTime(LocalDateTime dateTime) { _approximateDate = new ApproximateDate(dateTime.Year, dateTime.Month, dateTime.Day); _approximateTime = new ApproximateTime(dateTime.Hour, dateTime.Minute, dateTime.Second, dateTime.Millisecond); }