Timestamp Encoding Specification
The Heex SDK excels in Smart Data management using an innovative event-based approach. Each event is given a timestamp, capturing its exact occurrence time. The encoding of these timestamps plays a crucial role in messaging and storage. This page is your go-to guide, detailing the specifications for timestamp encoding in the dynamic realms of messaging and storage.
HeexSDK methods requires timestamps in UTC time.
For example, every timestamp generated by default uses the boost::posix_time::microsec_clock::universal_time();
.
Format
HeexSDK uses the ISO 8601-1:2019 standard. It is a string representation of dates and times. The main advantage is the availability of many libraries dealing with this representation.
There are many options, but the format favored by Heex is YYYY-MM-DDThh:mm:ss.sss
.
YYYY
is the yearMM
is the monthDD
is the dayT
is a separatorhh
is for hoursmm
is for minutesss
is for secondssss
(following the dot) is for milliseconds
If more precision is needed, the format YYYY-MM-DDThh:mm:ss.ssssss
can be used (microsecond precision).
Example:
2021-07-07T13:54:05.123
See also this Wikipedia article for more details.
Notes on Usage & Conversion
Heex uses libraries (like boost) to generate or read timestamps. Therefore, you need to convert your timestamp if it is stored in Posix, Boost or Unix time (time_t). Some utility functions do exist in the C++ Standard Library (std) and Boost to perform the conversion. In addition, some middleware like ROS also provide a custom time format that need to be converted.
Some of the most relevant utility functions are:
Original type (myTime) | Final type | Utility function |
---|---|---|
boost::posix_time::ptime | iso_extended_string | to_iso_extended_string(myTime) |
long double (Unix format) | iso_extended_string | HeexUtils::unixTimeToIsoExtendedTime(myTime) |
ros::Time | iso_extended_string | to_iso_extended_string(myTime.toBoost()) |
Original type (myTime) | Final type | Utility function |
---|---|---|
iso_extended_string | boost::posix_time::ptime | boost::posix_time::from_iso_extended_string(myTime) |
iso_extended_string | long double (Unix format) | HeexUtils::isoExtendedTimeToUnixTime(myTime) |
iso_extended_string | ros::Time | ros::Time::fromBoost(boost::posix_time::from_iso_extended_string(myTime)) |
If you are using Boost, this page may be hepful: Boost Posix Time System