![]() |
Fixposition SDK 0.0.0-heads/main-0-gfaec355
Collection of c++ libraries and apps for use with Fixposition products
|
#include <time.hpp>
Public Member Functions | |
Set time | |
These do not throw and instead return true/false. | |
bool | SetSecNSec (const uint32_t sec, const uint32_t nsec) |
Set time from seconds and nanoseconds (atomic) | |
bool | SetNSec (const uint64_t nsec) |
Set time from nanoseconds (atomic) | |
bool | SetSec (const double sec) |
Set time from seconds (atomic) | |
bool | SetPosix (const time_t posix) |
Set time from POSIX time (POSIX) | |
bool | SetRosTime (const RosTime &rostime) |
Set time from ROS time (POSIX) | |
bool | SetWnoTow (const WnoTow &wnotow) |
Set time from GNSS (GPS, Galileo, BeiDou) time (atomic) | |
bool | SetGloTime (const GloTime &glotime) |
Set time from GLONASS time (UTC + 3h) | |
bool | SetUtcTime (const UtcTime &utctime) |
Set time from UTC time (UTC) | |
bool | SetTai (const time_t tai) |
Set time from TAI time (CLOCK_TAI) | |
bool | SetClockRealtime () |
Set time from system clock current (now) system time (CLOCK_REALTIME) | |
Get time | |
uint64_t | GetNSec () const |
Get time as nanoseconds (atomic) | |
double | GetSec (const int prec=9) const |
Get time as seconds (atomic) | |
time_t | GetPosix () const |
Get time as POSIX time (POSIX) | |
RosTime | GetRosTime () const |
Get time as ROS time (POSIX) | |
WnoTow | GetWnoTow (const WnoTow::Sys sys=WnoTow::Sys::GPS, const int prec=9) const |
Get time as GNSS (GPS, Galileo, BeiDou) time (atomic) | |
GloTime | GetGloTime (const int prec=9) const |
Get time as GLONASS time (UTC + 3h) | |
UtcTime | GetUtcTime (const int prec=9) const |
Get time as UTC time (UTC) | |
double | GetDayOfYear (const int prec=12) const |
Get day of year. | |
time_t | GetTai () const |
Get time as TAI time (CLOCK_TAI) | |
std::chrono::milliseconds | GetChronoMilli () const |
Get time as std::chrono::duration (milliseconds since epoch) (POSIX) | |
std::chrono::nanoseconds | GetChronoNano () const |
Get time as std::chrono::nanoseconds (nanoseconds since epoch) (POSIX) | |
Misc | |
bool | IsZero () const |
Check if time is zero (invalid) | |
Arithmetic methods | |
These do not throw and instead return true/false. | |
bool | AddDur (const Duration &dur) |
Add duration to time. | |
bool | AddSec (const double sec) |
Add seconds to time. | |
bool | AddNSec (const int64_t nsec) |
Add nanoseconds to time. | |
bool | SubDur (const Duration &dur) |
Substract duration from time. | |
bool | SubNSec (const int64_t nsec) |
Substract nanoseconds from time. | |
bool | SubSec (const double sec) |
Substract seconds from time. | |
bool | Diff (const Time &other, Duration &diff) const |
Calculate difference between times. | |
Arithmetic operators | |
| |
Time | operator+ (const Duration &rhs) const |
Sum time and duration. | |
Time | operator+ (const int64_t nsec) const |
Sum time and nanoseconds. | |
Time | operator+ (const double sec) const |
Sum time and seconds. | |
Time & | operator+= (const Duration &rhs) |
Add duration to time. | |
Time & | operator+= (const int64_t nsec) |
Add nanoseconds to time. | |
Time & | operator+= (const double sec) |
Add seconds to time. | |
Time | operator- (const Duration &rhs) const |
Subtract time and duration. | |
Time | operator- (const int64_t nsec) const |
Subtract time and nanoseconds. | |
Time | operator- (const double sec) const |
Subtract time and seconds. | |
Time & | operator-= (const Duration &rhs) |
Subtract duration from time. | |
Time & | operator-= (const int64_t nsec) |
Subtract nanoseconds from time. | |
Time & | operator-= (const double sec) |
Subtract seconds from time. | |
Duration | operator- (const Time &rhs) const |
Subtract time and time. | |
Logic operators | |
bool | operator== (const Time &rhs) const |
Equal. | |
bool | operator!= (const Time &rhs) const |
Not equal. | |
bool | operator> (const Time &rhs) const |
Greater than. | |
bool | operator< (const Time &rhs) const |
Smaller than. | |
bool | operator>= (const Time &rhs) const |
Greater or equal than. | |
bool | operator<= (const Time &rhs) const |
Smaller or equal than. | |
Stringification | |
See also fpsdk::common::string::Strftime(). | |
std::string | StrWnoTow (const WnoTow::Sys sys=WnoTow::Sys::GPS, const int prec=3) const |
Stringify as GNSS time (atomic) | |
std::string | StrUtcTime (const int prec=3) const |
Stringify as year, month, day, hour, minute and second time (UTC) | |
std::string | StrIsoTime (const int prec=0) const |
Stringify as ISO 8601 time (UTC) | |
Leapseconds | |
bool | SetCurrentLeapseconds (const int value) const |
Set or change current leapseconds. | |
Public Attributes | |
uint32_t | sec_ |
Seconds part of time (atomic seconds since 1970-01-01 00:00:00 UTC) | |
uint32_t | nsec_ |
Nanoseconds part of time (should be in range 0-999999999) | |
Static Public Attributes | |
static const Time | MIN |
Minimum representable time. | |
static const Time | MAX |
Maximum representable time. | |
static const Time | ZERO |
Zero (invalid, uninitialised) time. | |
Make Time object | |
| |
Time () | |
Constructor, empty (invalid) time. | |
static Time | FromSecNSec (const uint32_t sec, const uint32_t nsec) |
Time from seconds and nanoseconds (atomic) | |
static Time | FromNSec (const uint64_t nsec) |
Time from nanoseconds (atomic) | |
static Time | FromSec (const double sec) |
From seconds (atomic) | |
static Time | FromPosix (const std::time_t posix) |
From POSIX time (POSIX) | |
static Time | FromRosTime (const RosTime &rostime) |
From ROS time (POSIX) | |
static Time | FromWnoTow (const WnoTow &wnotow) |
From GNSS time (atomic) | |
static Time | FromGloTime (const GloTime &glotime) |
From GLONASS time (UTC + 3h) | |
static Time | FromUtcTime (const UtcTime &utctime) |
From UTC time (UTC) | |
static Time | FromTai (const time_t tai) |
From TAI time (CLOCK_TAI) | |
static Time | FromClockRealtime () |
From system clock current (now) system time (CLOCK_REALTIME) | |
Time.
This class implements conversion from and to different time systems and time artithmetics. Internally it uses an atomic time in seconds and nanoseconds since 1970 as its representation of time. Conversion from and to UTC time or POSIX time are available. No timezones or local time are supported (use the ctime API for that).
Some of the constructors and operators can throw. Non-throwing methods to manipulate the time are provided as well.
This time object can represent the time from T_MIN to T_MAX, which is (the old) 32bit POSIX time. Note that for the different GNSS times you will get negative week numbers (GPS, Galileo, BeiDou) or a negative offset "M4" value (GLONASS) for timestamps before the beginning of respective timescales.
---1970-------------1980-------1996-1999----2006--------------------2106---//--fuuuuuture----> time 1970-01-01 00:00:00.0 UTC |<----- std::time_t ---------------------------------------------------//----->| |<----- ros::Time/rclcpp::Time----------------------------------->| 1980-01-06 00:00:00.0 UTC |<---- GPS time---------------------------------------//-----> 1996-01-01 00:00:00.0 UTC(SU) |<---- GLONASS time -----------------------//-----> 1999-08-21 23:59:47.0 UTC |<---- Galileo time ------------------//-----> 2006-01-01 00:00:00.0 UTC |<---- BeiDou time -----------//-----> |<======================= Time object ===========================>| T_MIN T_MAX 1970-01-01 00:00:0.0 UTC 2106-02-06 06:28:16.0 UTC (approximately!)
Some notes:
Some references:
|
static |
|
static |
|
static |
|
static |
|
static |
From TAI time (CLOCK_TAI)
|
static |
From system clock current (now) system time (CLOCK_REALTIME)
bool fpsdk::common::time::Time::SetSecNSec | ( | const uint32_t | sec, |
const uint32_t | nsec ) |
bool fpsdk::common::time::Time::SetNSec | ( | const uint64_t | nsec | ) |
Set time from nanoseconds (atomic)
[in] | nsec | Time value nanoseconds (> 0) |
bool fpsdk::common::time::Time::SetSec | ( | const double | sec | ) |
Set time from seconds (atomic)
[in] | sec | Time value seconds (> 0.0) |
bool fpsdk::common::time::Time::SetPosix | ( | const time_t | posix | ) |
Set time from POSIX time (POSIX)
[in] | posix | The POSIX time |
bool fpsdk::common::time::Time::SetRosTime | ( | const RosTime & | rostime | ) |
Set time from ROS time (POSIX)
[in] | rostime | Time value |
bool fpsdk::common::time::Time::SetWnoTow | ( | const WnoTow & | wnotow | ) |
Set time from GNSS (GPS, Galileo, BeiDou) time (atomic)
[in] | wnotow | GNSS time |
bool fpsdk::common::time::Time::SetGloTime | ( | const GloTime & | glotime | ) |
Set time from GLONASS time (UTC + 3h)
[in] | glotime | GLONASS time |
bool fpsdk::common::time::Time::SetUtcTime | ( | const UtcTime & | utctime | ) |
Set time from UTC time (UTC)
[in] | utctime | UTC time |
bool fpsdk::common::time::Time::SetTai | ( | const time_t | tai | ) |
Set time from TAI time (CLOCK_TAI)
[in] | tai | The TAI time |
bool fpsdk::common::time::Time::SetClockRealtime | ( | ) |
Set time from system clock current (now) system time (CLOCK_REALTIME)
uint64_t fpsdk::common::time::Time::GetNSec | ( | ) | const |
Get time as nanoseconds (atomic)
double fpsdk::common::time::Time::GetSec | ( | const int | prec = 9 | ) | const |
Get time as seconds (atomic)
[in] | prec | Round the seconds to this many fractional digits (0-9) |
time_t fpsdk::common::time::Time::GetPosix | ( | ) | const |
Get time as POSIX time (POSIX)
RosTime fpsdk::common::time::Time::GetRosTime | ( | ) | const |
Get time as ROS time (POSIX)
WnoTow fpsdk::common::time::Time::GetWnoTow | ( | const WnoTow::Sys | sys = WnoTow::Sys::GPS, |
const int | prec = 9 ) const |
Get time as GNSS (GPS, Galileo, BeiDou) time (atomic)
[in] | sys | GNSS |
[in] | prec | Round the seconds to this many fractional digits (0-9) |
GloTime fpsdk::common::time::Time::GetGloTime | ( | const int | prec = 9 | ) | const |
Get time as GLONASS time (UTC + 3h)
[in] | prec | Round the seconds to this many fractional digits (0-9) |
UtcTime fpsdk::common::time::Time::GetUtcTime | ( | const int | prec = 9 | ) | const |
Get time as UTC time (UTC)
[in] | prec | Round the seconds to this many fractional digits (0-9) |
double fpsdk::common::time::Time::GetDayOfYear | ( | const int | prec = 12 | ) | const |
Get day of year.
[in] | prec | Round to this many fractional digits (0-12) |
time_t fpsdk::common::time::Time::GetTai | ( | ) | const |
Get time as TAI time (CLOCK_TAI)
std::chrono::milliseconds fpsdk::common::time::Time::GetChronoMilli | ( | ) | const |
Get time as std::chrono::duration (milliseconds since epoch) (POSIX)
std::chrono::nanoseconds fpsdk::common::time::Time::GetChronoNano | ( | ) | const |
Get time as std::chrono::nanoseconds (nanoseconds since epoch) (POSIX)
bool fpsdk::common::time::Time::IsZero | ( | ) | const |
Check if time is zero (invalid)
bool fpsdk::common::time::Time::AddDur | ( | const Duration & | dur | ) |
Add duration to time.
[in] | dur | Duration to add |
bool fpsdk::common::time::Time::AddSec | ( | const double | sec | ) |
Add seconds to time.
[in] | sec | Seconds to add |
bool fpsdk::common::time::Time::AddNSec | ( | const int64_t | nsec | ) |
Add nanoseconds to time.
[in] | nsec | Nanoseconds to add |
bool fpsdk::common::time::Time::SubDur | ( | const Duration & | dur | ) |
Substract duration from time.
[in] | dur | Duration to substract |
bool fpsdk::common::time::Time::SubNSec | ( | const int64_t | nsec | ) |
Substract nanoseconds from time.
[in] | nsec | Nanoseconds to substract |
bool fpsdk::common::time::Time::SubSec | ( | const double | sec | ) |
Substract seconds from time.
[in] | sec | Seconds to substract |
Calculate difference between times.
[in] | other | The other time |
[out] | diff | The difference to the other time (time - other) |
std::string fpsdk::common::time::Time::StrWnoTow | ( | const WnoTow::Sys | sys = WnoTow::Sys::GPS, |
const int | prec = 3 ) const |
Stringify as GNSS time (atomic)
[in] | sys | The desired GNSS time system |
[in] | prec | Number of fractional digits for the seconds (0-9) |
std::string fpsdk::common::time::Time::StrUtcTime | ( | const int | prec = 3 | ) | const |
Stringify as year, month, day, hour, minute and second time (UTC)
[in] | prec | Number of fractional digits for the seconds (0-9) |
std::string fpsdk::common::time::Time::StrIsoTime | ( | const int | prec = 0 | ) | const |
Stringify as ISO 8601 time (UTC)
[in] | prec | Number of fractional digits for the seconds (0-9) |
bool fpsdk::common::time::Time::SetCurrentLeapseconds | ( | const int | value | ) | const |
Set or change current leapseconds.
This extends the build-in leapseconds table with the current value. The given value is assumed to be the leapseconds value (TAI - UTC) that is valid from the object's time (truncated to integer seconds). The object's time must be past (later than) and the value must be greater or equal than the information in the latest entry in the built-in table.
The built-in table and the "current leapseconds" information are global per process. Setting or changing the current leapseconds value affects all existing and future Time objects immediately.
For example, the latest entry in the built-in table may be 2017-01-01 00:00:00 UTC with TAI-UTC = 37. So it could be updated with a time of 2035-06-01 00:00:00 UTC and a value of 38.
The idea is to use this in real-time applications where an upcoming leapseconds event can be learned from on-line data, such as GNSS navigation data. Calling this method at and appropriate time with appropriate arguments is up to the application. For example, if multiple future leapseconds events are known, the right event must be "activated" at the right time.
[in] | value | The current leapseconds value |
|
static |
|
static |
|
static |
uint32_t fpsdk::common::time::Time::sec_ |
uint32_t fpsdk::common::time::Time::nsec_ |