Table of Contents

Class DateRange

Namespace
Geotab.Checkmate.ObjectModel
Assembly
Geotab.Checkmate.ObjectModel.dll

A date range.

public class DateRange : IDateRange, IEquatable<DateRange>
Inheritance
DateRange
Implements
Derived
Inherited Members

Constructors

DateRange()

Initializes a new instance of the DateRange class.

public DateRange()

DateRange(DateTime?, DateTime?)

Initializes a new instance of the DateRange class.

public DateRange(DateTime? from, DateTime? to)

Parameters

from DateTime?

The "From" Date.

to DateTime?

The "To" Date.

Properties

From

Gets the first or starting date in the date range.

public DateTime? From { get; }

Property Value

DateTime?

DateTime

To

Gets the second or ending date in the date range.

public DateTime? To { get; }

Property Value

DateTime?

DateTime

Methods

AreDateRangesInclusive(DateTime?, DateTime?, DateTime?, DateTime?)

Tests whether DateRange 1 inclusive DateRange 2.

public static bool AreDateRangesInclusive(DateTime? from0, DateTime? to0, DateTime? from1, DateTime? to1)

Parameters

from0 DateTime?

The first "From" Date.

to0 DateTime?

The first "To" Date.

from1 DateTime?

The second "From" Date.

to1 DateTime?

The second "To" Date.

Returns

bool

Returns true if range1 inclusive range2.

Contains(DateTime?, bool)

Checks if a date falls inside this date range, inclusively, or, optionally, exclusively if false is passed in for inclusive.

public bool Contains(DateTime? date, bool inclusive = true)

Parameters

date DateTime?

The date.

inclusive bool

True by default.

Returns

bool

True, if the date is inside this range.

Examples

|---date---|

Deconstruct(out DateTime, out DateTime)

Deconstructs this range into its To and From date.

public void Deconstruct(out DateTime from, out DateTime to)

Parameters

from DateTime

The from.

to DateTime

The to.

DoDateRangesIntersect(DateTime?, DateTime?, DateTime?, DateTime?, bool)

Tests whether 2 ranges intersect.

public static bool DoDateRangesIntersect(DateTime? from0, DateTime? to0, DateTime? from1, DateTime? to1, bool includeBounds = true)

Parameters

from0 DateTime?

The first "From" Date.

to0 DateTime?

The first "To" Date.

from1 DateTime?

The second "From" Date.

to1 DateTime?

The second "To" Date.

includeBounds bool

Intersect bounds of non-zero-duration ranges. Default value: true.

Returns

bool

Returns true if date ranges intersect.

Duration()

Get duration between "From" Date to "To" Date.

public TimeSpan Duration()

Returns

TimeSpan

The duration TimeSpan.

Equals(DateRange?)

public virtual bool Equals(DateRange? other)

Parameters

other DateRange

Returns

bool

Equals(object?)

Determines whether the specified object, is equal to this instance.

public override bool Equals(object? obj)

Parameters

obj object

The object to compare with this instance.

Returns

bool

true if the specified object is equal to this instance; otherwise, false.

GetHashCode()

Returns a hash code for this instance.

public override int GetHashCode()

Returns

int

A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.

Intersect(DateRange, bool)

Gets the intersecting duration between this range and another.

public TimeSpan Intersect(DateRange range, bool includeBounds = true)

Parameters

range DateRange

The range.

includeBounds bool

The includeBounds.

Returns

TimeSpan

TimeSpan

Intersects(DateRange, bool)

Checks if another range starts or stops inside this range, inclusively, or, optionally, exclusively if false is passed in for inclusive.

public bool Intersects(DateRange range, bool inclusive = true)

Parameters

range DateRange

The range.

inclusive bool

True by default.

Returns

bool

True, if the date is inside this range.

Examples

|---range1---|
    |---range2---|

IntersectsWith(DateRange, bool)

Checks if another range starts or stops inside this range, inclusively, or, optionally, exclusively if false is passed in for inclusive.

public bool IntersectsWith(DateRange range, bool inclusive = true)

Parameters

range DateRange

The range.

inclusive bool

True by default.

Returns

bool

True, if the date is inside this range.

Examples

|---range1---|
    |---range2---|

ToString()

Returns a string that represents the current object.

public override string ToString()

Returns

string

A string that represents the current object.

Operators

operator ==(DateRange?, DateRange?)

Checks if two ranges are equal.

public static bool operator ==(DateRange? range1, DateRange? range2)

Parameters

range1 DateRange

The range1.

range2 DateRange

The range2.

Returns

bool

True if two ranges are equal.

operator >(DateRange?, DateRange?)

Checks if a range's From date is greater than another's To date (i.e. range1 starts after range2 ends; range2 comes before range1).

public static bool operator >(DateRange? range1, DateRange? range2)

Parameters

range1 DateRange

The range1.

range2 DateRange

The range2.

Returns

bool

True if range1 starts after range2 ends.

Examples

|---range2---|___|---range1---|

Remarks

Note that the arrow of the comparison points from the From date to the To date of a range (i.e. range > date means range.From > date, date < range means date < range.From).

operator >(DateRange?, DateTime?)

Checks if a range's From date is greater than a date (i.e. the range starts after the date; the date comes before the range starts).

public static bool operator >(DateRange? range, DateTime? date)

Parameters

range DateRange

The range.

date DateTime?

The date.

Returns

bool

True if the range starts after the date.

Examples

date___|---range---|

Remarks

Note that the arrow of the comparison points from the From date to the To date of a range (i.e. range > date means range.From > date, date < range means date < range.From).

