|
|
These do not throw and instead return true/false.
- Note
- These throw std::runtime_error if the values are out of range.
|
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)
|
|
|
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)
|
|
|
bool | IsZero () const |
| Check if time is zero (invalid)
|
|
|
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.
|
|
|
- Note
- These throw std::runtime_error if the values are out of range.
|
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.
|
|
|
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.
|
|
|
|
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)
|
|
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:
*
* - "Strict" POSIX time is used for the methods marked with "POSIX". This time has a discontinuity and/or ambiguity
* at/during leapsecond events. It does not use the "Mills" or NTP style of handling these periods and is therefore,
* for those timestamps, likely not compatible with the system time (CLOCK_REALTIME) of a typical Linux system. See
* references below.
* - The from/to UTC calculations are not fully correct for times before 1972.
* - FromClockTai() and SetClockTai() likely will not give the expected result unless your system (Linux kernel) is
* configured for the correct leapsecond.
* - The precision of all integer getters, setters and operators should be [ns] in all cases
* - The precision of all double getters, setters and operators should be [ns] in most cases
* - The internal representation of time (the sec_ value) is atomic, but it is not CLOCK_TAI (which already "has" 10
* leapseconds at sec_ = 0).
*
* Some references:
*
* - https://en.wikipedia.org/wiki/Unix_time
* - https://en.wikipedia.org/wiki/Atomic_clock
* - https://en.wikipedia.org/wiki/Coordinated_Universal_Time
* - https://docs.ntpsec.org/latest/leapsmear.html
* - https://www.eecis.udel.edu/~mills/leap.html
* - https://manpages.org/adjtimex/2
*
*
Definition at line 564 of file time.hpp.