This class encapsulates the "Julian Date" time representation.
The implementation is in terms of "jday", which is int(JD+0.5), plus two scaled 64-bit integers (dday,fday) to represent the fraction of the day. So fraction of day = (dday+fday*JDFACT)*JDFACT where JDFACT = 1.0e-17; this yields precision up to 1e-34. Implementation of class MJD is similar.
There are a few subtle implementation issues here: (0) JD is integer at noon, which is awkward; MJD is integer at midnight. Thus the representation of "integer day" plus "fractional part of day" or similar is straightforward for MJD but for JD there is that pesky 0.5.
(1) Some compliers, notably MSVC on Windows implement long double as double. This causes a loss of precision when attempting to write JD as a single floating number (double or even long double). Therefore, point 2:
(2) Here, long double is eliminated; the long double c'tor is deprecated. There is a "long double JD()" provided, for convenience when high precision is not needed (e.g. Solar system ephemeris), but with a warning of less precision. NEVER try to store timetags for reuse as long double JD().
(3) TimeSystem is left out of the long double constructor on purpose, otherwise compilers see an ambiguity between the two c'tors (GPS here could be any system) MJD(long double jd, TimeSystem::GPS) and MJD(long ijd, double sod) because TimeSystem::GPS is an int and can be implicitly cast to double. [However note that TimeSystem(2) will not be implicitly cast.] Use setTimeSystem(TimeSystem::GPS).
(4) On constructors for JulianDate jd. The following give the same value: jd.fromString("1350000"); // full JD jd = JulianDate(1350000,43200,0.0); // jday not int(JD), sod, fsod jd.fromIntFrac(135000,0.0); // int(JD) and frac(JD)
(5) fromString() and asString() provide I/O which is repeatable and the most precise, with up to 34 decimal digits (prec ~ 1e-34 = JDFACT^2). fromIntFrac() is the worst b/c of the double fraction of the day.
Definition at line 89 of file JulianDate.hpp.
#include <JulianDate.hpp>
Public Member Functions | |
JulianDate Basic Operations | |
JulianDate (long double j=0., TimeSystem ts=TimeSystem::Unknown) | |
JulianDate (const JulianDate &right) | |
JulianDate (const TimeTag &right) | |
JulianDate (const CommonTime &right) | |
JulianDate & | operator= (const JulianDate &right) |
virtual | ~JulianDate () |
Virtual Destructor. More... | |
virtual CommonTime | convertToCommonTime () const |
virtual void | convertFromCommonTime (const CommonTime &ct) |
virtual std::string | printf (const std::string &fmt) const |
virtual std::string | printError (const std::string &fmt) const |
virtual bool | setFromInfo (const IdToValue &info) |
virtual std::string | getPrintChars () const |
virtual std::string | getDefaultFormat () const |
Return a string containing the default format to use in printing. More... | |
virtual bool | isValid () const |
Returns true if this object's members are valid, false otherwise. More... | |
virtual void | reset () |
Reset this object to the default state. More... | |
![]() | |
virtual std::string | asString () const |
bool | changeTimeSystem (TimeSystem timeSys) |
bool | changeTimeSystem (TimeSystem timeSys, TimeSystemConverter *conv) |
TimeSystem | getTimeSystem () const |
Obtain time system info (enum). More... | |
virtual | operator CommonTime () const |
virtual void | scanf (const std::string &str, const std::string &fmt) |
void | setTimeSystem (const TimeSystem &timeSys) |
Set method for internal variable timeSystem (enum). More... | |
TimeTag () | |
Default constructor. More... | |
TimeTag (const TimeSystem &ts) | |
Constructor. More... | |
virtual | ~TimeTag () |
Virtual Destructor. More... | |
JulianDate Comparison Operators | |
All comparison operators have a parameter "right" which corresponds to the JulianDate object to the right of the symbol. All comparison operators are const and return true on success and false on failure. | |
long double | jd |
bool | operator== (const JulianDate &right) const |
bool | operator!= (const JulianDate &right) const |
bool | operator< (const JulianDate &right) const |
bool | operator> (const JulianDate &right) const |
bool | operator<= (const JulianDate &right) const |
bool | operator>= (const JulianDate &right) const |
Additional Inherited Members | |
![]() | |
typedef std::map< char, std::string > | IdToValue |
![]() | |
static void | checkTimeSystem (TimeSystem ts1, TimeSystem ts2) |
static std::string | getError () |
This returns the default error string for the TimeTag classes. More... | |
static std::string | getFormatPrefixFloat () |
static std::string | getFormatPrefixInt () |
static void | getInfo (const std::string &str, const std::string &fmt, IdToValue &info) |
![]() | |
TimeSystem | timeSystem |
time system (representation) of the data More... | |
|
inline |
Default Constructor. All elements are initialized to zero.
Definition at line 100 of file JulianDate.hpp.
|
inline |
Copy Constructor.
right | a reference to the JulianDate object to copy |
Definition at line 108 of file JulianDate.hpp.
Alternate Copy Constructor. Takes a const TimeTag reference and copies its contents via conversion to CommonTime.
right | a const reference to the BasicTime object to copy |
InvalidRequest | on over-/under-flow |
Definition at line 119 of file JulianDate.hpp.
|
inline |
Alternate Copy Constructor. Takes a const CommonTime reference and copies its contents via the convertFromCommonTime method.
right | a const reference to the CommonTime object to copy |
InvalidRequest | on over-/under-flow |
Definition at line 131 of file JulianDate.hpp.
|
inlinevirtual |
Virtual Destructor.
Definition at line 144 of file JulianDate.hpp.
|
virtual |
InvalidRequest | if ct cannot be correctly represented in this TimeTag object. |
Implements gnsstk::TimeTag.
Definition at line 76 of file JulianDate.cpp.
|
virtual |
InvalidRequest | if this TimeTag cannot be correctly represented by a CommonTime object. |
Implements gnsstk::TimeTag.
Definition at line 54 of file JulianDate.cpp.
|
inlinevirtual |
Return a string containing the default format to use in printing.
Implements gnsstk::TimeTag.
Definition at line 177 of file JulianDate.hpp.
|
inlinevirtual |
Return a string containing the characters that this class understands when printing times.
Implements gnsstk::TimeTag.
Definition at line 171 of file JulianDate.hpp.
|
virtual |
Returns true if this object's members are valid, false otherwise.
Implements gnsstk::TimeTag.
Definition at line 151 of file JulianDate.cpp.
bool gnsstk::JulianDate::operator!= | ( | const JulianDate & | right | ) | const |
Definition at line 183 of file JulianDate.cpp.
bool gnsstk::JulianDate::operator< | ( | const JulianDate & | right | ) | const |
Any (wildcard) type exception allowed, otherwise must be same time systems
Definition at line 188 of file JulianDate.cpp.
bool gnsstk::JulianDate::operator<= | ( | const JulianDate & | right | ) | const |
Definition at line 211 of file JulianDate.cpp.
JulianDate & gnsstk::JulianDate::operator= | ( | const JulianDate & | right | ) |
Assignment Operator.
right | a const reference to the JulianDate to copy |
Definition at line 47 of file JulianDate.cpp.
bool gnsstk::JulianDate::operator== | ( | const JulianDate & | right | ) | const |
Any (wildcard) type exception allowed, otherwise must be same time systems
Definition at line 168 of file JulianDate.cpp.
bool gnsstk::JulianDate::operator> | ( | const JulianDate & | right | ) | const |
Definition at line 206 of file JulianDate.cpp.
bool gnsstk::JulianDate::operator>= | ( | const JulianDate & | right | ) | const |
Definition at line 217 of file JulianDate.cpp.
|
virtual |
This function works similarly to printf. Instead of filling the format with data, it fills with error messages.
Implements gnsstk::TimeTag.
Definition at line 107 of file JulianDate.cpp.
|
virtual |
This function formats this time to a string. The exceptions thrown would only be due to problems parsing the fmt string.
Implements gnsstk::TimeTag.
Definition at line 88 of file JulianDate.cpp.
|
virtual |
Reset this object to the default state.
Implements gnsstk::TimeTag.
Definition at line 162 of file JulianDate.cpp.
Set this object using the information provided in info.
info | the IdToValue object to which this object shall be set. |
Implements gnsstk::TimeTag.
Definition at line 126 of file JulianDate.cpp.
long double gnsstk::JulianDate::jd |
Definition at line 202 of file JulianDate.hpp.