Struct DateOrNanoseconds
- Namespace
- MassiveDotNet
- Assembly
- MassiveDotNet.dll
A point in time accepted by the tick-level Massive endpoints that take "either a date with the format YYYY-MM-DD or a nanosecond timestamp".
public readonly struct DateOrNanoseconds : IEquatable<DateOrNanoseconds>
- Implements
- Inherited Members
Remarks
This is DateOrTimestamp with the unit changed. The two are separate types with the unit in the name because an Instant converts implicitly to either, and a millisecond render on a nanosecond endpoint would compile and ask for a moment in 1970 (decision D20). The map chooses the type each endpoint documents.
Implicit conversions exist from LocalDate, Instant, long, and string, so callers can pass whichever form they already have without converting by hand.
Methods
Equals(DateOrNanoseconds)
Indicates whether the current object is equal to another object of the same type.
public bool Equals(DateOrNanoseconds other)
Parameters
otherDateOrNanosecondsAn object to compare with this object.
Returns
Equals(object?)
Indicates whether this instance and a specified object are equal.
public override bool Equals(object? obj)
Parameters
objobjectThe object to compare with the current instance.
Returns
- bool
true if
objand this instance are the same type and represent the same value; otherwise, false.
FromDate(LocalDate)
Creates a value from a calendar date, rendered as YYYY-MM-DD.
public static DateOrNanoseconds FromDate(LocalDate value)
Parameters
valueLocalDateThe calendar date.
Returns
- DateOrNanoseconds
The wrapped value.
FromInstant(Instant)
Creates a value from an instant, rendered as Unix nanoseconds.
public static DateOrNanoseconds FromInstant(Instant value)
Parameters
valueInstantThe instant.
Returns
- DateOrNanoseconds
The wrapped value.
FromLiteral(string)
Creates a value from a literal already in a form the API accepts.
public static DateOrNanoseconds FromLiteral(string value)
Parameters
valuestringThe literal value, such as
"2026-01-15".
Returns
- DateOrNanoseconds
The wrapped value.
Exceptions
- ArgumentException
valueis null or whitespace.
FromUnixNanoseconds(long)
Creates a value from a Unix nanosecond timestamp.
public static DateOrNanoseconds FromUnixNanoseconds(long epochNanoseconds)
Parameters
epochNanosecondslongNanoseconds since the Unix epoch.
Returns
- DateOrNanoseconds
The wrapped value.
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.
ToString()
Renders the value in the form the API expects.
public override string ToString()
Returns
- string
Either a
YYYY-MM-DDdate or a Unix nanosecond timestamp.
Operators
operator ==(DateOrNanoseconds, DateOrNanoseconds)
Compares two values for equality.
public static bool operator ==(DateOrNanoseconds left, DateOrNanoseconds right)
Parameters
leftDateOrNanosecondsThe left value.
rightDateOrNanosecondsThe right value.
Returns
implicit operator DateOrNanoseconds(Instant)
Converts an instant.
public static implicit operator DateOrNanoseconds(Instant value)
Parameters
valueInstantThe instant.
Returns
implicit operator DateOrNanoseconds(LocalDate)
Converts a calendar date.
public static implicit operator DateOrNanoseconds(LocalDate value)
Parameters
valueLocalDateThe calendar date.
Returns
implicit operator DateOrNanoseconds(long)
Converts a Unix nanosecond timestamp.
public static implicit operator DateOrNanoseconds(long value)
Parameters
valuelongNanoseconds since the Unix epoch.
Returns
implicit operator DateOrNanoseconds(string)
Converts a literal value.
public static implicit operator DateOrNanoseconds(string value)
Parameters
valuestringThe literal value.
Returns
operator !=(DateOrNanoseconds, DateOrNanoseconds)
Compares two values for inequality.
public static bool operator !=(DateOrNanoseconds left, DateOrNanoseconds right)
Parameters
leftDateOrNanosecondsThe left value.
rightDateOrNanosecondsThe right value.