Show / Hide Table of Contents

Struct Timestamp

Represents timestamp.

Implements
IComparable<Timestamp>
IComparisonOperators<Timestamp, Timestamp, bool>
IEqualityOperators<Timestamp, Timestamp, bool>
IAdditionOperators<Timestamp, TimeSpan, Timestamp>
ISubtractionOperators<Timestamp, TimeSpan, Timestamp>
IInterlockedOperations<Timestamp>
IEquatable<Timestamp>
Inherited Members
ValueType.Equals(object)
ValueType.GetHashCode()
object.Equals(object, object)
object.GetType()
object.ReferenceEquals(object, object)
Namespace: DotNext.Diagnostics
Assembly: DotNext.dll
Syntax
public readonly record struct Timestamp : IComparable<Timestamp>, IComparisonOperators<Timestamp, Timestamp, bool>, IEqualityOperators<Timestamp, Timestamp, bool>, IAdditionOperators<Timestamp, TimeSpan, Timestamp>, ISubtractionOperators<Timestamp, TimeSpan, Timestamp>, IInterlockedOperations<Timestamp>, IEquatable<Timestamp>
Remarks

This class can be used as allocation-free alternative to Stopwatch.

Constructors

| Edit this page View Source

Timestamp()

Captures the current point in time.

Declaration
public Timestamp()
| Edit this page View Source

Timestamp(TimeProvider)

Captures the current point in time.

Declaration
public Timestamp(TimeProvider provider)
Parameters
Type Name Description
TimeProvider provider

The time provider.

| Edit this page View Source

Timestamp(TimeSpan)

Constructs timestamp from TimeSpan.

Declaration
public Timestamp(TimeSpan ts)
Parameters
Type Name Description
TimeSpan ts

The point in time.

Exceptions
Type Condition
ArgumentOutOfRangeException

ts is negative.

Properties

| Edit this page View Source

Elapsed

Gets precise difference between the current point in time and this timestamp.

Declaration
public TimeSpan Elapsed { get; }
Property Value
Type Description
TimeSpan
Remarks

This property is always greater than or equal to Zero.

| Edit this page View Source

ElapsedMilliseconds

Gets the total elapsed time measured by the current instance, in milliseconds.

Declaration
public double ElapsedMilliseconds { get; }
Property Value
Type Description
double
| Edit this page View Source

ElapsedTicks

Gets the total elapsed time measured by the current instance, in timer ticks.

Declaration
public long ElapsedTicks { get; }
Property Value
Type Description
long
| Edit this page View Source

IsEmpty

Gets a value indicating that the timestamp is zero.

Declaration
public bool IsEmpty { get; }
Property Value
Type Description
bool
| Edit this page View Source

IsFuture

Gets a value indicating that the current timestamp represents the future point in time.

Declaration
public bool IsFuture { get; }
Property Value
Type Description
bool
| Edit this page View Source

IsPast

Gets a value indicating that the current timestamp represents the past point in time.

Declaration
public bool IsPast { get; }
Property Value
Type Description
bool
| Edit this page View Source

Value

Gets TimeSpan representing this timestamp.

Declaration
public TimeSpan Value { get; }
Property Value
Type Description
TimeSpan
Remarks

This property may return a value with lost precision.

Methods

| Edit this page View Source

CompareExchange(ref Timestamp, Timestamp, Timestamp)

Compares two values for equality and, if they are equal, replaces the first value.

Declaration
public static Timestamp CompareExchange(ref Timestamp location, Timestamp value, Timestamp comparand)
Parameters
Type Name Description
Timestamp location

The destination, whose value is compared with comparand and possibly replaced.

Timestamp value

The value that replaces the destination value if the comparison results in equality.

Timestamp comparand

The value that is compared to the value at location.

Returns
Type Description
Timestamp

The original value in location.

| Edit this page View Source

CompareTo(Timestamp)

Compares this timestamp with the given value.

Declaration
public int CompareTo(Timestamp other)
Parameters
Type Name Description
Timestamp other

