A time representation class for all common time formats, including GPS. There is a seamless conversion between dates, times, and both, as well as the ability to input and output the stored day-time in formatted strings (printf() and scanf()).
Internally, the representation of day and time uses a CommonTime object.
In addition, the representation includes a tolerance value which is used in CommonTime comparisons. It defaults to the value of the static gnsstk::Epoch::EPOCH_TOLERANCE, but this can be modified with the static method setEpochTolerance(). Several different default tolerances have been defined and are in the Epoch-Specific Definitions section. The tolerance can also be changed on a per-object basis with the setTolerance() member function. All comparisons are done using the tolerance as a range for the comparison. So, for example, operator==() returns true if the times are within 'tolerance' seconds. Once set for each object, the tolerance is appropriately "carried forward" to new objects through the copy operator (operator=), the copy constructor, and elsewhere.
The internal representation is manipulated using four fundamental routines, two that convert between 'jday' (the integer representation of JD) and calendar date: year/month/day-of-month, and two that convert between seconds-of-day and hour/minute/second. These routines can be found in the TimeConverters.hpp file. The range of validity of the jday–calendar routines is approximately 4317 B.C. to 4317 A.D.; these limits are incorporated into constants Epoch::BEGINNING_OF_TIME and Epoch::END_OF_TIME.
This representation separates day and time-of-day cleanly. Because day and time are logically separated, it is possible to use Epoch for day only, or for time only. Thus, for example, one could instantiate a Epoch object and only manipulate the date, without reference to time-of-day; or vice-versa. [However in this regard note that the default constructor for Epoch sets the data, not to zero, but to the current (system) time.]
When constructing Epoch objects from GPS time values – such as GPS week and seconds of weeks, or GPS week and z count – there may be ambiguity associated with the GPS week. Many receivers and receiver processing software store the GPS week as it appears in the NAV message, as a 10-bit number. This leads to a 1024 week ambiguity when 10-bit GPS weeks are used to specify a Epoch. In general, Epoch uses the system time to disambiguate which 1024 week period to use. This is a good assumption except when processing binary data from before GPS week rollover, which occured on August 22, 1999.
#include <Epoch.hpp>
Public Member Functions | |
NEW_EXCEPTION_CLASS (EpochException, gnsstk::Exception) | |
NEW_EXCEPTION_CLASS (FormatException, gnsstk::Exception) | |
Constructors and Destructor | |
Epoch (const TimeTag &tt=SystemTime()) | |
Epoch (const CommonTime &ct) noexcept | |
Epoch (const WeekSecond &tt, short year) | |
Epoch (const GPSZcount &gzc) noexcept | |
~Epoch () noexcept | |
Destructor. More... | |
Assignment and Copy | |
Epoch (const Epoch &right) noexcept | |
Copy constructor. More... | |
Epoch & | operator= (const Epoch &right) noexcept |
Assignment operator. More... | |
Arithmetic | |
double | operator- (const Epoch &right) const noexcept |
Epoch | operator+ (double sec) const |
Epoch | operator- (double sec) const |
Epoch & | operator+= (double sec) |
Epoch & | operator-= (double sec) |
Epoch & | addSeconds (double seconds) |
Epoch & | addSeconds (long seconds) |
Epoch & | addMilliSeconds (long msec) |
Epoch & | addMicroSeconds (long usec) |
Comparisons | |
bool | operator== (const Epoch &right) const noexcept |
bool | operator!= (const Epoch &right) const noexcept |
bool | operator< (const Epoch &right) const noexcept |
bool | operator> (const Epoch &right) const noexcept |
bool | operator<= (const Epoch &right) const noexcept |
bool | operator>= (const Epoch &right) const noexcept |
Accessor Methods (get and set) | |
template<class TimeTagType > | |
TimeTagType | get () const |
long double | JD () const |
long double | MJD () const |
short | year () const |
Get year. More... | |
short | month () const |
Get month of year. More... | |
short | day () const |
Get day of month. More... | |
short | dow () const |
Get day of week. More... | |
short | hour () const |
Get hour of day. More... | |
short | minute () const |
Get minutes of hour. More... | |
double | second () const |
Get seconds of minute. More... | |
double | sod () const |
Get seconds of day. More... | |
short | GPSModWeek () const |
Get 10-bit GPS week. More... | |
short | GPSweek10 () const |
Get 10-bit GPS week. Deprecated, used GPSModWeek() More... | |
long | GPSzcount () const |
Get normal (19 bit) zcount. More... | |
long | GPSzcountFloor () const |
Same as GPSzcount() but without rounding to nearest zcount. More... | |
unsigned long | GPSzcount32 () const |
unsigned long | GPSzcount32Floor () const |
Same as fullZcount() but without rounding to nearest zcount. More... | |
double | GPSsow () const |
Get GPS second of week. More... | |
short | GPSweek () const |
Get full (>10 bits) week. More... | |
double | BDSsow () const |
Get BDS second of week. More... | |
short | BDSweek () const |
Get full BDS week. More... | |
short | BDSModWeek () const |
Get mod (short) BDS week. More... | |
double | QZSsow () const |
Get QZS second of week. More... | |
short | QZSweek () const |
Get full QZS week. More... | |
short | QZSModWeek () const |
Get mod (short) QZS week. More... | |
double | GALsow () const |
Get GAL second of week. More... | |
short | GALweek () const |
Get full GAL week. More... | |
short | GALModWeek () const |
Get mod (short) GAL week. More... | |
short | doy () const |
Get day of year. More... | |
struct timeval | unixTime () const |
Get object time in UNIX timeval structure. More... | |
operator GPSZcount () const | |
operator CommonTime () const noexcept | |
Convert this object to a CommonTime object. More... | |
Epoch & | set (const TimeTag &tt=SystemTime()) |
Epoch & | set (const WeekSecond &tt, short year) |
Epoch & | set (const CommonTime &c) noexcept |
Epoch & | set (const GPSZcount &z) |
Epoch & | setTime (const CommonTime &ct) |
Epoch & | setDate (const CommonTime &ct) |
Epoch & | setLocalTime () |
Printing and Scanning Methods | |
Epoch & | scanf (const std::string &str, const std::string &fmt) |
std::string | printf (const std::string &fmt=PRINT_FORMAT) const |
Static Public Attributes | |
Epoch-Specific Definitions | |
All of these tolerances are 1/2 of the tolerance they specify. So one nsec tolerance is actually 1/2 an ns added to the time in units of days. | |
static const double | ONE_NSEC_TOLERANCE = 1e-9 |
One nanosecond tolerance. More... | |
static const double | ONE_USEC_TOLERANCE = 1e-6 |
One microsecond tolerance. More... | |
static const double | ONE_MSEC_TOLERANCE = 1e-3 |
One millisecond tolerance. More... | |
static const double | ONE_SEC_TOLERANCE = 1 |
One second tolerance. More... | |
static const double | ONE_MIN_TOLERANCE = 60 |
One minute tolerance. More... | |
static const double | ONE_HOUR_TOLERANCE = 3600 |
One hour tolerance. More... | |
static double | EPOCH_TOLERANCE = ONE_NSEC_TOLERANCE |
Default tolerance for time equality in days. More... | |
static const Epoch | BEGINNING_OF_TIME |
Earliest representable Epoch. More... | |
static const Epoch | END_OF_TIME |
Latest Representable Epoch. More... | |
static std::string | PRINT_FORMAT |
This is how an Epoch is printed by default. More... | |
Private Attributes | |
Private Methods and Data Members | |
CommonTime | core |
double | tolerance |
double tolerance used in comparisons (seconds) More... | |
Tolerance Functions | |
Epoch & | setTolerance (double tol) noexcept |
double | getTolerance () const noexcept |
static double | setEpochTolerance (double tol) noexcept |
Changes the EPOCH_TOLERANCE for all Epoch objects. More... | |
static double | getEpochTolerance () noexcept |
Returns the current EPOCH_TOLERANCE. More... | |
gnsstk::Epoch::Epoch | ( | const TimeTag & | tt = SystemTime() | ) |
Default Constructor. Initializes to current system time or to the given TimeTag. TimeTag-covered constructors: year, month, day, hour, minute, second (CivilTime) long double mjd (MJD) double mjd (MJD) year, doy, sod (YDSTime) Unix struct timeval (UnixTime) GPS full week and second (GPSWeekSecond)
EpochException |
|
noexcept |
CommonTime Constructor. Set the time using the given CommonTime object.
gnsstk::Epoch::Epoch | ( | const WeekSecond & | tt, |
short | year | ||
) |
TimeTag + Year Constructor. Set the current time using the given year as a hint. For example, when one only knows the 10-bit GPS week, one could could use a "hint" year to figure out which Epoch the week was in. TimeTag + year -covered constructors: gps 10-bit week and second and year (GPSEpochWeekSecond + year) gps week and zcount and year (GPSWeekZcount + year)
Epochexception | TimeTag + Year Constructor. Set the current time using the given year as a hint. |
Epoch & gnsstk::Epoch::addMicroSeconds | ( | long | usec | ) |
Epoch & gnsstk::Epoch::addMilliSeconds | ( | long | msec | ) |
Epoch & gnsstk::Epoch::addSeconds | ( | double | seconds | ) |
Epoch & gnsstk::Epoch::addSeconds | ( | long | seconds | ) |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
TimeTagType gnsstk::Epoch::get |
|
inlinestaticnoexcept |
|
inlinenoexcept |
|
inline |
|
inline |
|
inline |
|
inline |
Get 10-bit GPS week. Deprecated, used GPSModWeek()
Get 10-bit GPS week, deprecated, use GPSModWeek()
EpochException |
|
inline |
|
inline |
|
inline |
|
inline |
Same as GPSzcount() but without rounding to nearest zcount.
Same as GPSzcount() but without rounding to nearest zcount.
EpochException |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
gnsstk::Epoch::NEW_EXCEPTION_CLASS | ( | EpochException | , |
gnsstk::Exception | |||
) |
gnsstk::Epoch::NEW_EXCEPTION_CLASS | ( | FormatException | , |
gnsstk::Exception | |||
) |
Epoch formatting ("printing") error exception class.
|
noexcept |
Convert this object to a CommonTime object.
gnsstk::Epoch::operator GPSZcount | ( | ) | const |
Epoch gnsstk::Epoch::operator+ | ( | double | sec | ) | const |
Epoch & gnsstk::Epoch::operator+= | ( | double | sec | ) |
Epoch gnsstk::Epoch::operator- | ( | double | sec | ) | const |
Epoch & gnsstk::Epoch::operator-= | ( | double | sec | ) |
string gnsstk::Epoch::printf | ( | const std::string & | fmt = PRINT_FORMAT | ) | const |
Format this time into a string.
Generate and return a string containing a formatted date, formatted by the specification fmt
.
fmt | format to use for this time. |
fmt
. StringUtils::StringException |
|
inline |
|
inline |
|
inline |
Similar to scanf, this function takes a string and a format describing string in order to read in values. The parameters it can take are listed below and described above with the printf() function.
The specification must resolve to a day at a minimum level. The following table lists combinations that give valid times. Anything more or other combinations will give unknown (read as: "bad") results so don't try it. Anything less will throw an exception. If nothing changes the time of day, it will default to midnight. Also, the year defaults to the current year if a year isn't specified or can't be determined.
So
works but
doesn't work (incomplete specification because it doesn't specify a day).
Don't worry about counting whitespace - this function will take care of that. Just make sure that the extra stuff in the format string (ie '.' ',') are in the same relative location as they are in the actual string. (see in the example above))
str | string to get date/time from. |
fmt | format to use to parse str . |
EpochException | if fmt is an incomplete specification |
FormatException | if unable to scan str . |
StringException | if an error occurs manipulating the str or fmt strings. |
|
inline |
|
noexcept |
Set the object using the give CommonTime.
c | the CommonTime object to set to |
Epoch & gnsstk::Epoch::set | ( | const TimeTag & | tt = SystemTime() | ) |
Set the object using a TimeTag object.
tt | the TimeTag to which to set this object (Defaults to SystemTime()). |
EpochException |
Epoch & gnsstk::Epoch::set | ( | const WeekSecond & | tt, |
short | year | ||
) |
Epoch & gnsstk::Epoch::setDate | ( | const CommonTime & | ct | ) |
Set the object's date using a CommonTime object. This operation leaves the object's time unchanged.
EpochException |
|
inlinestaticnoexcept |
Epoch & gnsstk::Epoch::setLocalTime | ( | ) |
Epoch & gnsstk::Epoch::setTime | ( | const CommonTime & | ct | ) |
Set the object's time using a CommonTime object. This operation leaves the object's date unchanged.
EpochException |
|
noexcept |
Sets the tolerance for output and comparisons on this object only. See the constants in this file (e.g. ONE_NSEC_TOLERANCE) for some easy to use tolerance values.
tol | Tolerance in days to be used by comparison operators. |
|
inline |
|
inline |
|
inline |
|
private |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
private |