ALox  V. 2402 R. 0
Home ALox for C++ ALox for C# ALox for Java Download
Public Static Fields | Public Methods | Private Static Fields | Protected Fields | List of all members
Ticks Class Reference
Inheritance diagram for Ticks:
[legend]
Collaboration diagram for Ticks:
[legend]

Class Description


This class provides an interface into system dependent timer values (usually 64 bit tick counters) that we call ticks. Ticks and this class allow to store and calculate time values in an efficient and highly accurate way.

Ticks generated by this class can be added and subtracted:

Conversion functions to milliseconds, microseconds and nanoseconds accept ticks and span values in ticks in the same manner.

As Ticks are system dependent, they should not be stored in system independent data files or otherwise shared between systems. In general such values should only be used by methods of this class and class TickWatch.

The resolution and accuracy of the values is platform dependent. Especially nanoseconds are deemed to be not accurate and above 100 ns (this was written and fact in 2013).

Public Static Fields

static readonly Ticks CreationTime
 
static readonly long InternalFrequency
 

Public Methods

 Ticks ()
 
 Ticks (long ticks)
 
 Ticks (Ticks copy)
 
void Add (long value)
 
void Add (Ticks other)
 
Ticks Age ()
 
Ticks Age (Ticks result)
 
void FromDays (long days)
 
void FromHours (long hours)
 
void FromMicros (long micros)
 
void FromMillis (long millis)
 
void FromMinutes (long mins)
 
void FromNanos (long nanos)
 
void FromSeconds (long secs)
 
bool HasElapsed (Ticks waitTime)
 
long InDays ()
 
DateTime InDotNetDateTime ()
 
long InDotNetDateTimeTicks ()
 
long InEpochMillis ()
 
double InHertz (int qtyFractionalDigits=-1)
 
long InHours ()
 
long InMicros ()
 
long InMillis ()
 
long InMinutes ()
 
long InNanos ()
 
long InSeconds ()
 
long Raw ()
 
void Set ()
 
void Set (Ticks other)
 
void SetFromDotNetDateTime (DateTime dateTime)
 
void SetFromEpochMillis (long epochMillis)
 
void SetRaw (long value)
 
Ticks Since (Ticks olderTime)
 
Ticks Since (Ticks olderTime, Ticks result)
 
void Sub (long value)
 
void Sub (Ticks other)
 
string ToString (string formatString, System.IFormatProvider fProvider)
 

Private Static Fields

static readonly double convSWToDT
 A conversion factor between stopwatch ticks and DateTimeTicks. *‍/.
 
static readonly Stopwatch creationTimeStopWatch
 A stopwatch started when static constructor is invoked. *‍/.
 
static readonly long dateTimeTicks19700101
 The DateTime.Now.Ticks at 1/1/1970 0:00:00. *‍/.
 

Protected Fields

Ticks tempTicks
 A temporary ticks object. used for as a return value. *‍/.
 
long ticks
 The value. *‍/.
 

Constructor & Destructor Documentation

◆ Ticks() [1/3]

Ticks ( )
inline

Creates a Ticks instance representing the point in time when this constructor was invoked.

◆ Ticks() [2/3]

Ticks ( Ticks  copy)
inline

Creates a Ticks instance representing the same point in time or time span as the instance provided.

Parameters
copyThe instance to copy the ticks value from.

◆ Ticks() [3/3]

Ticks ( long  ticks)
inline

Creates a Ticks instance representing a given time point or time span in ticks.

Parameters
ticksThe value to copy into this.

Member Function Documentation

◆ Add() [1/2]

void Add ( long  value)
inline

Adds the point in time or time span represented by the given Ticks instance to this instance.

Parameters
valueThe ticks to add.

◆ Add() [2/2]

void Add ( Ticks  other)
inline

Adds the point in time or time span represented by the given Ticks instance to this instance.

Parameters
otherThe Ticks object to add the ticks from.

