Class CogniteTime
DateTime utility functions.
Inherited Members
Namespace: Cognite.Extractor.Common
Assembly: Cognite.Common.dll
Syntax
public static class CogniteTime
Properties
| Edit this page View SourceDateTimeEpoch
DateTime object representing the Unix Epoch, midnight 1/1/1970, in UTC.
Declaration
public static DateTime DateTimeEpoch { get; }
Property Value
Type | Description |
---|---|
DateTime |
Methods
| Edit this page View SourceFromTicks(long)
Creates an UTC DateTime object at ticksSinceEpoch
ticks after the Unix Epoch, midninght 1/1/1970.
Declaration
public static DateTime FromTicks(long ticksSinceEpoch)
Parameters
Type | Name | Description |
---|---|---|
long | ticksSinceEpoch | Number of ticks since Epoch |
Returns
Type | Description |
---|---|
DateTime | UTC DateTime object at |
FromUnixTimeMilliseconds(long)
Creates an UTC DateTime object at msSinceEpoch
milliseconds after the Unix Epoch, midnight 1/1/1970.
Declaration
public static DateTime FromUnixTimeMilliseconds(long msSinceEpoch)
Parameters
Type | Name | Description |
---|---|---|
long | msSinceEpoch | Number of milliseconds since Epoch |
Returns
Type | Description |
---|---|
DateTime | UTC DateTime object at |
Max(DateTime, DateTime)
Return the latest of the two given DateTimes
Declaration
public static DateTime Max(DateTime t1, DateTime t2)
Parameters
Type | Name | Description |
---|---|---|
DateTime | t1 | |
DateTime | t2 |
Returns
Type | Description |
---|---|
DateTime |
Max(TimeSpan, TimeSpan)
Return the longest of the two given TimeSpans. Handles the case of InfiniteTimeSpan, which is technically negative.
Declaration
public static TimeSpan Max(TimeSpan t1, TimeSpan t2)
Parameters
Type | Name | Description |
---|---|---|
TimeSpan | t1 | |
TimeSpan | t2 |
Returns
Type | Description |
---|---|
TimeSpan |
Min(DateTime, DateTime)
Return the earliest of the two given DateTimes.
Declaration
public static DateTime Min(DateTime t1, DateTime t2)
Parameters
Type | Name | Description |
---|---|---|
DateTime | t1 | |
DateTime | t2 |
Returns
Type | Description |
---|---|
DateTime |
Min(TimeSpan, TimeSpan)
Return the shortest of the two given TimeSpans. Handles the case of InfiniteTimeSpan, which is technically negative.
Declaration
public static TimeSpan Min(TimeSpan t1, TimeSpan t2)
Parameters
Type | Name | Description |
---|---|---|
TimeSpan | t1 | |
TimeSpan | t2 |
Returns
Type | Description |
---|---|
TimeSpan |
NanosecondsSinceEpoch(DateTime)
Returns the how many nanoseconds have passed since the Unix Epoch, 1/1/1970 to the date passed as parameter. A Nanosecond corresponds to 100 ticks.
Declaration
public static long NanosecondsSinceEpoch(this DateTime time)
Parameters
Type | Name | Description |
---|---|---|
DateTime | time | UTC DateTime object to convert |
Returns
Type | Description |
---|---|
long | Number of ticks since epoch |
ParseTimeSpanString(string?, string?)
Parse cognite timestamp into timespan.
Format is N[timeunit].
If timeunit is left out, then defaultUnit
can be specified
and if t is a whole number it can be converted using that.
Declaration
public static TimeSpan? ParseTimeSpanString(string? t, string? defaultUnit = null)
Parameters
Type | Name | Description |
---|---|---|
string | t | Raw input |
string | defaultUnit | Default unit to use if no unit is specified |
Returns
Type | Description |
---|---|
TimeSpan? | TimeSpan or null if input is invalid |
ParseTimestampString(string?, DateTime?)
Parse Cognite timestamp string.
The format is N[timeunit]-ago where timeunit is w,d,h,m,s. Example: '2d-ago'
returns a timestamp two days ago.
If the format is N[timeunit], without -ago, it is set to the future, or after relative
Without timeunit, it is converted to a datetime in milliseconds since epoch.
Declaration
public static DateTime? ParseTimestampString(string? t, DateTime? relative = null)
Parameters
Type | Name | Description |
---|---|---|
string | t | Timestamp string |
DateTime? | relative | Set time relative to this if -ago syntax is used |
Returns
Type | Description |
---|---|
DateTime? | DateTime or null if the input is invalid |
TicksSinceEpoch(DateTime)
Returns the how many ticks have passed since the Unix Epoch, 1/1/1970 to the date passed as parameter. A Tick corresponds to 10 000 ms (ref. TimeSpan.TicksPerMillisecond).
This method may return a negative number.
Declaration
public static long TicksSinceEpoch(this DateTime time)
Parameters
Type | Name | Description |
---|---|---|
DateTime | time | UTC DateTime object to convert |
Returns
Type | Description |
---|---|
long | Number of ticks since epoch |
ToISOString(DateTime)
Return ISO 8601 formatted string (yyyy-MM-dd HH:mm:ss.fff) with millisecond resolution.
Declaration
public static string ToISOString(this DateTime time)
Parameters
Type | Name | Description |
---|---|---|
DateTime | time |
Returns
Type | Description |
---|---|
string | ISO 8601 formatted string |
ToUnixTimeMilliseconds(DateTime)
Returns the how many milliseconds have passed since the Unix Epoch, 1/1/1970 to the date passed as parameter. NOTE: Using TimeSpan.ToMilliseconds may cause rounding problems when 'time' is DateTime.MaxValue: The resulting(time - DateTimeEpoch).ToMilliseconds is 253402300800000, which cannot be converted back to DateTime(ArgumentOutOfRangeException). This method returns 253402300799999 instead.
Declaration
public static long ToUnixTimeMilliseconds(this DateTime time)
Parameters
Type | Name | Description |
---|---|---|
DateTime | time | DateTime object to convert |
Returns
Type | Description |
---|---|
long | Number of milliseconds since epoch |