Evo C++ Library v0.5.1
Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | List of all members
SysTimestamp Struct Reference

#include <evo/impl/systime.h>

Inheritance diagram for SysTimestamp:
Inheritance graph
[legend]

Detailed Description

Holds a system timestamp for storing date/time and measuring elapsed time.

Public Member Functions

 SysTimestamp ()
 Constructor. More...
 
 SysTimestamp (const SysTimestamp &src)
 Copy constructor. More...
 
void add_msec (ulong new_msec)
 Add milliseconds to current time. More...
 
void add_nsec (ulongl new_nsec)
 Add nanoseconds to current time. More...
 
void clear ()
 Clear and reset as 0. More...
 
int compare (const SysTimestamp &oth) const
 Compare to another timestamp. More...
 
ulongl diff_msec (const SysTimestamp &start) const
 Use this as an end-time and get the difference from start time in milliseconds. More...
 
ulongl diff_nsec (const SysTimestamp &start) const
 Use this as an end-time and get the difference from start time in nanoseconds. More...
 
ulongl diff_usec (const SysTimestamp &start) const
 Use this as an end-time and get the difference from start time in microseconds. More...
 
SysTimestampoperator= (const SysTimestamp &src)
 Assignment operator. More...
 
void set (const SysNativeTimeStamp &src)
 Set from system native timestamp. More...
 
void set_cpu ()
 Set as current CPU (process) time for use by timers. More...
 
void set_wall_datetime ()
 Set as current real (wall clock) time for calendar date/time use. More...
 
void set_wall_timer ()
 Set as current real (wall clock) time for use by timers. More...
 

Static Public Member Functions

static void get_wall_datetime_fields_local (int &year, int &month, int &day, int &hour, int &minute, int &second, int &msecond)
 Get fields for current real (wall clock) time for calendar date/time use (Local Time). More...
 
static void get_wall_datetime_fields_local (int &year, int &month, int &day, int &hour, int &minute, int &second, int &msecond, int &tz_offset)
 Get fields for current real (wall clock) time for calendar date/time use (Local Time). More...
 
static void get_wall_datetime_fields_utc (int &year, int &month, int &day, int &hour, int &minute, int &second, int &msecond)
 Get fields for current real (wall clock) time for calendar date/time use (UTC). More...
 
static int tz_get_offset ()
 Get current time zone (local time) offset from UTC in minutes. More...
 
static void tz_init ()
 Initializater that optimizes timezone (local time) conversion in some cases. More...
 

Public Attributes

ulong nsec
 Number of nanoseconds from seconds. More...
 
ulongl sec
 Number of seconds since Jan 1, EPOCH_YEAR. More...
 

Static Public Attributes

static const int EPOCH_YEAR = 1970
 Epoch year used by system – 1970 for Linux/Unix/POSIX, 1601 for Windows. More...
 
static const ulong MSEC_PER_SEC = 1000
 Milliseconds per second. More...
 
static const ulong NSEC_PER_MSEC = 1000000UL
 Nanoseconds per millisecond. More...
 
static const ulong NSEC_PER_SEC = 1000000000UL
 Nanoseconds per second. More...
 
static const ulong NSEC_PER_USEC = 1000
 Nanoseconds per microsecond. More...
 
static const int SEC_PER_MIN = 60
 Seconds per minute. More...
 
static const ulong USEC_PER_SEC = 1000000UL
 Microseconds per second. More...
 

Constructor & Destructor Documentation

◆ SysTimestamp() [1/2]

SysTimestamp ( )
inline

Constructor.

◆ SysTimestamp() [2/2]

SysTimestamp ( const SysTimestamp src)
inline

Copy constructor.

Parameters
srcSource to copy

Member Function Documentation

◆ add_msec()

void add_msec ( ulong  new_msec)
inline

Add milliseconds to current time.

  • This normalizes the current time so the nsec field has less than 1 second
Parameters
new_msecMilliseconds to add

◆ add_nsec()

void add_nsec ( ulongl  new_nsec)
inline

Add nanoseconds to current time.

  • This normalizes the current time so the nsec field has less than 1 second
Parameters
new_nsecNanoseconds to add

◆ clear()

void clear ( )
inline

Clear and reset as 0.

◆ compare()

int compare ( const SysTimestamp oth) const
inline

Compare to another timestamp.

Parameters
othOther timestamp to compare to
Returns
Result (<0 if this is less, 0 if equal, >0 if this is greater)

◆ diff_msec()

ulongl diff_msec ( const SysTimestamp start) const
inline

Use this as an end-time and get the difference from start time in milliseconds.

Parameters
startStart time to use, must not be greater than this
Returns
Difference in milliseconds

◆ diff_nsec()

ulongl diff_nsec ( const SysTimestamp start) const
inline

Use this as an end-time and get the difference from start time in nanoseconds.

Parameters
startStart time to use, must not be greater than this
Returns
Difference in nanoseconds

◆ diff_usec()

ulongl diff_usec ( const SysTimestamp start) const
inline

Use this as an end-time and get the difference from start time in microseconds.

Parameters
startStart time to use, must not be greater than this
Returns
Difference in microseconds

◆ get_wall_datetime_fields_local() [1/2]

