Firestore API - Struct Timestamp (3.5.1)

public struct Timestamp : IEquatable<Timestamp>, IComparable, IComparable<Timestamp>

Reference documentation and code samples for the Firestore API struct Timestamp.

A nanosecond-precision immutable timestamp. When this is stored as part of a document in Firestore, it is truncated to the microsecond, towards the start of time.

Namespace

Google.Cloud.Firestore

Assembly

Google.Cloud.Firestore.dll

Methods

CompareTo(Timestamp)

public int CompareTo(Timestamp other)

Compares the current instance with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other object.

Parameter
NameDescription
otherTimestamp

An object to compare with this instance.

Returns
TypeDescription
int

A value that indicates the relative order of the objects being compared. The return value has these meanings:
Value

Meaning

Less than zero

This instance precedes other in the sort order.

Zero

This instance occurs in the same position in the sort order as other.

Greater than zero

This instance follows other in the sort order.

CompareTo(object)

public int CompareTo(object obj)

Compares the current instance with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other object.

Parameter
NameDescription
objobject

An object to compare with this instance.

Returns
TypeDescription
int

A value that indicates the relative order of the objects being compared. The return value has these meanings:
Value

Meaning

Less than zero

This instance precedes obj in the sort order.

Zero

This instance occurs in the same position in the sort order as obj.

Greater than zero

This instance follows obj in the sort order.

Exceptions
TypeDescription
ArgumentException

obj is not the same type as this instance.

FromDateTime(DateTime)

public static Timestamp FromDateTime(DateTime dateTime)

Converts a DateTime to a Timestamp.

Parameter
NameDescription
dateTimeDateTime

The value to convert; its kind must be Utc.

Returns
TypeDescription
Timestamp

A Timestamp representation of dateTime.

FromDateTimeOffset(DateTimeOffset)

public static Timestamp FromDateTimeOffset(DateTimeOffset dateTimeOffset)

Converts the given DateTimeOffset to a Timestamp

Parameter
NameDescription
dateTimeOffsetDateTimeOffset

The date and time (with UTC offset) to convert to a timestamp.

Returns
TypeDescription
Timestamp

The converted timestamp.

Remarks

The offset is taken into consideration when converting the value (so the same instant in time is represented) but is not a separate part of the resulting value. In other words, there is no roundtrip operation to retrieve the original DateTimeOffset.

FromProto(Timestamp)

public static Timestamp FromProto(Timestamp proto)

Creates an instance from a Protobuf Timestamp representation. Later modifications to the Protobuf representation will not affect the returned oject.

Parameter
NameDescription
protoTimestamp

A Protobuf timestamp representation. Must not be null.

Returns
TypeDescription
Timestamp

An immutable timestamp.

GetCurrentTimestamp()

public static Timestamp GetCurrentTimestamp()

Returns the current timestamp according to the system clock. The system time zone is irrelevant, as a timestamp represents an instant in time.

Returns
TypeDescription
Timestamp

The current timestamp according to the system clock.

GetHashCode()

public override int GetHashCode()

Returns the hash code for this instance.

Returns
TypeDescription
int

A 32-bit signed integer that is the hash code for this instance.

Overrides

ToDateTime()

public DateTime ToDateTime()

Converts this timestamp to a DateTime with a kind of Utc. This can lose information as DateTime has a precision of a tick (100 nanoseconds). If the timestamp is not a precise number of ticks, it will be truncated towards the start of time.

Returns
TypeDescription
DateTime

A DateTime representation of this timestamp.

ToDateTimeOffset()

public DateTimeOffset ToDateTimeOffset()

Converts this timestamp into a DateTimeOffset.

Returns
TypeDescription
DateTimeOffset

This timestamp as a DateTimeOffset.

Remarks

The resulting DateTimeOffset will always have an Offset of zero. If the timestamp is not a precise number of ticks, it will be truncated towards the start of time. DateTimeOffset value precisely on a second.

ToProto()

public Timestamp ToProto()

Creates a Protobuf Timestamp representation of this timestamp. Modifications to the returned message will not be reflected in this object.

Returns
TypeDescription
Timestamp

A Protobuf timestamp representation.

ToString()

public override string ToString()

Returns the fully qualified type name of this instance.

Returns
TypeDescription
string

The fully qualified type name.

Overrides

Operators

operator ==(Timestamp, Timestamp)

public static bool operator ==(Timestamp lhs, Timestamp rhs)

Operator overload to compare two Blob values for equality.

Parameters
NameDescription
lhsTimestamp

Left value to compare

rhsTimestamp

Right value to compare

Returns
TypeDescription
bool

true if lhs is equal to rhs; otherwise false.

operator >(Timestamp, Timestamp)

public static bool operator >(Timestamp lhs, Timestamp rhs)

Compares two timestamps.

Parameters
NameDescription
lhsTimestamp

The left timestamp to compare.

rhsTimestamp

The right timestamp to compare.

Returns
TypeDescription
bool

true is lhs is strictly later than rhs; otherwise false.

operator >=(Timestamp, Timestamp)

public static bool operator >=(Timestamp lhs, Timestamp rhs)

Compares two timestamps.

Parameters
NameDescription
lhsTimestamp

The left timestamp to compare.

rhsTimestamp

The right timestamp to compare.

Returns
TypeDescription
bool

true is lhs is later than or equal to rhs; otherwise false.

operator !=(Timestamp, Timestamp)

public static bool operator !=(Timestamp lhs, Timestamp rhs)

Operator overload to compare two Blob values for inequality.

Parameters
NameDescription
lhsTimestamp

Left value to compare

rhsTimestamp

Right value to compare

Returns
TypeDescription
bool

false if lhs is equal to rhs; otherwise true.

operator <(Timestamp, Timestamp)

public static bool operator <(Timestamp lhs, Timestamp rhs)

Compares two timestamps.

Parameters
NameDescription
lhsTimestamp

The left timestamp to compare.

rhsTimestamp

The right timestamp to compare.

Returns
TypeDescription
bool

true is lhs is strictly earlier than rhs; otherwise false.

operator <=(Timestamp, Timestamp)

public static bool operator <=(Timestamp lhs, Timestamp rhs)

Compares two timestamps.

Parameters
NameDescription
lhsTimestamp

The left timestamp to compare.

rhsTimestamp

The right timestamp to compare.

Returns
TypeDescription
bool

true is lhs is earlier than or equal to rhs; otherwise false.