operator >(DateTime?, DateRange?)

Checks if a date is greater than a date range's To date (i.e. the range ends before the date).

public static bool operator >(DateTime? date, DateRange? range)

Parameters

date DateTime?

The date.

range DateRange

The range.

Returns

bool

True if the range ends before the date.

Examples

|---range---|___date

Remarks

Note that the arrow of the comparison points from the From date to the To date of a range (i.e. range > date means range.From > date, date < range means date < range.From).

operator >=(DateRange?, DateRange?)

Checks if a range's From date is greater than or equal to another's To date (i.e. range1 starts after or at the end of range2).

public static bool operator >=(DateRange? range1, DateRange? range2)

Parameters

range1 DateRange

The range1.

range2 DateRange

The range2.

Returns

bool

True if range1 starts after or at the end of range2.

Examples

|---range2---|___|---range1---| OR |---range2---||---range1---|

Remarks

Note that the arrow of the comparison points from the From date to the To date of a range (i.e. r1 > r2 means r1.From > r2.To, r1 < r2 means r1.To < r2.From).

operator >=(DateRange?, DateTime?)

Checks if a range's From date is greater than or equal to a date (i.e. the range starts after or at the date).

public static bool operator >=(DateRange? range, DateTime? date)

Parameters

range DateRange

The range.

date DateTime?

The date.

Returns

bool

True if a range's From date is greater than or equal to a date

Examples

date|---range---| OR date___|---range---|

Remarks

Note that the arrow of the comparison points from the From date to the To date of a range (i.e. range > date means range.From > date, date < range means date < range.From).

operator >=(DateTime?, DateRange?)

Checks if a date is greater than or equal to a range's To date (i.e. the range ends before or on the date).

public static bool operator >=(DateTime? date, DateRange? range)

Parameters

date DateTime?

The date.

range DateRange

The range.

Returns

bool

True if a date is greater than or equal to a range's To date.

Examples

|---range---|___date OR |---range---|date

Remarks

Note that the arrow of the comparison points from the From date to the To date of a range (i.e. range > date means range.From > date, date < range means date < range.From).

operator !=(DateRange?, DateRange?)

Checks if two ranges are not equal (i.e. range a/b starts before range b/a).

public static bool operator !=(DateRange? range1, DateRange? range2)

Parameters

range1 DateRange

The range1.

range2 DateRange

The range2.

Returns

bool

True if two ranges are not equal.

operator <(DateRange?, DateRange?)

Checks if a range's To date is less than another's From date (i.e. range1 starts and ends before range2; range1 comes before range2).

public static bool operator <(DateRange? range1, DateRange? range2)

Parameters

range1 DateRange

The range1.

range2 DateRange

The range2.

Returns

bool

True if range1 starts and ends before range2.

Examples

|---range1---|___|---range2---|

Remarks

Note that the arrow of the comparison points from the From date to the To date of a range (i.e. r1 > r2 means r1.From > r2.To, r1 < r2 means r1.To < r2.From).

operator <(DateRange?, DateTime?)

Checks if a range's To date is less than a date (i.e. the range ends before the date).

public static bool operator <(DateRange? range, DateTime? date)

Parameters

range DateRange

The range.

date DateTime?

The date.

Returns

bool

True if the range ends before the date.

Examples

date---|---range---|

Remarks

Note that the arrow of the comparison points from the From date to the To date of a range (i.e. range > date means range.From > date, date < range means date < range.From).

operator <(DateTime?, DateRange?)

Checks if a date is less than a date range's From date (i.e. the range starts after the date).

public static bool operator <(DateTime? date, DateRange? range)

Parameters

date DateTime?

The date.

range DateRange

The range.

Returns

bool

True if a date is less than a date range's From date.

Examples

date___|---range---|

Remarks

Note that the arrow of the comparison points from the From date to the To date of a range (i.e. range > date means range.From > date, date < range means date < range.From).

operator <=(DateRange?, DateRange?)

Checks if a range's To date is less than or equal to another's From date (i.e. range1 ends anytime before or at the start of range2).

public static bool operator <=(DateRange? range1, DateRange? range2)

Parameters

range1 DateRange

The range1.

range2 DateRange

The range2.

Returns

bool

True if range1 ends before or at the start of range2.

Examples

|---range1---|___|---range2---| OR |---range1---||---range2---|

Remarks

Note that the arrow of the comparison points from the From date to the To date of a range (i.e. r1 > r2 means r1.From > r2.To, r1 < r2 means r1.To < r2.From).

operator <=(DateRange?, DateTime?)

Checks if a range's To date is less than or equal to a date (i.e. the range ends before or on the date).

public static bool operator <=(DateRange? range, DateTime? date)

Parameters

range DateRange

The range.

date DateTime?

The date.

Returns

bool

True if a range's To date is less than or equal to a date.

Examples

|---range---|___date OR |---range---|date

Remarks

Note that the arrow of the comparison points from the From date to the To date of a range (i.e. range > date means range.From > date, date < range means date < range.From).

operator <=(DateTime?, DateRange?)

Checks if a date is less than or equal to the range's From date (i.e. the range starts after or on the date).

public static bool operator <=(DateTime? date, DateRange? range)

Parameters

date DateTime?

The date.

range DateRange

The range.

Returns

bool

True if a date is less than or equal to the range's From date.

Examples

date|---range---| OR date___|---range---|

Remarks

Note that the arrow of the comparison points from the From date to the To date of a range (i.e. range > date means range.From > date, date < range means date < range.From).