DateRange Struct
Represents a date range, which is an inclusive pair of DateTime
objects representing dates.
public struct DateRange : IComparable<DateRange>, IEquatable<DateRange>
- Implements:
- IComparable<DateRange> IEquatable<DateRange>
Properties
Count
Gets the number of dates contained in the range.
EndDate
Gets the end date of this range.
StartDate
Gets the start date of this range.
Methods
CompareTo(DateRange)
Compares the current object with another object of the same type.
public int CompareTo(DateRange other)
Parameter | Type | Description |
---|---|---|
other | DateRange | An object to compare with this object. |
Returns
- int:
A 32-bit signed integer that indicates the relative order of the objects being compared. The return value has the following meanings: Less than zero means this object is less than the
other
parameter. Zero means this object is equal toother
. Greater than zero means this object is greater thanother
.
Contains(DateRange)
Determines whether the specified date range is contained in this range.
public bool Contains(DateRange dateRange)
Parameter | Type | Description |
---|---|---|
dateRange | DateRange | The date range. |
Returns
- bool:
true
if the specified date range is contained in this range; otherwise,false
.
Contains(DateTime)
Determines whether the specified date is contained in this range.
public bool Contains(DateTime date)
Parameter | Type | Description |
---|---|---|
date | DateTime | The date to examine. |
Returns
- bool:
true
if the specified date is contained in this range; otherwise,false
.
Equals(DateRange)
Indicates whether the current object is equal to another object of the same type.
public bool Equals(DateRange other)
Parameter | Type | Description |
---|---|---|
other | DateRange | An object to compare with this object. |
Returns
- bool:
true if the current object is equal to the
other
parameter; otherwise, false.
Equals(object)
Indicates whether this instance and a specified object are equal.
public override bool Equals(object obj)
Parameter | Type | Description |
---|---|---|
obj | object | Another object to compare to. |
Returns
- bool:
true
ifobj
and this instance are the same type and represent the same value; otherwise,false
.
FromDate(DateTime)
Gets a date range for specified single date.
public static DateRange FromDate(DateTime date)
Parameter | Type | Description |
---|---|---|
date | DateTime | The start date. |
Returns
- DateRange:
A date range for the specified single date.
FromDecade(DateTime)
Gets a date range for the decade that contains the specified date.
public static DateRange FromDecade(DateTime date)
Parameter | Type | Description |
---|---|---|
date | DateTime | The date. |
Returns
- DateRange:
A date range for the decade that contains the specified date.
FromMonth(DateTime)
Gets a date range for the month that contains the specified date.
public static DateRange FromMonth(DateTime date)
Parameter | Type | Description |
---|---|---|
date | DateTime | The date. |
Returns
- DateRange:
A date range for the month that contains the specified date.
FromRange(DateTime, DateTime)
Gets a date range for specified range.
public static DateRange FromRange(DateTime startDate, DateTime endDate)
Parameter | Type | Description |
---|---|---|
startDate | DateTime | The start date. |
endDate | DateTime | The end date. |
Returns
- DateRange:
A date range for the specified range.
FromYear(DateTime)
Gets a date range for the year that contains the specified date.
public static DateRange FromYear(DateTime date)
Parameter | Type | Description |
---|---|---|
date | DateTime | The date. |
Returns
- DateRange:
A date range for the year that contains the specified date.
GetEnumerator()
Returns an enumerator that iterates through the collection.
public IEnumerator<DateTime> GetEnumerator()
Returns
- IEnumerator<DateTime>:
A IEnumerator<T> that can be used to iterate through the collection.
GetHashCode()
Returns the hash code for this instance.
public override int GetHashCode()
Returns
- int:
A 32-bit signed integer that is the hash code for this instance.
OverlapsWith(DateRange)
Determines whether the specified date range overlaps with, or crosses, this range.
public bool OverlapsWith(DateRange otherRange)
Parameter | Type | Description |
---|---|---|
otherRange | DateRange | The date range to examine. |
Returns
- bool:
true
if the specified date range overlaps with, or crosses, this range; otherwisefalse
.
ToString()
Returns the fully qualified type name of this instance.
Operators
operator ==(DateRange, DateRange)
Compares two DateRange objects to determine whether they are equal.
public static bool operator ==(DateRange left, DateRange right)
Parameter | Type | Description |
---|---|---|
left | DateRange | The left. |
right | DateRange | The right. |
Returns
operator >(DateRange, DateRange)
Compares two DateRange objects to determine whether the first instance is greater than the second instance.
public static bool operator >(DateRange left, DateRange right)
Parameter | Type | Description |
---|---|---|
left | DateRange | The left. |
right | DateRange | The right. |
Returns
operator !=(DateRange, DateRange)
Compares two DateRange objects to determine whether they are not equal.
public static bool operator !=(DateRange left, DateRange right)
Parameter | Type | Description |
---|---|---|
left | DateRange | The left. |
right | DateRange | The right. |
Returns
operator <(DateRange, DateRange)
Compares two DateRange objects to determine whether the first instance is less than the second instance.
public static bool operator <(DateRange left, DateRange right)
Parameter | Type | Description |
---|---|---|
left | DateRange | The left. |
right | DateRange | The right. |