Class epicsTime

Class Documentation

class epicsTime

C++ time stamp object.

Holds an EPICS time stamp, and provides conversion functions for both input and output from/to other types.

Note

Time conversions: The epicsTime implementation will properly convert between the various formats from the beginning of the EPICS epoch until at least 2038. Unless the underlying architecture support has defective POSIX, BSD/SRV5, or standard C time support the EPICS implementation should be valid until 2106.

epicsTimeStamp conversions

Convert to and from EPICS epicsTimeStamp format

inline operator const epicsTimeStamp&() const

Convert to epicsTimeStamp.

epicsTime(const epicsTimeStamp &replace)

Construct from epicsTimeStamp.

inline epicsTime &operator=(const epicsTimeStamp &replace)

Assign from epicsTimeStamp.

ANSI C time_t conversions

Convert to and from ANSI C time_t wrapper .

inline operator time_t_wrapper() const

Convert to ANSI C time_t.

inline epicsTime(const time_t_wrapper &replace)

Construct from ANSI C time_t.

inline epicsTime &operator=(const time_t_wrapper &replace)

Assign from ANSI C time_t.

ANSI C struct tm local-time conversions

Convert to and from ANSI Cs struct tm (with nano seconds), adjusted for the local time zone.

inline operator local_tm_nano_sec() const

Convert to struct tm in local time zone.

inline epicsTime(const local_tm_nano_sec &replace)

Construct from struct tm in local time zone.

inline epicsTime &operator=(const local_tm_nano_sec &replace)

Assign from struct tm in local time zone.

ANSI C struct tm UTC conversions

Convert to and from ANSI Cs struct tm (with nano seconds), adjusted for Greenwich Mean Time (UTC).

inline operator gm_tm_nano_sec() const

Convert to struct tm in UTC/GMT.

inline epicsTime(const gm_tm_nano_sec &replace)

Construct from struct tm in UTC/GMT.

inline epicsTime &operator=(const gm_tm_nano_sec &replace)

Assign from struct tm in UTC.

POSIX RT struct timespec conversions

Convert to and from the POSIX RealTime struct timespec format.

inline operator struct timespec() const

Convert to struct timespec

inline epicsTime(const struct timespec &replace)

Construct from struct timespec

inline epicsTime &operator=(const struct timespec &replace)

Assign from struct timespec

BSD’s struct timeval conversions

Convert to and from the BSD struct timeval format.

operator struct timeval() const

Convert to struct timeval

epicsTime(const struct timeval &replace)

Construct from struct timeval

epicsTime &operator=(const struct timeval &replace)

Assign from struct timeval

Arithmetic operators

Standard operators involving epicsTime objects and time differences which are always expressed as a double in seconds.

inline double operator-(const epicsTime &other) const

lhs minus rhs, in seconds

inline epicsTime operator+(double delta) const

lhs plus rhs seconds

inline epicsTime operator-(double delta) const

lhs minus rhs seconds

inline epicsTime operator+=(double delta)

add rhs seconds to lhs

inline epicsTime operator-=(double delta)

subtract rhs seconds from lhs

Comparison operators

Standard comparisons between epicsTime objects.

inline bool operator==(const epicsTime &other) const

lhs equals rhs

inline bool operator!=(const epicsTime &other) const

lhs not equal to rhs

inline bool operator<=(const epicsTime &other) const

rhs no later than lhs

inline bool operator<(const epicsTime &other) const

lhs was before rhs

inline bool operator>=(const epicsTime &other) const

rhs not before lhs

inline bool operator>(const epicsTime &other) const

lhs was after rhs

Public Types

typedef std::runtime_error unableToFetchCurrentTime

Exception: Time provider problem.

typedef std::logic_error formatProblemWithStructTM

Exception: Bad field(s) in struct tm

Public Functions

inline epicsTime()

The default constructor sets the time to the EPICS epoch.

inline size_t strftime(char *pBuff, size_t bufLength, const char *pFormat) const

Convert to string in user-specified format.

This method extends the standard C library routine strftime(). See your OS documentation for details about the standard routine. The epicsTime method adds support for printing the fractional portion of the time. It searches the format string for the sequence %0f where n is the desired precision, and uses this format to convert the fractional seconds with the requested precision. For example:

epicsTime time = epicsTime::getCurrent();
char buf[30];
time.strftime(buf, 30, "%Y-%m-%d %H:%M:%S.%06f");
printf("%s\n", buf);
This will print the current time in the format:
2001-01-26 20:50:29.813505

inline void show(unsigned interestLevel) const

Dump current state to standard out.

Public Static Functions

static inline epicsTime getEvent(const epicsTimeEvent &evt)

Get time of event system event.

Returns an epicsTime indicating when the associated event system event last occurred.

static epicsTime getCurrent()

Get current clock time.

Returns an epicsTime containing the current time. For example:

epicsTime now = epicsTime::getCurrent();

static inline epicsTime getMonotonic()

Get current monotonic time.

Returns an epicsTime containing the current monotonic time, an OS clock which never going backwards or jumping forwards. This time is has an undefined epoch, and is only useful for measuring time differences.