◆ Age() [1/2]

Ticks Age ( )
inline

Returns the time span between value represented by this instance and the current system time. If the internal value represents a historic point in time, the result is positive.

Note: Attention: The object returned is a temporary object, deemed to be reused by other interface methods of this instance. Therefore, it must be used only until subsequent method invocations on this instance are performed (hence, also not thread safe!) Use Age(Ticks result) to provide a dedicated external result instance.

Returns
The age of this instance, stored in a temporary object, not thread safe object.

◆ Age() [2/2]

Ticks Age ( Ticks  result)
inline

Returns the time span between value represented by this instance and the current time. If the internal value represents a historic point in time, the result is positive.

Parameters
resultThe Ticks object to store the result in. If null, this is created.
Returns
The age of this instance, stored in the given or created object.

◆ FromDays()

void FromDays ( long  days)
inline

Sets the internal value to a time span provided in days.

Parameters
daysThe time span to set in days.

◆ FromHours()

void FromHours ( long  hours)
inline

Sets the internal value to a time span provided in hours.

Parameters
hoursThe time span to set in hours.

◆ FromMicros()

void FromMicros ( long  micros)
inline

Sets the internal value to a time span provided in microseconds.

Parameters
microsThe time span to set in microseconds.

◆ FromMillis()

void FromMillis ( long  millis)
inline

Sets the internal value to a time span provided in milliseconds.

Parameters
millisThe time span to set in milliseconds.

◆ FromMinutes()

void FromMinutes ( long  mins)
inline

Sets the internal value to a time span provided in minutes.

Parameters
minsThe time span to set in minutes.

◆ FromNanos()

void FromNanos ( long  nanos)
inline

Sets the internal value to a time span provided in nanoseconds.

Parameters
nanosThe time span to set in nanoseconds.

◆ FromSeconds()

void FromSeconds ( long  secs)
inline

Sets the internal value to a time span provided in seconds.

Parameters
secsThe time span to set in seconds.

◆ HasElapsed()

bool HasElapsed ( Ticks  waitTime)
inline

Determines if this objects' age is higher than a given time span.

Parameters
waitTimeA Ticks object representing a time span.
Returns
true if the given Ticks object representing a time span is smaller or equal than our age. false otherwise.

◆ InDays()

long InDays ( )
inline

Converts the internal value to days.

Returns
The internal value converted to days.

◆ InDotNetDateTime()

DateTime InDotNetDateTime ( )
inline

Converts the internal value to DateTime. The conversion is dependent on time zone and system clock setting of the host.

Returns
A corresponding DateTime object.

◆ InDotNetDateTimeTicks()

long InDotNetDateTimeTicks ( )
inline

Converts the internal value to DateTime ticks. The conversion is dependent on time zone and system clock setting of the host.

Returns
The converted DateTime compatible ticks value.

◆ InEpochMillis()

long InEpochMillis ( )
inline

Converts the internal value into milliseconds since January 1, 1970, 00:00:00 GMT. The conversion is dependent on time zone and system clock setting of the host.

Returns
Milliseconds in the epoch.

◆ InHertz()

double InHertz ( int  qtyFractionalDigits = -1)
inline

Returns 1 divided by internal value in seconds, hence the number of Hertz that this Ticks object represents when interpreted as a time span.

Parameters
qtyFractionalDigitsNumber of digits that the return value will be rounded to. Defaults to -1 which means no rounding.
Returns
A double value representing the frequency in hertz.

◆ InHours()

long InHours ( )
inline

Converts the internal value to hours.

Returns
The internal value converted to hours.

◆ InMicros()

long InMicros ( )
inline

Converts the internal value to microseconds.

Returns
The internal value converted to microseconds.

◆ InMillis()

long InMillis ( )
inline

Converts the internal value to milliseconds.

Returns
The internal value converted to milliseconds.

◆ InMinutes()

long InMinutes ( )
inline

Converts the internal value to minutes.

Returns
The internal value converted to minutes.

◆ InNanos()

long InNanos ( )
inline

Converts the internal value to nanoseconds.

Returns
The internal value converted to nanoseconds.

◆ InSeconds()

long InSeconds ( )
inline

Converts the internal value to seconds.

Returns
The internal value converted to seconds.

◆ Raw()

long Raw ( )
inline

Gets the internally stored system dependent time in ticks.

Returns
The internal value

◆ Set() [1/2]

void Set ( )
inline

Sets the actual point in time as the value of this instance.

◆ Set() [2/2]

void Set ( Ticks  other)
inline

Sets the point in time or time span represented by this instance to the value represented by the given Ticks instance.

Parameters
otherThe Ticks object to retrieve the new ticks value from.

◆ SetFromDotNetDateTime()

void SetFromDotNetDateTime ( DateTime  dateTime)
inline

Sets the internal value by converting the given DateTime. The conversion is dependent on time zone and system clock setting of the host.

Parameters
dateTimeA DateTime instance to read and convert the ticks from.

◆ SetFromEpochMillis()

void SetFromEpochMillis ( long  epochMillis)
inline

Sets the internal value by converting the given milliseconds since January 1, 1970, 00:00:00 GMT. The conversion is dependent on time zone and system clock setting of the host.

Parameters
epochMillisThe milliseconds in the epoch to convert.

◆ SetRaw()

void SetRaw ( long  value)
inline

Sets this objects' value to the value specified in ticks.

Parameters
valueThe ticks value to set

◆ Since() [1/2]

Ticks Since ( Ticks  olderTime)
inline

Returns the time span between the value represented by this instance and the given TickWatch. If the given TickWatch represents an earlier point in time, the result is positive.

Note: Attention: The object returned is a temporary object, deemed to be reused by other interface methods of this instance. Therefore, it must be used only until subsequent method invocations on this instance are performed (hence, also not thread safe!) Use Since(Ticks result, Ticks result) to provide a dedicated external result instance.

Parameters
olderTimeThe value to compare this instance with
Returns
The calculated time span, stored in a temporary object, not thread safe object

◆ Since() [2/2]

Ticks Since ( Ticks  olderTime,
Ticks  result 
)
inline

Returns the time span between the value represented by this instance and the given TickWatch. If the given TickWatch represents an earlier point in time, the result is positive.

Parameters
olderTimeThe value to compare this instance with
resultThe Ticks object to store the result in. If null, this is created.
Returns
The calculated time span, stored in the given or created object.

◆ Sub() [1/2]

void Sub ( long  value)
inline

Subtracts the point in time or time span represented by the given Ticks instance from this instance.

Parameters
valueThe ticks to subtract.

◆ Sub() [2/2]

void Sub ( Ticks  other)
inline

Subtracts the point in time or time span represented by the given Ticks instance from this instance.

Parameters
otherThe Ticks object to subtract the ticks from.

◆ ToString()

string ToString ( string  formatString,
System.IFormatProvider  fProvider 
)
inline

Returns a String that represents this object formatted according to formatString. For this, an object of .Net type DateTime is created and its ToString method is invoked. Hence, the format string follows the syntax defined for class DateTime.

Parameters
formatStringThe format string
fProviderThe format provider
Returns
A String that represents this object.

Member Data Documentation

◆ CreationTime

readonly Ticks CreationTime
static

The time (in ticks) when the ticker library containing the ticker (ALIB) was initialized. This might be useful to measure the time since the process was started.

◆ InternalFrequency

readonly long InternalFrequency
static

The Frequency of the internal tick timer. The Frequency gives you an indication of the accuracy of the time (At least if the underlying system library is reasonably well working in this respect). And this is the reason why it is published with this field. This value does not necessarily correspond to the number of ticks per second that you get from this classes Raw method.


The documentation for this class was generated from the following file: