Struct DateOrTimestamp
- Namespace
- MassiveDotNet
- Assembly
- MassiveDotNet.dll
A point in time accepted by Massive endpoints that take "either a date with the format YYYY-MM-DD or a millisecond timestamp".
public readonly struct DateOrTimestamp : IEquatable<DateOrTimestamp>
- Implements
- Inherited Members
Remarks
Implicit conversions exist from LocalDate, Instant, long, and string, so callers can pass whichever form they already have without converting by hand.
Methods
Equals(DateOrTimestamp)
Indicates whether the current object is equal to another object of the same type.
public bool Equals(DateOrTimestamp other)
Parameters
otherDateOrTimestampAn 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 DateOrTimestamp FromDate(LocalDate value)
Parameters
valueLocalDateThe calendar date.
Returns
- DateOrTimestamp
The wrapped value.
FromInstant(Instant)
Creates a value from an instant, rendered as Unix milliseconds.
public static DateOrTimestamp FromInstant(Instant value)
Parameters
valueInstantThe instant.
Returns
- DateOrTimestamp
The wrapped value.
FromLiteral(string)
Creates a value from a literal already in a form the API accepts.
public static DateOrTimestamp FromLiteral(string value)
Parameters
valuestringThe literal value, such as
"2026-01-15".
Returns
- DateOrTimestamp
The wrapped value.
Exceptions
- ArgumentException
valueis null or whitespace.
FromUnixMilliseconds(long)
Creates a value from a Unix millisecond timestamp.
public static DateOrTimestamp FromUnixMilliseconds(long epochMilliseconds)
Parameters
epochMillisecondslongMilliseconds since the Unix epoch.
Returns
- DateOrTimestamp
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 millisecond timestamp.
Operators
operator ==(DateOrTimestamp, DateOrTimestamp)
Compares two values for equality.
public static bool operator ==(DateOrTimestamp left, DateOrTimestamp right)
Parameters
leftDateOrTimestampThe left value.
rightDateOrTimestampThe right value.
Returns
implicit operator DateOrTimestamp(Instant)
Converts an instant.
public static implicit operator DateOrTimestamp(Instant value)
Parameters
valueInstantThe instant.
Returns
implicit operator DateOrTimestamp(LocalDate)
Converts a calendar date.
public static implicit operator DateOrTimestamp(LocalDate value)
Parameters
valueLocalDateThe calendar date.
Returns
implicit operator DateOrTimestamp(long)
Converts a Unix millisecond timestamp.
public static implicit operator DateOrTimestamp(long value)
Parameters
valuelongMilliseconds since the Unix epoch.
Returns
implicit operator DateOrTimestamp(string)
Converts a literal value.
public static implicit operator DateOrTimestamp(string value)
Parameters
valuestringThe literal value.
Returns
operator !=(DateOrTimestamp, DateOrTimestamp)
Compares two values for inequality.
public static bool operator !=(DateOrTimestamp left, DateOrTimestamp right)
Parameters
leftDateOrTimestampThe left value.
rightDateOrTimestampThe right value.