OB.DAAC Logo
NASA Logo
Ocean Color Science Software

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

enum 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]

TimePoint ( )
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_epochseconds since clock epoch
clock_typewhat kind of clock

◆ TimePoint() [3/6]

TimePoint ( const boost::gregorian::date &  date,
const boost::posix_time::time_duration &  time 
)
inline

Construct a new TimePoint given date, time, and optional input clock_type.

Parameters
datedate
timetime

Definition at line 74 of file TimePoint.hpp.

◆ TimePoint() [4/6]

TimePoint ( const boost::gregorian::date  date,
const boost::posix_time::time_duration &  time,
const int  milli 
)
inline

Construct a new TimePoint given date, time plus miliseconds.

Parameters
datedate
timetime
millimilliseconds

Definition at line 83 of file TimePoint.hpp.

◆ TimePoint() [5/6]

TimePoint ( const boost::posix_time::ptime &  ptime)
inlineexplicit

Construct a new TimePoint given a boost ptime.

Parameters
ptimetime point to represent

Definition at line 90 of file TimePoint.hpp.

◆ TimePoint() [6/6]

TimePoint ( const std::string datetime)
explicit

Construct a new TimePoint given a string.

Parameters
datetimestring representation of date (see example section for acceptable strings)

Member Function Documentation

◆ day()

uint8_t day ( ) const
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()

uint16_t day_of_year ( ) const
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()

double gps ( ) const
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()

uint8_t hour ( ) const
inline

Get hour part of the time.

Returns
hour

Definition at line 302 of file TimePoint.hpp.

◆ julian_date()

double julian_date ( ) const
inline

Get Julian date.

Returns
Julian date

Definition at line 206 of file TimePoint.hpp.

◆ minute()

uint8_t minute ( ) const
inline

Get minute part of the time.

Returns
minute

Definition at line 306 of file TimePoint.hpp.

◆ modified_julian_date()

double modified_julian_date ( ) const
inline

Get modified Julian date.

Returns
modified Julian date

Definition at line 209 of file TimePoint.hpp.

◆ month()

uint8_t month ( ) const
inline

Get month part of the date (one-based, Jan = 1)

Returns
month

Definition at line 290 of file TimePoint.hpp.

◆ native()

const boost::posix_time::ptime& native ( ) const
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()

double reduced_julian_date ( ) const
inline

Get reduced Julian date.

Returns
reduced Julian date

Definition at line 212 of file TimePoint.hpp.

◆ second()

uint8_t second ( ) const
inline

Get second part of the time.

Returns
second

Definition at line 310 of file TimePoint.hpp.

◆ seconds_since()

double seconds_since ( const TimePoint::ClockType  clock_type) const

Return duration since given time.

Parameters
timeepoch 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()

double tai ( ) const
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()

double tai93 ( ) const
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
formatformat string
Returns
string representing this time point

◆ truncated_julian_date()

double truncated_julian_date ( ) const
inline

Get truncated Julian date.

Returns
truncated Julian date

Definition at line 215 of file TimePoint.hpp.

◆ tt()

double tt ( ) const
inline

Get terrestrial time in seconds since Jan 1, 1977.

Returns
Terrestrial seconds since 1977

Definition at line 197 of file TimePoint.hpp.

◆ utc()

double utc ( ) const
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()

int16_t year ( ) const
inline

Get year part of the date.

Returns
year

Definition at line 286 of file TimePoint.hpp.

Friends And Related Function Documentation

◆ operator!=

bool operator!= ( const TimePoint lhs,
const TimePoint rhs 
)
friend

Check if two time points are not equal (clock type or time differ)

Parameters
lhsLeft hand side argument
rhsRight hand side argument
Returns
true if the two given objects are not equal

Definition at line 236 of file TimePoint.hpp.

◆ operator<

bool operator< ( const TimePoint lhs,
const TimePoint rhs 
)
friend

Return true if the left TimePoint is less than the right.

Parameters
lhsLeft hand side argument
rhsRight hand side argument
Returns
true if the left hand side is less

Definition at line 246 of file TimePoint.hpp.

◆ operator<<

std::ostream& operator<< ( std::ostream &  out,
const TimePoint t 
)
friend

Output time point using the to_string() function with default parameters.

Parameters
outoutput stream to which to print
tTimePoint object to print
Returns
output stream passed in, for chaining

Definition at line 132 of file TimePoint.hpp.

◆ operator<=

bool operator<= ( const TimePoint lhs,
const TimePoint rhs 
)
friend

Return true if the left TimePoint is less than or equal to the right.

Parameters
lhsLeft hand side argument
rhsRight 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==

bool operator== ( const TimePoint lhs,
const TimePoint rhs 
)
friend

Check if two time points are equal.

Parameters
lhsLeft hand side argument
rhsRight hand side argument
Returns
true if the two given objects are equal

Definition at line 225 of file TimePoint.hpp.

◆ operator>

bool operator> ( const TimePoint lhs,
const TimePoint rhs 
)
friend

Return true if the left TimePoint is greater than the right.

Parameters
lhsLeft hand side argument
rhsRight hand side argument
Returns
true if the left hand side is greater

Definition at line 258 of file TimePoint.hpp.

◆ operator>=

bool operator>= ( const TimePoint lhs,
const TimePoint rhs 
)
friend

Return true if the left TimePoint is greater than or equal to the right.

Parameters
lhsLeft hand side argument
rhsRight 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: