Base module

Timestamp

A [Timestamp]({#ref classicy_1_1Timestamp #}) stores a monotonic* time value with (theoretical) microseconds resolution.

Timestamp

#include <icy/datetime.h>

A Timestamp stores a monotonic* time value with (theoretical) microseconds resolution. Timestamps can be compared with each other and simple arithmetics are supported.

[*] Note that Timestamp values are only monotonic as long as the systems's clock is monotonic as well (and not, e.g. set back).

Timestamps are UTC (Coordinated Universal Time) based and thus independent of the timezone in effect on the system.

Public Methods

ReturnNameDescription
TimestampCreates a timestamp with the current time.
TimestampCreates a timestamp from the given time value.
TimestampCopy constructor.
~TimestampDestroys the timestamp.
voidswapSwaps the Timestamp with another one.
voidupdateUpdates the Timestamp with the current time.
booloperator== const inline
booloperator!= const inline
booloperator> const inline
booloperator>= const inline
booloperator< const inline
booloperator<= const inline
Timestampoperator+ const inline
Timestampoperator- const inline
TimeDiffoperator- const inline
Timestamp &operator+= inline
Timestamp &operator-= inline
std::time_tepochTime const inlineReturns the timestamp expressed in time_t. time_t base time is midnight, January 1, 1970. Resolution is one second.
UtcTimeValutcTime const inlineReturns the timestamp expressed in UTC-based time. UTC base time is midnight, October 15, 1582. Resolution is 100 nanoseconds.
TimeValepochMicroseconds const inlineReturns the timestamp expressed in microseconds since the Unix epoch, midnight, January 1, 1970.
TimeDiffelapsed const inlineReturns the time elapsed since the time denoted by the timestamp. Equivalent to Timestamp() - *this.
boolisElapsed const inlineReturns true iff the given interval has passed since the time denoted by the timestamp.

Timestamp

Timestamp()

Creates a timestamp with the current time.


Timestamp

Timestamp(TimeVal tv)

Creates a timestamp from the given time value.


Timestamp

Timestamp(const Timestamp & other)

Copy constructor.


~Timestamp

~Timestamp()

Destroys the timestamp.


swap

void swap(Timestamp & timestamp)

Swaps the Timestamp with another one.


update

void update()

Updates the Timestamp with the current time.


operator==

const inline

inline bool operator==(const Timestamp & ts) const

operator!=

const inline

inline bool operator!=(const Timestamp & ts) const

operator>

const inline

inline bool operator>(const Timestamp & ts) const

operator>=

const inline

inline bool operator>=(const Timestamp & ts) const

operator<

const inline

inline bool operator<(const Timestamp & ts) const

operator<=

const inline

inline bool operator<=(const Timestamp & ts) const

operator+

const inline

inline Timestamp operator+(TimeDiff d) const

operator-

const inline

inline Timestamp operator-(TimeDiff d) const

operator-

const inline

inline TimeDiff operator-(const Timestamp & ts) const

operator+=

inline

inline Timestamp & operator+=(TimeDiff d)

operator-=

inline

inline Timestamp & operator-=(TimeDiff d)

epochTime

const inline

inline std::time_t epochTime() const

Returns the timestamp expressed in time_t. time_t base time is midnight, January 1, 1970. Resolution is one second.


utcTime

const inline

inline UtcTimeVal utcTime() const

Returns the timestamp expressed in UTC-based time. UTC base time is midnight, October 15, 1582. Resolution is 100 nanoseconds.


epochMicroseconds

const inline

inline TimeVal epochMicroseconds() const

Returns the timestamp expressed in microseconds since the Unix epoch, midnight, January 1, 1970.


elapsed

const inline

inline TimeDiff elapsed() const

Returns the time elapsed since the time denoted by the timestamp. Equivalent to Timestamp() - *this.


isElapsed

const inline

inline bool isElapsed(TimeDiff interval) const

Returns true iff the given interval has passed since the time denoted by the timestamp.

Public Static Methods

ReturnNameDescription
TimestampfromEpochTime staticCreates a timestamp from a std::time_t.
TimestampfromUtcTime staticCreates a timestamp from a UTC time value.
TimeValresolution static inlineReturns the resolution in units per second. Since the timestamp has microsecond resolution, the returned value is always 1000000.

fromEpochTime

static

static Timestamp fromEpochTime(std::time_t t)

Creates a timestamp from a std::time_t.


fromUtcTime

static

static Timestamp fromUtcTime(UtcTimeVal val)

Creates a timestamp from a UTC time value.


resolution

static inline

static inline TimeVal resolution()

Returns the resolution in units per second. Since the timestamp has microsecond resolution, the returned value is always 1000000.

Public Types

NameDescription
TimeValmonotonic UTC time value in microsecond resolution
UtcTimeValmonotonic UTC time value in 100 nanosecond resolution
TimeDiffdifference between two timestamps in microseconds

TimeVal

std::int64_t TimeVal()

monotonic UTC time value in microsecond resolution


UtcTimeVal

std::int64_t UtcTimeVal()

monotonic UTC time value in 100 nanosecond resolution


TimeDiff

std::int64_t TimeDiff()

difference between two timestamps in microseconds

Private Attributes

ReturnNameDescription
TimeVal_ts

_ts

TimeVal _ts