epochTime class

A class for dealing with different definitions of the start of the epoch.

The functions for converting between GSP and Unix epoch - taking leap seconds into account - were converted from the php functions available at https://www.andrews.edu/~tzs/timeconv/timealgorithm.html. From that site:

[W]hile there was an offset of 315964800 seconds between Unix and GPS time when GPS time began, that offset changes each time there is a leap second. GPS time labels each second uniquely including leap seconds while Unix time does not, preferring to count a constant number of seconds a day including those containing leap seconds.

Public static functions

static time_t convert_epoch(time_t in_timestamp, epochStart in_epoch, epochStart out_epoch) -> time_t
Static function to convert between any two timestamps.
static time_t convert_epoch(epochTime in_time, epochStart out_epoch) -> time_t
Get the timestamp of an epochTime object in a different epoch.
static time_t unix2gps(time_t unixTime) -> time_t
Convert Unix Time to GPS Time.
static time_t gps2unix(time_t gpsTime) -> time_t
Convert GPS Time to Unix Time.

Constructors, destructors, conversion operators

epochTime(time_t timestamp, epochStart epoch = epochStart::unix_epoch)
Constructor, requires thse unix offset value as input.
operator bool() const deleted explicit
Deleted bool conversion operator.

Public functions

bool operator==(epochTime a) const -> bool
Equality comparison operator.
bool operator!=(epochTime a) const -> bool
In-equality comparison operator.

Function documentation

static time_t epochTime::convert_epoch(time_t in_timestamp, epochStart in_epoch, epochStart out_epoch)

Static function to convert between any two timestamps.

Parameters
in_timestamp The timestamp to convert - in seconds since the start of the input epoch.
in_epoch The starting epoch
out_epoch The ending epoch
Returns time_t The equivalent timestamp relative to the requested epoch

static time_t epochTime::convert_epoch(epochTime in_time, epochStart out_epoch)

Get the timestamp of an epochTime object in a different epoch.

Parameters
in_time The input epochTime object
out_epoch The ending epoch
Returns time_t The equivalent timestamp relative to the requested epoch

static time_t epochTime::unix2gps(time_t unixTime)

Convert Unix Time to GPS Time.

Parameters
unixTime A unix epoch timestamp
Returns time_t The equivalent GPS epoch timestamp

static time_t epochTime::gps2unix(time_t gpsTime)

Convert GPS Time to Unix Time.

Parameters
gpsTime A GPS epoch timestamp
Returns time_t The equivalent Unix epoch timestamp

epochTime::epochTime(time_t timestamp, epochStart epoch = epochStart::unix_epoch)

Constructor, requires thse unix offset value as input.

Parameters
timestamp A timestamp - in seconds since the start of the given epoch.
epoch The start if the epoch for the timestamp.

epochTime::operator bool() const explicit deleted

Deleted bool conversion operator.

The bool conversion operator allows an object of this class to be converted into a boolean. Deleting this prevents anyone from calling if(epochStart)


bool epochTime::operator==(epochTime a) const

Equality comparison operator.

Parameters
a Another epochStart object
Returns bool True if the objects have the same epoch start

bool epochTime::operator!=(epochTime a) const

In-equality comparison operator.

Parameters
a Another epochStart object
Returns bool True if the objects have the a different epoch start