ocssw
V2022
|
#include <TimePoint.hpp>
Public Types | |
enum | ClockType { local, utc, tai, tai93, gps, tt } |
Public Member Functions | |
TimePoint () | |
TimePoint (const double seconds_since_epoch, const TimePoint::ClockType clock_type=ClockType::utc) | |
TimePoint (const boost::gregorian::date &date, const boost::posix_time::time_duration &time) | |
TimePoint (const boost::gregorian::date date, const boost::posix_time::time_duration &time, const int milli) | |
TimePoint (const boost::posix_time::ptime &ptime) | |
TimePoint (const std::string &datetime) | |
const std::string | to_string (const std::string &format="%Y-%m-%dT%H:%M:%S%F") const |
const boost::posix_time::ptime & | native () const |
double | seconds_since (const TimePoint::ClockType clock_type) const |
double | utc () const |
double | tai () const |
double | tai93 () const |
double | gps () const |
double | tt () const |
double | julian_date () const |
double | modified_julian_date () const |
double | reduced_julian_date () const |
double | truncated_julian_date () const |
int16_t | year () const |
uint8_t | month () const |
uint8_t | day () const |
uint16_t | day_of_year () const |
uint8_t | hour () const |
uint8_t | minute () const |
uint8_t | second () const |
Friends | |
std::ostream & | operator<< (std::ostream &out, const TimePoint &t) |
bool | operator== (const TimePoint &lhs, const TimePoint &rhs) |
bool | operator!= (const TimePoint &lhs, const TimePoint &rhs) |
bool | operator< (const TimePoint &lhs, const TimePoint &rhs) |
bool | operator> (const TimePoint &lhs, const TimePoint &rhs) |
bool | operator<= (const TimePoint &lhs, const TimePoint &rhs) |
bool | operator>= (const TimePoint &lhs, const TimePoint &rhs) |
Detailed Description
Representation of a single point in time, with clock conversions.
The internal representation is a boost::posix_time::ptime, meaning that leap seconds are compensated for manually within this class. ptime's are stored as a Gregorian date and the time duration that has passed within that date, wrapping to a new date when hitting 23:59:60; this also means that leap seconds can't be represented in UTC (time will "freeze").
Conversions to and from local time are not supported, largely due to DST.
Example
Definition at line 29 of file TimePoint.hpp.
Member Enumeration Documentation
◆ ClockType
|
strong |
Enumerator | |
---|---|
local | Local UTC clock with time zone offset. |
utc | UTC Unix time. |
tai | TAI clock 1958. |
tai93 | TAI clock 1993. |
gps | GPS clock 1980, Jan 6. |
tt | Terrestrial Time clock 1977. |
Definition at line 35 of file TimePoint.hpp.
Constructor & Destructor Documentation
◆ TimePoint() [1/6]
|
inlineexplicit |
Construct a TimePoint with the current time.
Definition at line 47 of file TimePoint.hpp.
◆ TimePoint() [2/6]
TimePoint | ( | const double | seconds_since_epoch, |
const TimePoint::ClockType | clock_type = ClockType::utc |
||
) |
Construct a clock with offset from the clock epic in seconds.
This is the epic for each clock:
Clock | Epoch |
---|---|
local | Jan 1, 1970, 00:00:00 (standard Unix epoch) |
utc | Jan 1, 1970, 00:00:00 (standard Unix epoch) |
tai | Jan 1, 1958, 00:00:00 |
tai93 | Jan 1, 1993, 00:00:00 |
gps | Jan 6, 1980, 00:00:00 |
tt | Jan 1, 1977, 00:00:00 |
- Parameters
-
seconds_since_epoch seconds since clock epoch clock_type what kind of clock
◆ TimePoint() [3/6]
|
inline |
Construct a new TimePoint given date, time, and optional input clock_type.
- Parameters
-
date date time time
Definition at line 74 of file TimePoint.hpp.
◆ TimePoint() [4/6]
|
inline |
Construct a new TimePoint given date, time plus miliseconds.
- Parameters
-
date date time time milli milliseconds
Definition at line 83 of file TimePoint.hpp.
◆ TimePoint() [5/6]
Construct a new TimePoint given a boost ptime.
- Parameters
-
ptime time point to represent
Definition at line 90 of file TimePoint.hpp.
◆ TimePoint() [6/6]
|
explicit |
Construct a new TimePoint given a string.
- Parameters
-
datetime string representation of date (see example section for acceptable strings)
Member Function Documentation
◆ day()
|
inline |
Get month-based day part of the date (one-based, first of the month = 1)
- Returns
- day
Definition at line 294 of file TimePoint.hpp.
◆ day_of_year()
|
inline |
Get day of year part of the date (one-based, Jan 1 = 1)
- Returns
- day of year
Definition at line 298 of file TimePoint.hpp.
◆ gps()
|
inline |
Get GPS time in seconds since Jan 6, 1980 including leap seconds.
- Returns
- GPS seconds since 1980 Jan 6
Definition at line 193 of file TimePoint.hpp.
◆ hour()
|
inline |
◆ julian_date()
|
inline |
◆ minute()
|
inline |
◆ modified_julian_date()
|
inline |
◆ month()
|
inline |
Get month part of the date (one-based, Jan = 1)
- Returns
- month
Definition at line 290 of file TimePoint.hpp.
◆ native()
|
inline |
Get the native representation of this date time.
This shouldn't really be used, as the internals might change to not even use a ptime if a limitation is discovered.
- Returns
- the raw, underlying ptime used by this object
Definition at line 122 of file TimePoint.hpp.
◆ reduced_julian_date()
|
inline |
◆ second()
|
inline |
◆ seconds_since()
double seconds_since | ( | const TimePoint::ClockType | clock_type | ) | const |
Return duration since given time.
- Parameters
-
time epoch time to check
- Returns
- duration since given epoch
Return duration since 1970-01-01 00:00:00.
- Returns
- duration since 1970-01-01 00:00:00. / boost::posix_time::time_duration duration_since_1970() const {return duration_since(boost::posix_time::ptime{{1970,1,1}});} /! Return seconds since 1970-01-01 00:00:00.
-
seconds since 1970-01-01 00:00:00. / double seconds_since_1970() const {return (double)duration_since_1970().total_microseconds() / 1'000'000.0;} /! Return duration since 1993-01-01 00:00:00.
-
duration since 1993-01-01 00:00:00. / boost::posix_time::time_duration duration_since_1993() const {return duration_since(boost::posix_time::ptime{{1993,1,1}});} /! Return seconds since 1993-01-01 00:00:00.
-
seconds since 1993-01-01 00:00:00. / double seconds_since_1993() const {return (double)duration_since_1993().total_microseconds() / 1'000'000.0;} /! Return duration since 1958-01-01 00:00:00.
-
duration since 1958-01-01 00:00:00. / boost::posix_time::time_duration duration_since_1958() const {return duration_since(boost::posix_time::ptime{{1958,1,1}});} /! Return seconds since 1958-01-01 00:00:00.
-
seconds since 1958-01-01 00:00:00. */ double seconds_since_1958() const {return (double)duration_since_1958().total_microseconds() / 1'000'000.0;}
/*! \brief Return seconds since clock epoch adding leap seconds for TAI based clocks. \return seconds since epoch. This is the epic for each clock: Clock | Epoch ----- | ----- local | Jan 1, 1970, 00:00:00 (standard Unix epoch) utc | Jan 1, 1970, 00:00:00 (standard Unix epoch) tai | Jan 1, 1958, 00:00:00 tai93 | Jan 1, 1993, 00:00:00 gps | Jan 6, 1980, 00:00:00 tt | Jan 1, 1977, 00:00:00
◆ tai()
|
inline |
Get TAI time in seconds since Jan 1, 1958 including leap seconds.
- Returns
- TAI seconds since 1958
Definition at line 185 of file TimePoint.hpp.
◆ tai93()
|
inline |
Get TAI93 time in seconds since Jan 1, 1993 including leap seconds.
- Returns
- TAI seconds since 1993
Definition at line 189 of file TimePoint.hpp.
◆ to_string()
const std::string to_string | ( | const std::string & | format = "%Y-%m-%dT%H:%M:%S%F" | ) | const |
Return time point as string, with the given format.
The format is as described in the following link:
https://www.boost.org/doc/libs/1_73_0/doc/html/date_time/date_time_io.html
- Parameters
-
format format string
- Returns
- string representing this time point
◆ truncated_julian_date()
|
inline |
Get truncated Julian date.
- Returns
- truncated Julian date
Definition at line 215 of file TimePoint.hpp.
◆ tt()
|
inline |
Get terrestrial time in seconds since Jan 1, 1977.
- Returns
- Terrestrial seconds since 1977
Definition at line 197 of file TimePoint.hpp.
◆ utc()
|
inline |
Get UTC time (unix) in seconds since Jan 1, 1970.
- Returns
- TAI seconds since 1970
Definition at line 181 of file TimePoint.hpp.
◆ year()
|
inline |
Friends And Related Function Documentation
◆ operator!=
Check if two time points are not equal (clock type or time differ)
- Parameters
-
lhs Left hand side argument rhs Right hand side argument
- Returns
- true if the two given objects are not equal
Definition at line 236 of file TimePoint.hpp.
◆ operator<
Return true if the left TimePoint is less than the right.
- Parameters
-
lhs Left hand side argument rhs Right hand side argument
- Returns
- true if the left hand side is less
Definition at line 246 of file TimePoint.hpp.
◆ operator<<
Output time point using the to_string() function with default parameters.
- Parameters
-
out output stream to which to print t TimePoint object to print
- Returns
- output stream passed in, for chaining
Definition at line 132 of file TimePoint.hpp.
◆ operator<=
Return true if the left TimePoint is less than or equal to the right.
- Parameters
-
lhs Left hand side argument rhs Right hand side argument
- Returns
- true if the left hand side is less than or equal to the right
Definition at line 268 of file TimePoint.hpp.
◆ operator==
Check if two time points are equal.
- Parameters
-
lhs Left hand side argument rhs Right hand side argument
- Returns
- true if the two given objects are equal
Definition at line 225 of file TimePoint.hpp.
◆ operator>
Return true if the left TimePoint is greater than the right.
- Parameters
-
lhs Left hand side argument rhs Right hand side argument
- Returns
- true if the left hand side is greater
Definition at line 258 of file TimePoint.hpp.
◆ operator>=
Return true if the left TimePoint is greater than or equal to the right.
- Parameters
-
lhs Left hand side argument rhs Right hand side argument
- Returns
- true if the left hand side is greater than or equal to the right
Definition at line 278 of file TimePoint.hpp.
The documentation for this class was generated from the following file:
- /gfs-oceanweb/web/ocssw/ocssw_src/include/focs/TimePoint.hpp