#include <DayTime.hpp>
Collaboration diagram for DayTime:

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 setToString()).
Internally, the representation of day and time uses three quantities, (1) jday, an integer representation of Julian Date, specifically jday = int(JD+0.5) or jday=int(MJD+2400001). [Recall that JD = MJD + 2400000.5 and MJD is an integer when second-of-day==0. N.B. jday is NOT == JD or Julian Date, but DayTime::JD() does return JD.] (2) mSod, the integer part of milliseconds of the day, and (3) mSec, the (double) fractional part of milliseconds of the day.
In addition, the representation includes a tolerance value (see below) and a time frame. The time frame is a simple way of denoting the origin or type of day-time which is stored in the object. See TimeFrame for the list of possible values. The time frame of an object is determined in the call to a constructor (default is timeFrame=Unknown), and carried forward into other objects. It may be read or changed using member functions setAllButTimeFrame(), setTimeFrame(), and getTimeFrame().
The member datum 'double tolerance' is used in DayTime comparisons. It defaults to the value of the static gpstk::DayTime::DAYTIME_TOLERANCE, but this can be modified with the static method setDayTimeTolerance(). Several different default tolerances have been defined and are in the DayTime-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 (DayTime::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. The range of validity of the jday--calendar routines is approximately 4317 B.C. to 4317 A.D.; these limits are incorporated into constants DayTime::BEGINNING_OF_TIME and DayTime::END_OF_TIME.
* All DayTime objects that lie outside these limits are disallowed. *
This internal representation allows close to the maximum precision possible in the time-of-day. Although, note that the code uses FACTOR=1000 everywhere to compute milliseconds, via e.g. mSec=seconds/FACTOR, and thus FACTOR could be changed to give a different precision. (This has not been tested.)
This representation separates day and time-of-day cleanly. Because day and time are logically separated, it is possible to use DayTime for day only, or for time only. Thus, for example, one could instantiate a DayTime 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 DayTime sets the data, not to zero, but to the current (system) time; because there is no year 0, a DayTime object with all zero data is invalid!]
When constructing DayTime 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 DayTime. In general, DayTime 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.
Definition at line 152 of file DayTime.hpp.
Public Types | |
| enum | TimeFrame { Unknown, UTC, LocalSystem, GPS_Tx, GPS_Rx, GPS_SV, GPS_Receiver } |
| The various time frames. More... | |
Public Member Functions | |
| DayTime & | setTolerance (const double tol) throw () |
| Sets the tolerance for output and comparisons on this object only. | |
| double | getTolerance () throw () |
| Return the tolerance value currently in use by this object. | |
| DayTime () throw (DayTimeException) | |
| Default constructor. | |
| DayTime (short GPSWeek, double GPSSecond, TimeFrame f=Unknown) throw (DayTimeException) | |
| GPS time with full week constructor. | |
| DayTime (short GPSWeek, double GPSSecond, short year, TimeFrame f=Unknown) throw (DayTimeException) | |
| GPS time constructor. | |
| DayTime (short GPSWeek, long zcount, short year, TimeFrame f=Unknown) throw (DayTimeException) | |
| GPS time constructor. | |
| DayTime (unsigned long fullZcount, TimeFrame f=Unknown) throw (DayTimeException) | |
| GPS time constructor given the full Z count. | |
| DayTime (const GPSZcount &z, TimeFrame f=Unknown) throw (DayTimeException) | |
| GPS Zcount constructor. | |
| DayTime (const CommonTime &c, TimeFrame f=Unknown) throw (DayTimeException) | |
| CommonTime constructor. | |
| DayTime (short year, short month, short day, short hour, short minute, double second, TimeFrame f=Unknown) throw (DayTimeException) | |
| Calendar time constructor. | |
| DayTime (long double MJD, TimeFrame f=Unknown) throw (DayTimeException) | |
| Modified Julian date time constructor. | |
| DayTime (double MJD, TimeFrame f=Unknown) throw (DayTimeException) | |
| Modified Julian date time constructor. | |
| DayTime (short year, short doy, double sod, TimeFrame f=Unknown) throw (DayTimeException) | |
| Day of year time constructor. | |
| DayTime (const struct timeval &t, TimeFrame f=Unknown) throw (DayTimeException) | |
| UNIX time constructor. | |
| ~DayTime () throw () | |
| Destructor. | |
| DayTime (const DayTime &right) throw (DayTimeException) | |
| Copy constructor. | |
| DayTime & | operator= (const DayTime &right) throw () |
| Assignment operator. | |
| double | operator- (const DayTime &right) const throw () |
| DayTime difference function. | |
| DayTime | operator+ (double sec) const throw () |
| Add seconds to this time. | |
| DayTime | operator- (double sec) const throw () |
| Subtract seconds from this time. | |
| DayTime & | operator+= (double sec) throw (DayTimeException) |
| Add seconds to this time. | |
| DayTime & | operator-= (double sec) throw (DayTimeException) |
| Subtract seconds from this time. | |
| DayTime & | addSeconds (double seconds) throw (DayTimeException) |
| Add (double) seconds to this time. | |
| DayTime & | addSeconds (long seconds) throw (DayTimeException) |
| Add (integer) seconds to this time. | |
| DayTime & | addMilliSeconds (long msec) throw (DayTimeException) |
| Add (integer) milliseconds to this time. | |
| DayTime & | addMicroSeconds (long usec) throw (DayTimeException) |
| Add (integer) microseconds to this time. | |
| bool | operator== (const DayTime &right) const throw () |
| Equality operator. | |
| bool | operator!= (const DayTime &right) const throw () |
| Inequality operator. | |
| bool | operator< (const DayTime &right) const throw () |
| Comparison operator (less-than). | |
| bool | operator> (const DayTime &right) const throw () |
| Comparison operator (greater-than). | |
| bool | operator<= (const DayTime &right) const throw () |
| Comparison operator (less-than or equal-to). | |
| bool | operator>= (const DayTime &right) const throw () |
| Comparison operator (greater-than or equal-to). | |
| DayTime & | setAllButTimeFrame (const DayTime &right) throw (DayTimeException) |
| Change time frames via pseudo-copy method. | |
| DayTime & | setTimeFrame (TimeFrame f) throw () |
| Set the time frame for this time. | |
| TimeFrame | getTimeFrame () const throw () |
| Get the time frame for this time. | |
| double | JD () const throw () |
| Get Julian Date JD. | |
| double | MJD () const throw () |
| Get Modified Julian Date MJD. | |
| short | year () const throw () |
| Get year. | |
| short | month () const throw () |
| Get month of year. | |
| short | day () const throw () |
| Get day of month. | |
| short | dayOfWeek () const throw () |
| Get day of week. | |
| void | getYMD (int &yy, int &mm, int &dd) const throw () |
| Get year, month and day of month. | |
| short | hour () const throw () |
| Get hour of day. | |
| short | minute () const throw () |
| Get minutes of hour. | |
| double | second () const throw () |
| Get seconds of minute. | |
| double | secOfDay () const throw () |
| Get seconds of day. | |
| short | GPS10bitweek () const throw () |
| Get 10-bit GPS week. | |
| long | GPSzcount () const throw () |
| Get normal (19 bit) zcount. | |
| long | GPSzcountFloor () const throw () |
| Same as GPSzcount() but without rounding to nearest zcount. | |
| double | GPSsecond () const throw () |
| Get seconds of week. | |
| double | GPSsow () const throw () |
| Get GPS second of week. | |
| short | GPSday () const throw () |
| Get day of week. | |
| short | GPSfullweek () const throw () |
| Get full (>10 bits) week. | |
| short | GPSyear () const throw () |
| Get year. | |
| short | DOYyear () const throw () |
| Get year. | |
| short | DOYday () const throw () |
| Get day of year. | |
| short | DOY () const throw () |
| Get day of year. | |
| double | DOYsecond () const throw () |
| Get seconds of day. | |
| double | MJDdate () const throw () |
| Get object time as a modified Julian date. | |
| long double | getMJDasLongDouble () const throw () |
| Get object time as a (long double) modified Julian date. | |
| timeval | unixTime () const throw (DayTimeException) |
| Get object time in UNIX timeval structure. | |
| unsigned long | fullZcount () const throw () |
| Get time as 32 bit Z count. | |
| unsigned long | fullZcountFloor () const throw () |
| Same as fullZcount() but without rounding to nearest zcount. | |
| operator GPSZcount () const throw (DayTimeException) | |
| Convert this object to a GPSZcount object. | |
| operator CommonTime () const throw (DayTimeException) | |
| Convert this object to a CommonTime object. | |
| DayTime & | setYMDHMS (short year, short month, short day, short hour, short min, double sec, TimeFrame f=Unknown) throw (DayTimeException) |
| Set the object's time using calendar (Y/M/D) date and ordinary (H:M:S) time. | |
| DayTime & | setGPS (short week, double sow, TimeFrame f=Unknown) throw (DayTimeException) |
| Set the object's time using GPS time. | |
| DayTime & | setGPS (short week, long zcount, TimeFrame f=Unknown) throw (DayTimeException) |
| Set the object's time using GPS time (week and Z count). | |
| DayTime & | setGPS (short week, long zcount, short year, TimeFrame f=Unknown) throw (DayTimeException) |
| Set the object's time using GPS time. | |
| DayTime & | setGPS (short week, double sow, short year, TimeFrame f=Unknown) throw (DayTimeException) |
| Set the object's time using GPS time. | |
| DayTime & | setGPS (unsigned long Zcount, TimeFrame f=Unknown) throw (DayTimeException) |
| Set the object's time using GPS time (full Z count). | |
| DayTime & | setGPSfullweek (short fullweek, double sow, TimeFrame f=Unknown) throw (DayTimeException) |
| Set the object's time using GPS time. | |
| DayTime & | setGPSfullweek (short fullweek, long zcount, TimeFrame f=Unknown) throw (DayTimeException) |
| Set the object's time using GPS time. | |
| DayTime & | setGPSZcount (const GPSZcount &z, TimeFrame f=Unknown) throw (DayTimeException) |
| Set the object's time using the given GPSZcount. | |
| DayTime & | setCommonTime (const CommonTime &c, TimeFrame f=Unknown) throw () |
| Set the object's time using the give CommonTime. | |
| DayTime & | setYDoySod (short year, short day_of_year, double sec_of_day, TimeFrame f=Unknown) throw (DayTimeException) |
| Set the object's time using day of year. | |
| DayTime & | setMJD (long double mjd, TimeFrame f=Unknown) throw (DayTimeException) |
| Set the object's time using (long double) Modified Julian date. | |
| DayTime & | setMJDdate (long double mjd, TimeFrame f=Unknown) throw (DayTimeException) |
| Same as setMJD. | |
| DayTime & | setMJD (double mjd, TimeFrame f=Unknown) throw (DayTimeException) |
| Same as setMJD but with input of type double. | |
| DayTime & | setMJDdate (double mjd, TimeFrame f=Unknown) throw (DayTimeException) |
| Same as setMJD but with input of type double. | |
| DayTime & | setUnix (const struct timeval &t, TimeFrame f=Unknown) throw (DayTimeException) |
| Set the object's time using POSIX structures. | |
| DayTime & | setANSI (const time_t &t, TimeFrame f=Unknown) throw (DayTimeException) |
| Set the object's time using ANSI structures. | |
| DayTime & | setSystemTime () throw (DayTimeException) |
| Set the object's time to the current system time. | |
| DayTime & | setLocalTime () throw (DayTimeException) |
| Set the object time to the current local time. | |
| DayTime & | setYMD (int yy, int mm, int dd, TimeFrame f=Unknown) throw (DayTimeException) |
| Set the object using calendar (Y/M/D) date only (time is unchanged). | |
| DayTime & | setHMS (int hh, int mm, double sec, TimeFrame f=Unknown) throw (DayTimeException) |
| Set the object using ordinary (H:M:S) time only (day is unchanged). | |
| DayTime & | setSecOfDay (double sod, TimeFrame f=Unknown) throw (DayTimeException) |
| Set the object using seconds of day only (day is unchanged). | |
| DayTime & | setYDoy (int yy, int doy, TimeFrame f=Unknown) throw (DayTimeException) |
| Set the object using year and day of year only (time is unchanged). | |
| DayTime & | setToString (const std::string &str, const std::string &fmt) throw (DayTimeException, FormatException, gpstk::StringUtils::StringException) |
| Similar to scanf, this function takes a string and a format describing string in order to read in daytime values. | |
| std::string | printf (const char *fmt) const throw (gpstk::StringUtils::StringException) |
| Format this time into a string. | |
| std::string | printf (const std::string &fmt) const throw (gpstk::StringUtils::StringException) |
| Format this time into a string. printf(const char*). | |
| std::string | asString () const throw (gpstk::StringUtils::StringException) |
| Returns the string that operator<<() would print. | |
| void | dump (std::ostream &s) const throw (DayTimeException) |
| Dump everything possible, using every get() TD: keep? | |
Static Public Member Functions | |
| double | setDayTimeTolerance (const double tol) throw () |
| Changes the DAYTIME_TOLERANCE for all DayTime objects. | |
| double | getDayTimeTolerance () throw () |
| Returns the current DAYTIME_TOLERANCE. | |
| void | convertJDtoCalendar (long jd, int &iyear, int &imonth, int &iday) throw () |
| Fundamental routine to convert from "Julian day" (= JD + 0.5) to calendar day. | |
| long | convertCalendarToJD (int iyear, int imonth, int iday) throw () |
| Fundamental routine to convert from calendar day to "Julian day" (= JD + 0.5). | |
| void | convertSODtoTime (double sod, int &hh, int &mm, double &sec) throw () |
| Fundamental routine to convert seconds of day to H:M:S. | |
| double | convertTimeToSOD (int hh, int mm, double sec) throw () |
| Fundamental routine to convert H:M:S to seconds of day. | |
Static Public Attributes | |
DayTime-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. | |
| const long | FACTOR = 1000 |
| time-of-day is stored as long (seconds-of-day)*FACTOR plus double (remaining seconds)/FACTOR | |
| const double | JD_TO_MJD = 2400000.5 |
| Conversion offset, Julian Date to Modified Julian Date. | |
| const long | MJD_JDAY = 2400001L |
| 'Julian day' offset from MJD | |
| const long | GPS_EPOCH_JDAY = 2444245L |
| 'Julian day' of GPS epoch (Jan. 1, 1980). | |
| const long | GPS_EPOCH_MJD = 44244L |
| Modified Julian Date of GPS epoch (Jan. 1, 1980). | |
| const long | UNIX_MJD = 40587L |
| Modified Julian Date of UNIX epoch (Jan. 1, 1970). | |
| const long | HALFWEEK = 302400 |
| Seconds per half a GPS week. | |
| const long | FULLWEEK = 604800 |
| Seconds per whole GPS week. | |
| const long | SEC_DAY = 86400 |
| Seconds per day. | |
| const long | MS_PER_DAY = SEC_DAY*1000 |
| Milliseconds in a day. | |
| const double | ONE_NSEC_TOLERANCE = 1e-9 |
| One nanosecond tolerance. | |
| const double | ONE_USEC_TOLERANCE = 1e-6 |
| One microsecond tolerance. | |
| const double | ONE_MSEC_TOLERANCE = 1e-3 |
| One millisecond tolerance. | |
| const double | ONE_SEC_TOLERANCE = 1 |
| One second tolerance. | |
| const double | ONE_MIN_TOLERANCE = 60 |
| One minute tolerance. | |
| const double | ONE_HOUR_TOLERANCE = 3600 |
| One hour tolerance. | |
| double | DAYTIME_TOLERANCE = ONE_NSEC_TOLERANCE |
| Default tolerance for time equality in days. | |
| const long | BEGIN_LIMIT_JDAY = 0 |
| 'julian day' of earliest epoch expressible by DayTime: 1/1/4713 B.C. | |
| const long | END_LIMIT_JDAY = 3442448 |
| 'julian day' of latest epoch expressible by DayTime: 1/1/4713 A.D. | |
| const DayTime | BEGINNING_OF_TIME |
| earliest representable DayTime | |
| const DayTime | END_OF_TIME |
| latest representable DayTime | |
| bool | DAYTIME_TEST_VALID = true |
| If true, check the validity of inputs. | |
|
|
The various time frames.
Definition at line 179 of file DayTime.hpp. |
|
|
Default constructor. Initializes to current system time. Definition at line 166 of file DayTime.cpp. References DayTime::setSystemTime(). |
|
||||||||||||||||
|
GPS time with full week constructor.
Definition at line 177 of file DayTime.cpp. |
|
||||||||||||||||||||
|
GPS time constructor. In the case of 10-bit week input, the year and week are used to deduce the number of GPS week rollovers and thus the full GPS week.
Definition at line 191 of file DayTime.cpp. |
|
||||||||||||||||||||
|
GPS time constructor. In the case of 10-bit week input, the year and week are used to deduce the number of GPS week rollovers and thus the full GPS week.
Definition at line 206 of file DayTime.cpp. |
|
||||||||||||
|
GPS time constructor given the full Z count. The number of GPS week rollovers, and therefore the full GPS week, is determined from the current system time.
Definition at line 220 of file DayTime.cpp. |
|
||||||||||||
|
GPS Zcount constructor. The number of GPS week rollovers, and therefore the full GPS week, is determined from the current system time. Definition at line 231 of file DayTime.cpp. |
|
||||||||||||
|
CommonTime constructor.
Definition at line 242 of file DayTime.cpp. |
|
||||||||||||||||||||||||||||||||
|
Calendar time constructor.
Definition at line 258 of file DayTime.cpp. References gpstk::min(). |
|
||||||||||||
|
Modified Julian date time constructor. For some compilers, this result may have diminished accuracy.
Definition at line 274 of file DayTime.cpp. |
|
||||||||||||
|
Modified Julian date time constructor. For some compilers, this result may have diminished accuracy.
Definition at line 285 of file DayTime.cpp. |
|
||||||||||||||||||||
|
Day of year time constructor.
Definition at line 298 of file DayTime.cpp. |
|
||||||||||||
|
UNIX time constructor.
Definition at line 311 of file DayTime.cpp. |
|
|
Destructor.
Definition at line 428 of file DayTime.hpp. |
|
|
Copy constructor.
Definition at line 323 of file DayTime.cpp. |
|
|
Add (integer) microseconds to this time.
Definition at line 427 of file DayTime.cpp. |
|
|
Add (integer) milliseconds to this time.
Definition at line 414 of file DayTime.cpp. |
|
|
Add (integer) seconds to this time.
Definition at line 401 of file DayTime.cpp. |
|
|
Add (double) seconds to this time.
Definition at line 392 of file DayTime.cpp. Referenced by DayTime::operator+(), DayTime::operator-(), and testmeth(). |
|
|
Returns the string that operator<<() would print.
Definition at line 1611 of file DayTime.cpp. Referenced by SP3Data::dump(), and Rinex3ClockHeader::ParseHeaderRecord(). |
|
||||||||||||||||
|
Fundamental routine to convert from calendar day to "Julian day" (= JD + 0.5).
Definition at line 1729 of file DayTime.cpp. Referenced by DayTime::DOY(). |
|
||||||||||||||||||||
|
Fundamental routine to convert from "Julian day" (= JD + 0.5) to calendar day.
Definition at line 1680 of file DayTime.cpp. Referenced by DayTime::day(), DayTime::DOY(), DayTime::month(), and DayTime::year(). |
|
||||||||||||||||||||
|
Fundamental routine to convert seconds of day to H:M:S.
Definition at line 1775 of file DayTime.cpp. Referenced by DayTime::hour(), DayTime::minute(), and DayTime::second(). |
|
||||||||||||||||
|
Fundamental routine to convert H:M:S to seconds of day.
Definition at line 1801 of file DayTime.cpp. |
|
|
Get day of month.
Definition at line 532 of file DayTime.cpp. References DayTime::convertJDtoCalendar(). Referenced by DayTime::setToString(), and testRandomAccessors(). |
|
|
Get day of week.
Definition at line 541 of file DayTime.cpp. Referenced by EOPPrediction::getSerialNumber(). |
|
|
Get day of year.
Definition at line 613 of file DayTime.cpp. References DayTime::convertCalendarToJD(), and DayTime::convertJDtoCalendar(). Referenced by RTFileFrame::getRecord(), NeillTropModel::setAllParameters(), MOPSTropModel::setAllParameters(), NeillTropModel::setDayOfYear(), MOPSTropModel::setDayOfYear(), DayTime::setToString(), and testRandomAccessors(). |
|
|
Get day of year.
Definition at line 654 of file DayTime.hpp. Referenced by FICData::generateUniqueKey(), and ObsRngDev::ObsRngDev(). |
|
|
Get seconds of day.
Definition at line 663 of file DayTime.hpp. Referenced by DayTime::setToString(), and testRandomAccessors(). |
|
|
Get year.
Definition at line 649 of file DayTime.hpp. Referenced by FICData::generateUniqueKey(). |
|
|
Dump everything possible, using every get() TD: keep?
Definition at line 1620 of file DayTime.cpp. Referenced by GPSEphemerisStore::dump(), GalEphemerisStore::dump(), gpstk::operator<<(), and MinSfTest::process(). |
|
|
Get time as 32 bit Z count. The 13 MSBs are week modulo 1024, 19 LSBs are seconds of week in Zcounts. Definition at line 654 of file DayTime.cpp. References DayTime::GPS10bitweek(), and DayTime::GPSzcount(). |
|
|
Same as fullZcount() but without rounding to nearest zcount.
Definition at line 661 of file DayTime.cpp. References DayTime::GPS10bitweek(), and DayTime::GPSzcountFloor(). |
|
|
Returns the current DAYTIME_TOLERANCE.
Definition at line 263 of file DayTime.hpp. |
|
|
Get object time as a (long double) modified Julian date. For some compilers, this result may have diminished accuracy. Definition at line 622 of file DayTime.cpp. References DayTime::SEC_DAY, and DayTime::secOfDay(). |
|
|
Get the time frame for this time.
Definition at line 557 of file DayTime.hpp. References gpstk::convertJDtoCalendar(). |
|
|
Return the tolerance value currently in use by this object.
Definition at line 280 of file DayTime.hpp. |
|
||||||||||||||||
|
Get year, month and day of month.
Definition at line 592 of file DayTime.hpp. |
|
|
Get 10-bit GPS week.
Definition at line 578 of file DayTime.cpp. References DayTime::GPSfullweek(). Referenced by DayTime::fullZcount(), and DayTime::fullZcountFloor(). |
|
|
Get day of week.
Definition at line 635 of file DayTime.hpp. Referenced by FICData::generateUniqueKey(), and DayTime::GPSsow(). |
|
|
Get full (>10 bits) week.
Definition at line 606 of file DayTime.cpp. References DayTime::GPS_EPOCH_JDAY. Referenced by MDPSelftestStatus::encode(), MDPPVTSolution::encode(), MDPHeader::encode(), FICData9::FICData9(), FICData::generateUniqueKey(), EOPPrediction::getSerialNumber(), DayTime::GPS10bitweek(), gpstk::makeEngAlmanac(), gpstk::makeEngEphemeris(), gpstk::makeMDPObsEpoch(), DayTime::operator GPSZcount(), NovatelData::operator RinexNavData(), NovatelData::operator RinexObsData(), MinSfTest::process(), DayTime::setGPS(), and testRandomAccessors(). |