static void get_wall_datetime_fields_local ( int &  year,
int &  month,
int &  day,
int &  hour,
int &  minute,
int &  second,
int &  msecond 
)
inlinestatic

Get fields for current real (wall clock) time for calendar date/time use (Local Time).

  • This is equivalent of using get_wall_datetime() then converting the timestamp to date/time fields in local time
  • Time is in the current local timezone, but this does not get the local timezone offset
Parameters
yearSet to 4 digit year for date [out]
monthSet to month of year for date (1 - 12) [out]
daySet to day of moneth for date (1 - 31) [out]
hourSet to hour for time of day (0 - 23) [out]
minuteMinutes for time of day (0 - 59) [out]
secondSeconds for time of day (0 - 60) [out]
msecondMilliseconds for time of day (0 - 999) [out]

◆ get_wall_datetime_fields_local() [2/2]

static void get_wall_datetime_fields_local ( int &  year,
int &  month,
int &  day,
int &  hour,
int &  minute,
int &  second,
int &  msecond,
int &  tz_offset 
)
inlinestatic

Get fields for current real (wall clock) time for calendar date/time use (Local Time).

  • This is equivalent of using get_wall_datetime() then converting the timestamp to date/time fields in local time
  • Time is in the current local timezone
Parameters
yearSet to 4 digit year for date [out]
monthSet to month of year for date (1 - 12) [out]
daySet to day of moneth for date (1 - 31) [out]
hourSet to hour for time of day (0 - 23) [out]
minuteMinutes for time of day (0 - 59) [out]
secondSeconds for time of day (0 - 60) [out]
msecondMilliseconds for time of day (0 - 999) [out]
tz_offsetTime zone offset in minutes, see tz_get_offset() [out]

◆ get_wall_datetime_fields_utc()

static void get_wall_datetime_fields_utc ( int &  year,
int &  month,
int &  day,
int &  hour,
int &  minute,
int &  second,
int &  msecond 
)
inlinestatic

Get fields for current real (wall clock) time for calendar date/time use (UTC).

  • This is equivalent of using get_wall_datetime() then converting the timestamp to date/time fields
  • Timezone is always UTC here
Parameters
yearSet to 4 digit year for date [out]
monthSet to month of year for date (1 - 12) [out]
daySet to day of moneth for date (1 - 31) [out]
hourSet to hour for time of day (0 - 23) [out]
minuteMinutes for time of day (0 - 59) [out]
secondSeconds for time of day (0 - 60) [out]
msecondMilliseconds for time of day (0 - 999) [out]

◆ operator=()

SysTimestamp& operator= ( const SysTimestamp src)
inline

Assignment operator.

Parameters
srcSource to copy
Returns
This

◆ set()

void set ( const SysNativeTimeStamp src)
inline

Set from system native timestamp.

  • This converts from SysNativeTimeStamp, which has platform-specific fields
  • Timezone is always UTC here
Parameters
srcSource to convert from

◆ set_cpu()

void set_cpu ( )
inline

Set as current CPU (process) time for use by timers.

◆ set_wall_datetime()

void set_wall_datetime ( )
inline

Set as current real (wall clock) time for calendar date/time use.

  • This is intended for getting current calendar date/time, but is not accurate as a timer as it's subject to time adjustments (daylight savings, NTP, user modification)
  • This uses a faster but more coarse (millisecond) system clock, if possible
  • Timezone is always UTC here

◆ set_wall_timer()

void set_wall_timer ( )
inline

Set as current real (wall clock) time for use by timers.

  • This is intended for calculating time elapsed on the system and is accurate for that purpose, but is not accurate for getting current date/time
  • This uses a monotonic high-resolution (nanosecond) system clock, if possible

◆ tz_get_offset()

static int tz_get_offset ( )
inlinestatic

Get current time zone (local time) offset from UTC in minutes.

Returns
Time zone offset from UTC in minutes, 0 for UTC, negative for the Western Hemisphere (America), positive for the remaining time zones

◆ tz_init()

static void tz_init ( )
inlinestatic

Initializater that optimizes timezone (local time) conversion in some cases.

  • On some systems (Linux) this sets an env var (TZ) if not already set, which reduces system calls for local time conversion
  • Caution: Not thread safe – this should be called once at startup, before other threads are started

Member Data Documentation

◆ EPOCH_YEAR

const int EPOCH_YEAR = 1970
static

Epoch year used by system – 1970 for Linux/Unix/POSIX, 1601 for Windows.

◆ MSEC_PER_SEC

const ulong MSEC_PER_SEC = 1000
static

Milliseconds per second.

◆ nsec

ulong nsec

Number of nanoseconds from seconds.

◆ NSEC_PER_MSEC

const ulong NSEC_PER_MSEC = 1000000UL
static

Nanoseconds per millisecond.

◆ NSEC_PER_SEC

const ulong NSEC_PER_SEC = 1000000000UL
static

Nanoseconds per second.

◆ NSEC_PER_USEC

const ulong NSEC_PER_USEC = 1000
static

Nanoseconds per microsecond.

◆ sec

ulongl sec

Number of seconds since Jan 1, EPOCH_YEAR.

◆ SEC_PER_MIN

const int SEC_PER_MIN = 60
static

Seconds per minute.

◆ USEC_PER_SEC

const ulong USEC_PER_SEC = 1000000UL
static

Microseconds per second.


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