/// <summary> /// Returns a formatted string based on this Range<DateTime> object and the given string format. /// </summary> public static string ToString(this Range <DateTime> @this, string format) { if (@this.From == DateTime.MinValue && @this.To == DateTime.MinValue) { return(string.Empty); } if ("A".Equals(format, StringComparison.OrdinalIgnoreCase)) { if (@this.To != DateTime.MaxValue) { return("{0:d}-{1:d}".FormatWith(@this.From, @this.To)); } else { return("{0:d}-...".FormatWith(@this.From)); } } if ("F".Equals(format, StringComparison.OrdinalIgnoreCase)) { if (@this.To != DateTime.MaxValue) { return("From {0:d} to {1:d}".FormatWith(@this.From, @this.To)); } else { return("From {0:d}".FormatWith(@this.From)); } } if ("T".Equals(format, StringComparison.OrdinalIgnoreCase)) { if (@this.To != DateTime.MaxValue) { return("{0:d} to {1:d}".FormatWith(@this.From, @this.To)); } else { return("{0:d}".FormatWith(@this.From)); } } return(@this.ToString()); }