Table of Contents

Struct Timestamp

Namespace
LfrlAnvil.Chrono
Assembly
LfrlAnvil.Chrono.dll

Represents a number of elapsed ticks since UnixEpoch.

public readonly struct Timestamp : IEquatable<Timestamp>, IComparable<Timestamp>, IComparable
Implements
Inherited Members

Constructors

Timestamp(DateTime)

Creates a new Timestamp instance.

public Timestamp(DateTime utcValue)

Parameters

utcValue DateTime

Source date time.

Timestamp(long)

Creates a new Timestamp instance.

public Timestamp(long unixEpochTicks)

Parameters

unixEpochTicks long

Number of ticks since UnixEpoch.

Fields

Zero

Represents the UnixEpoch.

public static readonly Timestamp Zero

Field Value

Timestamp

Properties

UnixEpochTicks

Number of ticks elapsed since UnixEpoch.

public long UnixEpochTicks { get; }

Property Value

long

UtcValue

Gets the DateTime instance with Utc kind equivalent to this Timestamp.

public DateTime UtcValue { get; }

Property Value

DateTime

Methods

Add(Duration)

Creates a new Timestamp instance by adding value to this instance.

[Pure]
public Timestamp Add(Duration value)

Parameters

value Duration

Duration to add.

Returns

Timestamp

New Timestamp instance.

CompareTo(Timestamp)

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.

[Pure]
public int CompareTo(Timestamp other)

Parameters

other Timestamp

An object to compare with this instance.

Returns

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?)

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.

[Pure]
public int CompareTo(object? obj)

Parameters

obj object

An object to compare with this instance.

Returns

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

ArgumentException

obj is not the same type as this instance.

Equals(Timestamp)

Indicates whether the current object is equal to another object of the same type.

[Pure]
public bool Equals(Timestamp other)

Parameters

other Timestamp

An object to compare with this object.

Returns

bool

true if the current object is equal to the other parameter; otherwise, false.

Equals(object?)

Indicates whether this instance and a specified object are equal.

[Pure]
public override bool Equals(object? obj)

Parameters

obj object

The object to compare with the current instance.

Returns

bool

true if obj and this instance are the same type and represent the same value; otherwise, false.

GetHashCode()

Returns the hash code for this instance.

[Pure]
public override int GetHashCode()

Returns

int

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

Subtract(Duration)

Creates a new Timestamp instance by subtracting value from this instance.

[Pure]
public Timestamp Subtract(Duration value)

Parameters

value Duration

Duration to subtract.

Returns

Timestamp

New Timestamp instance.

Subtract(Timestamp)

Calculates a difference between this instance and the other instance, where this instance is treated as the end of the range.

[Pure]
public Duration Subtract(Timestamp other)

Parameters

other Timestamp

Instance to subtract.

Returns

Duration

New Duration instance.

ToString()

Returns a string representation of this Timestamp instance.

[Pure]
public override string ToString()

Returns

string

String representation.

Operators

operator +(Timestamp, Duration)

Creates a new Timestamp instance by adding a and b together.

[Pure]
public static Timestamp operator +(Timestamp a, Duration b)

Parameters

a Timestamp

First operand.

b Duration

Second operand.

Returns

Timestamp

New Timestamp instance.

operator ==(Timestamp, Timestamp)

Checks if a is equal to b.

[Pure]
public static bool operator ==(Timestamp a, Timestamp b)

Parameters

a Timestamp

First operand.

b Timestamp

Second operand.

Returns

bool

true when operands are equal, otherwise false.

explicit operator DateTime(Timestamp)

Converts the provided duration to DateTime.

[Pure]
public static explicit operator DateTime(Timestamp source)

Parameters

source Timestamp

Value to convert.

Returns

DateTime

UtcValue.

operator >(Timestamp, Timestamp)

Checks if a is greater than b.

[Pure]
public static bool operator >(Timestamp a, Timestamp b)

Parameters

a Timestamp

First operand.

b Timestamp

Second operand.

Returns

bool

true when a is greater than b, otherwise false.

operator >=(Timestamp, Timestamp)

Checks if a is greater than or equal to b.

[Pure]
public static bool operator >=(Timestamp a, Timestamp b)

Parameters

a Timestamp

First operand.

b Timestamp

Second operand.

Returns

bool

true when a is greater than or equal to b, otherwise false.

operator !=(Timestamp, Timestamp)

Checks if a is not equal to b.

[Pure]
public static bool operator !=(Timestamp a, Timestamp b)

Parameters

a Timestamp

First operand.

b Timestamp

Second operand.

Returns

bool

true when operands are not equal, otherwise false.

operator <(Timestamp, Timestamp)

Checks if a is less than b.

[Pure]
public static bool operator <(Timestamp a, Timestamp b)

Parameters

a Timestamp

First operand.

b Timestamp

Second operand.

Returns

bool

true when a is less than b, otherwise false.

operator <=(Timestamp, Timestamp)

Checks if a is less than or equal to b.

[Pure]
public static bool operator <=(Timestamp a, Timestamp b)

Parameters

a Timestamp

First operand.

b Timestamp

Second operand.

Returns

bool

true when a is less than or equal to b, otherwise false.

operator -(Timestamp, Duration)

Creates a new Timestamp instance by subtracting b from a.

[Pure]
public static Timestamp operator -(Timestamp a, Duration b)

Parameters

a Timestamp

First operand.

b Duration

Second operand.

Returns

Timestamp

New Timestamp instance.

operator -(Timestamp, Timestamp)

Creates a new Duration instance by subtracting b from a.

[Pure]
public static Duration operator -(Timestamp a, Timestamp b)

Parameters

a Timestamp

First operand.

b Timestamp

Second operand.

Returns

Duration

New Duration instance.