TReK C++
5.3.3
Telemetry/Command API
|
This class holds a time value represented as seconds from the system epoch. More...
#include <trek_time.h>
Public Member Functions | |
Constructors, Destructor, and Other Basic Methods | |
TrekTime () | |
Default constructor of the class. | |
TrekTime (TrekTime &input) | |
Copy constructor of the class. | |
virtual | ~TrekTime () |
Class destructor. More... | |
void | operator= (TrekTime &right_side) |
Provides the equal operator. | |
Methods for setting time | |
int32_t | SetTime () |
Sets the time to the current system time. More... | |
int32_t | SetTime (uint32_t sec, uint32_t sub=0) |
Sets the time relative the system epoch based on the input. More... | |
int32_t | SetTime (const char *input_ptr) |
Sets the time based on the input string. More... | |
int32_t | SetTime (double input) |
Sets the time relative the system epoch based on the input. More... | |
void | SetSubsecondsPerSecond (uint32_t input) |
Sets the number of subseconds per second. More... | |
Methods for getting time | |
void | GetTime (uint32_t &sec, uint32_t &sub) |
Gets the time relative the system epoch. More... | |
void | GetTime (double &input) |
Gets the time relative the system epoch. More... | |
int32_t | GetTime (char *time_str, uint32_t *size_of_output, bool fractional=false, bool file_friendly=false) |
Gets the time as a string. More... | |
int32_t | GetTime (uint16_t &year, uint16_t &day_of_year, uint8_t &month, uint8_t &day_of_month, uint8_t &hours, uint8_t &minutes, double &seconds) |
Gets the time as value components. More... | |
Miscellaneous methods | |
uint32_t | GetSeconds () |
Returns the current number of seconds since the epoch. | |
uint32_t | GetSubseconds () |
Returns the current number of subseconds. | |
uint32_t | GetSubsecondsPerSecond () |
Returns the number of subseconds per second. | |
double | GetDeltaTime (TrekTime &input) |
Gets the difference between two times. More... | |
int32_t | ShiftTime (double input) |
Shifts the time. More... | |
This class holds a time value represented as seconds from the system epoch.
The time may also have an optional fractional second (subsecond) value. The number of subseconds allowed is enforced by the maximum subseconds per second value. The default number of subseconds per second is 1,000,000 (microseconds).
|
virtual |
Class destructor.
Removes all resources created with this instance of the class.
double trek::TrekTime::GetDeltaTime | ( | TrekTime & | input | ) |
Gets the difference between two times.
Calculates a double precision floating point number representing the difference between the input time and the time stored in this class. If the input time is later, the value will be positive. The times are not required to have the same subsecond resolution.
[in] | input | The second time value. |
Example:
int32_t trek::TrekTime::GetTime | ( | char * | time_str, |
uint32_t * | size_of_output, | ||
bool | fractional = false , |
||
bool | file_friendly = false |
||
) |
Gets the time as a string.
Gets the time as a string in the format:
YYYY-MM-SS hh:mm:ss(.fff)
[out] | time_str | The time as seconds since epoch. |
[in,out] | size_of_output | The number of bytes allocated for the buffer on input. If return code is set to TREK_DATA_NOT_ENOUGH_SPACE, then the value is reset to the number of bytes required for the data to be copied. |
[in] | fractional | Include subseconds in returned string |
[in] | file_friendly | Uses '-' instead of ':' and ' ' for formatting |
Example:
void trek::TrekTime::GetTime | ( | double & | input | ) |
int32_t trek::TrekTime::GetTime | ( | uint16_t & | year, |
uint16_t & | day_of_year, | ||
uint8_t & | month, | ||
uint8_t & | day_of_month, | ||
uint8_t & | hours, | ||
uint8_t & | minutes, | ||
double & | seconds | ||
) |
Gets the time as value components.
[out] | year | Actual year number (e.g., 1999). |
[out] | day_of_year | Day of year (Jan 1 is day 1). |
[out] | month | Month of year (Jan is month 1). |
[out] | day_of_month | Day of month (1-31). |
[out] | hours | Hours of day (0-23). |
[out] | minutes | Minutes of hour (0-59). |
[out] | seconds | Seconds of minute (0-59.999999...). |
Example:
void trek::TrekTime::GetTime | ( | uint32_t & | sec, |
uint32_t & | sub | ||
) |
void trek::TrekTime::SetSubsecondsPerSecond | ( | uint32_t | input | ) |
Sets the number of subseconds per second.
Also resets the current subseconds to zero.
[in] | input | The new number of subseconds per second. |
Example:
int32_t trek::TrekTime::SetTime | ( | ) |
Sets the time to the current system time.
If the subseconds per second are allowed (see SetSubsecondsPerSecond), fractional seconds will be set as well.
Example:
int32_t trek::TrekTime::SetTime | ( | const char * | input_ptr | ) |
Sets the time based on the input string.
The format of the string is:
YYYY-MM-DD hh:mm:ss(.fffff) Where YYYY is the year and between 1970 and 2099 inclusive. MM is the month between 01 and 12 inclusive DD is the day between 01 and 31 inclusive hh is the hours between 00 and 23 inclusive mm is the minutes between 00 and 59 inclusive ss is the seconds between 00 and 59 inclusive (.fffff) is the optional fractional seconds without the parentheses.
[in] | input_ptr | The new time. |
Example:
int32_t trek::TrekTime::SetTime | ( | double | input | ) |
Sets the time relative the system epoch based on the input.
[in] | input | The new time. |
Example:
int32_t trek::TrekTime::SetTime | ( | uint32_t | sec, |
uint32_t | sub = 0 |
||
) |
Sets the time relative the system epoch based on the input.
[in] | sec | The new seconds since the epoch. |
[in] | sub | The new subseconds of seconds. |
Example:
int32_t trek::TrekTime::ShiftTime | ( | double | input | ) |
Shifts the time.
Adds the input time to the current value stored in class.
[in] | input | The number of seconds to shift time. Negative values shift to earlier time. |
Example: