Class TimeRange
Represents a range of time from First to Last. First and Last are both considered to be included in the range. The legal range of values is from the unix epoch, midnight 1/1/1970, to DateTime.MaxValue.
Inherited Members
Namespace: Cognite.Extractor.Common
Assembly: Cognite.Common.dll
Syntax
public sealed class TimeRange
Constructors
| Edit this page View SourceTimeRange(DateTime, DateTime)
Initialize a TimeRange object from two timestamps.
Declaration
public TimeRange(DateTime first, DateTime last)
Parameters
Type | Name | Description |
---|---|---|
DateTime | first | First point in the time range |
DateTime | last | Last point in the time range |
Fields
| Edit this page View SourceComplete
The largest legal range, (Epoch, DateTime.MaxValue). Extending a complete range will return the complete range. Contracting a complete range will return the given range.
Declaration
public static readonly TimeRange Complete
Field Value
Type | Description |
---|---|
TimeRange |
Empty
An empty range where first > last, and both are at the extreme range, (DateTime.MaxValue, Epoch). Extending an empty range will return the given range Contracting an empty range will return the empty range
Declaration
public static readonly TimeRange Empty
Field Value
Type | Description |
---|---|
TimeRange |
Properties
| Edit this page View SourceFirst
First point in the range
Declaration
public DateTime First { get; }
Property Value
Type | Description |
---|---|
DateTime |
IsEmpty
True if there are no points in the range at all (first > last).
Declaration
public bool IsEmpty { get; }
Property Value
Type | Description |
---|---|
bool |
Last
Last point in the range
Declaration
public DateTime Last { get; }
Property Value
Type | Description |
---|---|
DateTime |
Methods
| Edit this page View SourceAfter(DateTime)
Check if t
is after the last point in the range.
Declaration
public bool After(DateTime t)
Parameters
Type | Name | Description |
---|---|---|
DateTime | t | Datetime to test |
Returns
Type | Description |
---|---|
bool | True if |
Before(DateTime)
Check if t
is before the first point in the range.
Declaration
public bool Before(DateTime t)
Parameters
Type | Name | Description |
---|---|---|
DateTime | t | Datetime to test |
Returns
Type | Description |
---|---|
bool | True if |
Contains(DateTime)
True if given datetime is inside the range
Declaration
public bool Contains(DateTime t)
Parameters
Type | Name | Description |
---|---|---|
DateTime | t | DateTime to test |
Returns
Type | Description |
---|---|
bool |
Contract(TimeRange)
Returns a new TimeRange contracted by the given TimeRange New TimeRange is the latest start point and the earliest end point.
Declaration
public TimeRange Contract(TimeRange newRange)
Parameters
Type | Name | Description |
---|---|---|
TimeRange | newRange | Extending range |
Returns
Type | Description |
---|---|
TimeRange | A new TimeRange contracted by |
Contract(DateTime?, DateTime?)
Return a new TimeRange contracted by the given timestamps. New TimeRange is the latest start point and earliest end point. Letting first or last be null will keep the existing value for that end of the range.
Declaration
public TimeRange Contract(DateTime? first, DateTime? last)
Parameters
Type | Name | Description |
---|---|---|
DateTime? | first | First point in contracting range |
DateTime? | last | Last point in contracting range |
Returns
Type | Description |
---|---|
TimeRange | A new TimeRange contracted by |
Equals(object?)
Compares this time range with the provided object and returns true if they are equal
Declaration
public override bool Equals(object? obj)
Parameters
Type | Name | Description |
---|---|---|
object | obj | Object to compare |
Returns
Type | Description |
---|---|
bool | true, if equal. false otherwise |
Overrides
| Edit this page View SourceExtend(TimeRange)
Returns a new TimeRange extended by the given TimeRange New TimeRange is the earliest start point and the latest end point.
Declaration
public TimeRange Extend(TimeRange newRange)
Parameters
Type | Name | Description |
---|---|---|
TimeRange | newRange | Extending range |
Returns
Type | Description |
---|---|
TimeRange | A new TimeRange extended by |
Extend(DateTime?, DateTime?)
Return a new TimeRange extended by the given timestamps. New TimeRange is the earliest start point and the latest end point. Letting first or last be null will keep the existing value for that end of the range.
Declaration
public TimeRange Extend(DateTime? first, DateTime? last)
Parameters
Type | Name | Description |
---|---|---|
DateTime? | first | First point in extending range |
DateTime? | last | Last point in extending range |
Returns
Type | Description |
---|---|
TimeRange | A new TimeRange extended by |
GetHashCode()
Returns the computed hash code for this time range using its (First, Last) tuple
Declaration
public override int GetHashCode()
Returns
Type | Description |
---|---|
int |
Overrides
| Edit this page View SourceToString()
Returns a string representation of the TimeRange, on the form ([First as ISO-string], [Last as ISO-string]).
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
string | A string representation of the TimeRange |
Overrides
Operators
| Edit this page View Sourceoperator ==(TimeRange, TimeRange)
Returns true if the provided time ranges are equal
Declaration
public static bool operator ==(TimeRange x, TimeRange y)
Parameters
Type | Name | Description |
---|---|---|
TimeRange | x | time range |
TimeRange | y | time range |
Returns
Type | Description |
---|---|
bool | true, if equal. false otherwise |
operator !=(TimeRange, TimeRange)
Returns true if the provided time ranges are different
Declaration
public static bool operator !=(TimeRange x, TimeRange y)
Parameters
Type | Name | Description |
---|---|---|
TimeRange | x | time range |
TimeRange | y | time range |
Returns
Type | Description |
---|---|
bool | true, if different. false otherwise |