The timestamp to compare.

Returns
Type Description
int

The result of comparison.

| Edit this page View Source

ElapsedSince(Timestamp)

Gets a difference between two timestamps, in milliseconds.

Declaration
public double ElapsedSince(Timestamp past)
Parameters
Type Name Description
Timestamp past

The timestamp in the past.

Returns
Type Description
double

The number of milliseconds since past.

| Edit this page View Source

ElapsedSince(Timestamp, TimeProvider)

Gets a difference between two timestamps, in milliseconds.

Declaration
public double ElapsedSince(Timestamp past, TimeProvider provider)
Parameters
Type Name Description
Timestamp past

The timestamp in the past.

TimeProvider provider

Time provider.

Returns
Type Description
double

The number of milliseconds since past.

| Edit this page View Source

GetElapsedMilliseconds(TimeProvider)

Gets the total elapsed time measured by the current instance, in milliseconds.

Declaration
public double GetElapsedMilliseconds(TimeProvider provider)
Parameters
Type Name Description
TimeProvider provider

Time provider.

Returns
Type Description
double

The elapsed time, in ms, between the starting timestamp and the time of this call.

| Edit this page View Source

GetElapsedTicks(TimeProvider)

Gets the total elapsed time measured by the current instance, in timer ticks.

Declaration
public long GetElapsedTicks(TimeProvider provider)
Parameters
Type Name Description
TimeProvider provider

Time provider.

Returns
Type Description
long

The elapsed time, in ticks, between the starting timestamp and the time of this call.

| Edit this page View Source

GetElapsedTime(TimeProvider)

Gets precise difference between the current point in time and this timestamp.

Declaration
public TimeSpan GetElapsedTime(TimeProvider provider)
Parameters
Type Name Description
TimeProvider provider

Time provider.

Returns
Type Description
TimeSpan

The elapsed time between the starting timestamp and the time of this call.

| Edit this page View Source

Refresh(ref Timestamp)

Updates the timestamp to the current point in time and prevents the processor from reordering memory operations.

Declaration
public static void Refresh(ref Timestamp location)
Parameters
Type Name Description
Timestamp location

The location of the timestamp to update.

| Edit this page View Source

Refresh(ref Timestamp, TimeProvider)

Updates the timestamp to the current point in time and prevents the processor from reordering memory operations.

Declaration
public static void Refresh(ref Timestamp location, TimeProvider provider)
Parameters
Type Name Description
Timestamp location

The location of the timestamp to update.

TimeProvider provider

Time provider.

| Edit this page View Source

ToString()

Gets timestamp in the form of the string.

Declaration
public override string ToString()
Returns
Type Description
string

The string representing this timestamp.

Overrides
ValueType.ToString()
| Edit this page View Source

VolatileRead(ref readonly Timestamp)

Reads the timestamp and prevents the processor from reordering memory operations.

Declaration
public static Timestamp VolatileRead(ref readonly Timestamp location)
Parameters
Type Name Description
Timestamp location

The managed pointer to the timestamp.

Returns
Type Description
Timestamp

The value at the specified location.

| Edit this page View Source

VolatileWrite(ref Timestamp, Timestamp)

Writes the timestamp and prevents the processor from reordering memory operations.

Declaration
public static void VolatileWrite(ref Timestamp location, Timestamp newValue)
Parameters
Type Name Description
Timestamp location

The managed pointer to the timestamp.

Timestamp newValue

The value to write.

Operators

| Edit this page View Source

operator +(Timestamp, TimeSpan)

Adds the specified duration to the timestamp.

Declaration
public static Timestamp operator +(Timestamp x, TimeSpan y)
Parameters
Type Name Description
Timestamp x

The timestamp value.

TimeSpan y

The delta.

Returns
Type Description
Timestamp

The modified timestamp.

| Edit this page View Source

operator checked +(Timestamp, TimeSpan)

Adds the specified duration to the timestamp.

Declaration
public static Timestamp operator checked +(Timestamp x, TimeSpan y)
Parameters
Type Name Description
Timestamp x

