DateRange¶
Concrete, mutable begin/end date-pair implementation of IDateRange, with value-equality semantics, string round-tripping, and a shared empty-range singleton.
Purpose¶
- Concrete, mutable begin/end date-pair implementation of
IDateRange, with value-equality semantics, string round-tripping, and a shared empty-range singleton.
Context¶
- Namespace:
SAIF.Common - Assembly/package:
SAIF.Framework.Common
Public members¶
| Member | Signature | Purpose |
|---|---|---|
| BeginDate | public DateTime BeginDate { get; set; } |
The inclusive start of the range. |
| EndDate | public DateTime EndDate { get; set; } |
The inclusive end of the range. |
| DefaultToStringDelimiter | public const string DefaultToStringDelimiter = "-" |
Default separator used between the two dates when formatting with ToString. |
| DateRange() | public DateRange() |
Parameterless constructor; sets BeginDate to DateTime.MinValue and EndDate to DateTime.MaxValue (an open-ended range), not the DateTime default. |
| DateRange(DateTime beginDate) | public DateRange(DateTime beginDate) |
Constructs a range starting at beginDate with EndDate set to DateTime.MaxValue (open-ended). |
| DateRange(DateTime beginDate, DateTime endDate) | public DateRange(DateTime beginDate, DateTime endDate) |
Constructs a range from explicit begin/end dates; if endDate is DateTime.MinValue it is coerced to DateTime.MaxValue. (BR-033) |
| DateRange(IDateRange dateRange) | public DateRange(IDateRange dateRange) |
Copy constructor from any IDateRange implementation. |
| operator ==(DateRange, IDateRange) | public static bool operator ==(DateRange d1, IDateRange d2) |
Compares two ranges by BeginDate/EndDate value equality; dereferences both operands directly, so a null d1 or d2 raises a NullReferenceException rather than being handled. |
| operator !=(DateRange, IDateRange) | public static bool operator !=(DateRange d1, IDateRange d2) |
Inverse of the equality operator; shares the same null-dereference behavior. |
| Equals(object) | public override bool Equals(object obj) |
Structural equality against another IDateRange; delegates to the equality operator. |
| GetHashCode() | public override int GetHashCode() |
Combines BeginDate and EndDate hash codes. |
| ToString(string delimiter) | public string ToString(string delimiter = DefaultToStringDelimiter) |
Formats as "{BeginDate}{delimiter}{EndDate}" using each date's ToShortDateString(). |
| ToString(string beginDateFormat, string endDateFormat, string delimiter) | public string ToString(string beginDateFormat, string endDateFormat, string delimiter = DefaultToStringDelimiter) |
Formats each date with its own supplied format string. |
| Parse(string date, string delimiter) | public static DateRange Parse(string date, string delimiter = DefaultToStringDelimiter) |
Static factory that splits date on delimiter and parses each side as a DateTime, returning a populated DateRange; any exception during parsing is swallowed and an empty DateRange() is returned instead. (BR-031) |
| Empty | public static DateRange Empty { get; } |
Shared, effectively read-only instance representing an unset/empty range for defaulting purposes. |
Sources¶
Common/SAIF.Common/Classes/DateRange.cs