The timestamp value.

TimeSpan y

The delta.

Returns
Type Description
Timestamp

The modified timestamp.

Exceptions
Type Condition
OverflowException

y is too large.

| Edit this page View Source

operator checked -(Timestamp, TimeSpan)

Subtracts the specified duration from the timestamp.

Declaration
public static Timestamp operator checked -(Timestamp x, TimeSpan y)
Parameters
Type Name Description
Timestamp x

The timestamp value.

TimeSpan y

The delta.

Returns
Type Description
Timestamp

The modified timestamp.

Exceptions
Type Condition
OverflowException

y is too large.

| Edit this page View Source

explicit operator TimeSpan(Timestamp)

Gets TimeSpan representing the given timestamp.

Declaration
public static explicit operator TimeSpan(Timestamp stamp)
Parameters
Type Name Description
Timestamp stamp

The timestamp to convert.

Returns
Type Description
TimeSpan
Remarks

This operation leads to loss of precision.

| Edit this page View Source

operator >(Timestamp, Timestamp)

Determines whether the first timestamp is greater than the second.

Declaration
public static bool operator >(Timestamp first, Timestamp second)
Parameters
Type Name Description
Timestamp first

The first timestamp to compare.

Timestamp second

The second timestamp to compare.

Returns
Type Description
bool

true if first is greater than second.

| Edit this page View Source

operator >=(Timestamp, Timestamp)

Determines whether the first timestamp is greater than or equal to the second.

Declaration
public static bool operator >=(Timestamp first, Timestamp second)
Parameters
Type Name Description
Timestamp first

The first timestamp to compare.

Timestamp second

The second timestamp to compare.

Returns
Type Description
bool

true if first is greater than or equal to second.

| Edit this page View Source

operator <(Timestamp, Timestamp)

Determines whether the first timestamp is less than the second.

Declaration
public static bool operator <(Timestamp first, Timestamp second)
Parameters
Type Name Description
Timestamp first

The first timestamp to compare.

Timestamp second

The second timestamp to compare.

Returns
Type Description
bool

true if first is less than second.

| Edit this page View Source

operator <=(Timestamp, Timestamp)

Determines whether the first timestamp is less than or equal to the second.

Declaration
public static bool operator <=(Timestamp first, Timestamp second)
Parameters
Type Name Description
Timestamp first

The first timestamp to compare.

Timestamp second

The second timestamp to compare.

Returns
Type Description
bool

true if first is less than or equal to second.

| Edit this page View Source

operator -(Timestamp, TimeSpan)

Subtracts the specified duration from the timestamp.

Declaration
public static Timestamp operator -(Timestamp x, TimeSpan y)
Parameters
Type Name Description
Timestamp x

The timestamp value.

TimeSpan y

The delta.

Returns
Type Description
Timestamp

The modified timestamp.

Exceptions
Type Condition
OverflowException

y is too large.

Implements

IComparable<T>
IComparisonOperators<TSelf, TOther, TResult>
IEqualityOperators<TSelf, TOther, TResult>
IAdditionOperators<TSelf, TOther, TResult>
ISubtractionOperators<TSelf, TOther, TResult>
IInterlockedOperations<T>
IEquatable<T>

Extension Methods

BasicExtensions.Disclosed<T>(T)
BasicExtensions.Enclosed<T>(T)
BasicExtensions.IsBetween<T, TLowerBound, TUpperBound>(T, TLowerBound, TUpperBound)
BasicExtensions.IsOneOf<T>(T, ReadOnlySpan<T>)
Collection.ToAsyncEnumerator<TEnumerator, T>(TEnumerator, CancellationToken)
Collection.ToClassicEnumerator<TEnumerator, T>(TEnumerator)
Enumerator.Skip<TEnumerator, T>(ref TEnumerator, int)
ExpressionBuilder.Const<T>(T)
  • Edit this page
  • View Source
☀
☾
In this article
Back to top
Supported by the .NET Foundation
☀
☾