GammaLib
2.1.0.dev
|
Time class. More...
#include <GTime.hpp>
Public Member Functions | |
GTime (void) | |
Void constructor. More... | |
GTime (const GTime &time) | |
Copy constructor. More... | |
GTime (const double &time, const std::string &unit="sec") | |
Time constructor. More... | |
GTime (const double &time, const GTimeReference &ref) | |
Time constructor. More... | |
GTime (const std::string &time, const GTimeReference &ref) | |
Time constructor. More... | |
GTime (const std::string &time) | |
Time constructor. More... | |
virtual | ~GTime (void) |
Destructor. More... | |
GTime & | operator= (const GTime &time) |
Assignment operator. More... | |
GTime & | operator+= (const double &seconds) |
Add seconds to time. More... | |
GTime & | operator-= (const double &seconds) |
Subtract seconds from time. More... | |
void | clear (void) |
Clear time. More... | |
GTime * | clone (void) const |
Clone time. More... | |
std::string | classname (void) const |
Return class name. More... | |
double | jd (void) const |
Return time in Julian Days (TT) More... | |
double | jd (const std::string ×ys) const |
Return time in Julian Days for time system. More... | |
double | mjd (void) const |
Return time in Modified Julian Days (TT) More... | |
double | mjd (const std::string ×ys) const |
Return time in Modified Julian Days for time system. More... | |
const double & | secs (void) const |
Return time in seconds in native reference (TT) More... | |
double | secs (const std::string ×ys) const |
Return time in seconds in native reference for time system. More... | |
double | days (void) const |
Return time in days in native reference (TT) More... | |
double | days (const std::string ×ys) const |
Return time in days in native reference for time system. More... | |
double | julian_epoch (void) const |
Return Julian epoch in native reference (TT) More... | |
double | julian_epoch (const std::string ×ys) const |
Return Julian epoch in native reference for time system. More... | |
std::string | utc (const int &precision=0) const |
Return time as string in UTC time system. More... | |
double | gmst (void) const |
Return Greenwich mean sidereal time in hours in a day. More... | |
double | gast (void) const |
Return Greenwich apparent sidereal time in hours in a day. More... | |
double | lmst (const double &geolon) const |
Return local mean sidereal time in hours in a day. More... | |
double | last (const double &geolon) const |
Return local apparent sidereal time in hours in a day. More... | |
double | leap_seconds (void) const |
Return number of leap seconds for current time. More... | |
double | utc2tt (void) const |
Return time difference between UTC and TT (seconds) More... | |
double | convert (const GTimeReference &ref) const |
Return time in specified reference. More... | |
void | jd (const double &time) |
Set time in Julian Days in native reference (TT) More... | |
void | jd (const double &time, const std::string ×ys) |
Set time in Julian Days in native reference for time system. More... | |
void | mjd (const double &time) |
Set time in Modified Julian Days in native reference (TT) More... | |
void | mjd (const double &time, const std::string ×ys) |
Set time in Modified Julian Days in native reference for time system. More... | |
void | secs (const double &seconds) |
Set time in seconds in native reference (TT) More... | |
void | secs (const double &seconds, const std::string ×ys) |
Set time in seconds in native reference for time system. More... | |
void | days (const double &days) |
Set time in days in native reference (TT) More... | |
void | days (const double &days, const std::string ×ys) |
Set time in days in native reference for time system. More... | |
void | utc (const std::string &time) |
Set time as string in UTC time system. More... | |
void | set (const double &time, const GTimeReference &ref) |
Set time given in specified reference. More... | |
void | set (const std::string &time, const GTimeReference &ref) |
Set time from string. More... | |
void | set (const std::string &time) |
Set time for string for native time reference system. More... | |
void | now (void) |
Set time to current time. More... | |
GTimeReference | reference (void) const |
Returns native time reference. More... | |
std::string | print (const GChatter &chatter=NORMAL) const |
Print time. More... | |
Public Member Functions inherited from GBase | |
virtual | ~GBase (void) |
Destructor. More... | |
Protected Member Functions | |
void | init_members (void) |
Initialise class members. More... | |
void | copy_members (const GTime &time) |
Copy class members. More... | |
void | free_members (void) |
Delete class members. More... | |
double | leap_seconds (const double &mjd) const |
Returns number of leap seconds for a given MJD. More... | |
bool | is_leap_year (const int &year) const |
Signals if year is a leap year. More... | |
int | days_in_year (const int &year) const |
Returns number of days in year. More... | |
double | extract_timeval (const std::string &time) const |
Extract time value from time string. More... | |
std::string | extract_timesys (const std::string &time) const |
Extract time system from time string. More... | |
Protected Attributes | |
double | m_time |
Time in seconds in native reference (TT) More... | |
Friends | |
GTime | operator+ (const GTime &time, const double &seconds) |
Add seconds to time. More... | |
GTime | operator+ (const double &seconds, const GTime &time) |
Add seconds to time. More... | |
GTime | operator- (const GTime &time, const double &seconds) |
Subtract seconds from time. More... | |
double | operator- (const GTime &a, const GTime &b) |
Subtract times. More... | |
bool | operator== (const GTime &a, const GTime &b) |
Check if times are equal. More... | |
bool | operator!= (const GTime &a, const GTime &b) |
Check if times are not equal. More... | |
bool | operator< (const GTime &a, const GTime &b) |
Check if time is smaller than other time. More... | |
bool | operator<= (const GTime &a, const GTime &b) |
Check if time is smaller than or equal to other time. More... | |
bool | operator> (const GTime &a, const GTime &b) |
Check if time is larger than other time. More... | |
bool | operator>= (const GTime &a, const GTime &b) |
Check if time is larger than or equal to other time. More... | |
Time class.
The GTime class stores a time value in seconds in a GammaLib native time reference system. The GammaLib native time reference (i.e. time=0) is defined as
January 1, 2010, 00:00:00 (TT)
The time system is Terrestrial Time (TT). With respect to Coordinated Universal Time (UTC), TT time is greater than UTC time by 66.184 sec at January 1, 2010, 00:00:00. The difference is due to the introduction of leap seconds that synchronize TT with the Earth rotation (UTC).
GTime::GTime | ( | void | ) |
Void constructor.
Definition at line 67 of file GTime.cpp.
References init_members().
Referenced by clone().
GTime::GTime | ( | const GTime & | time | ) |
Copy constructor.
[in] | time | Time. |
Definition at line 82 of file GTime.cpp.
References copy_members(), and init_members().
GTime::GTime | ( | const double & | time, |
const std::string & | unit = "sec" |
||
) |
Time constructor.
[in] | time | Time value in TT (seconds or days). |
[in] | unit | Time unit string. |
GException::invalid_argument | Invalid time unit specified. |
Constructs a GTime object by setting the time in the native reference in the TT time system in units of seconds (default) or days.
Definition at line 107 of file GTime.cpp.
References days(), G_CONSTRUCT, init_members(), secs(), and gammalib::tolower().
GTime::GTime | ( | const double & | time, |
const GTimeReference & | ref | ||
) |
Time constructor.
[in] | time | Time in given reference system. |
[in] | ref | Reference system. |
Constructs a GTime object by setting the time to a value given in a specific reference system.
Definition at line 141 of file GTime.cpp.
References init_members(), and set().
GTime::GTime | ( | const std::string & | time, |
const GTimeReference & | ref | ||
) |
Time constructor.
[in] | time | Time string in given reference system. |
[in] | ref | Reference system. |
Constructs a GTime object by setting the time to a string value. See the set(std::string&, GTimeReference&) method for valid time strings.
Definition at line 163 of file GTime.cpp.
References init_members(), and set().
|
explicit |
Time constructor.
[in] | time | Time string. |
Constructs a GTime object by setting the time to a string value. See the set(const std::string& time) method for valid time strings.
Definition at line 184 of file GTime.cpp.
References init_members(), and set().
|
virtual |
|
inlinevirtual |
|
virtual |
Clear time.
Implements GBase.
Definition at line 252 of file GTime.cpp.
References free_members(), and init_members().
Referenced by GSPIEventCube::alloc_data(), GLATEventAtom::init_members(), GPhoton::init_members(), GCOMBvc::init_members(), GSource::init_members(), GMWLDatum::init_members(), GCTAEventAtom::init_members(), GEphemerides::init_members(), GCOMEventCube::init_members(), GPulsarEphemeris::init_members(), GCOMEventBin::init_members(), GCOMOad::init_members(), GModelTemporalLightCurve::init_members(), GCOMEventAtom::init_members(), GCTAEventBin::init_members(), GSPIEventBin::init_members(), GLATEventCube::init_members(), GCTAEventCube::init_members(), GGti::init_members(), GCOMDri::init_statistics(), and GGti::set_attributes().
|
virtual |
double GTime::convert | ( | const GTimeReference & | ref | ) | const |
Return time in specified reference.
Convert the time from the native reference system into the specified reference system.
Definition at line 698 of file GTime.cpp.
References leap_seconds(), m_time, mjd(), mjd_ref, GTimeReference::mjdref(), gammalib::sec2day, gammalib::sec_in_day, gammalib::tai2tt, GTimeReference::timesys(), gammalib::toupper(), and GTimeReference::unitseconds().
Referenced by GModelTemporalLightCurve::eval(), GGti::extend(), GModelTemporalLightCurve::print(), GGti::write(), GCTACubeExposure::write_attributes(), and GCTAObservation::write_attributes().
|
protected |
Copy class members.
[in] | time | Time. |
Definition at line 1230 of file GTime.cpp.
References m_time.
Referenced by GTime(), and operator=().
double GTime::days | ( | void | ) | const |
Return time in days in native reference (TT)
Definition at line 400 of file GTime.cpp.
References m_time, and gammalib::sec2day.
Referenced by days_in_year(), gast(), gmst(), GTime(), and utc().
double GTime::days | ( | const std::string & | timesys | ) | const |
Return time in days in native reference for time system.
[in] | timesys | Time system (one of "TT", "TAI", "UTC") |
Definition at line 413 of file GTime.cpp.
References gammalib::sec2day, and secs().
void GTime::days | ( | const double & | days | ) |
Set time in days in native reference (TT)
[in] | days | Time (TT) (days). |
Definition at line 857 of file GTime.cpp.
References m_time, and gammalib::sec_in_day.
void GTime::days | ( | const double & | days, |
const std::string & | timesys | ||
) |
Set time in days in native reference for time system.
[in] | days | Time (TT) (days). |
[in] | timesys | Time system (one of "TT", "TAI", "UTC") |
Definition at line 873 of file GTime.cpp.
References gammalib::sec_in_day, and secs().
|
inlineprotected |
Returns number of days in year.
[in] | year | Year (four digits integer). |
Definition at line 225 of file GTime.hpp.
References days(), and is_leap_year().
Referenced by utc().
|
protected |
Extract time system from time string.
[in] | time | Time string. |
Extracts the time system from a time string. Valid time systems are:
"(TT)" (TT system) "(UTC)" (UTC system) "(TAI)" (TAI system)
If no time system is found a blank string is returned.
Definition at line 1371 of file GTime.cpp.
References gammalib::str(), gammalib::strip_whitespace(), and gammalib::toupper().
Referenced by set().
|
protected |
Extract time value from time string.
[in] | time | Time string. |
Extracts the time value from a time string. The method strips any prefix such as "MJD" or "JD" and any suffix starting with a left parentheses "(" and converts the remainder into a double precision value.
Definition at line 1329 of file GTime.cpp.
References gammalib::todouble().
Referenced by set().
|
protected |
Delete class members.
Definition at line 1243 of file GTime.cpp.
Referenced by clear(), operator=(), and ~GTime().
double GTime::gast | ( | void | ) | const |
Return Greenwich apparent sidereal time in hours in a day.
See http://aa.usno.navy.mil/faq/docs/GAST.php
Definition at line 616 of file GTime.cpp.
References cos(), days(), gammalib::deg2rad, gmst(), and sin().
Referenced by last().
double GTime::gmst | ( | void | ) | const |
|
protected |
|
inlineprotected |
Signals if year is a leap year.
[in] | year | Year (four digits integer). |
Definition at line 210 of file GTime.hpp.
Referenced by days_in_year(), and utc().
double GTime::jd | ( | void | ) | const |
Return time in Julian Days (TT)
Returns the time in Julian Days (JD) in the Terrestrial Time (TT) system.
Definition at line 284 of file GTime.cpp.
References jd_ref, m_time, and gammalib::sec2day.
Referenced by GEphemerides::ephemeris(), jd(), julian_epoch(), GEphemerides::load(), GSkyDir::moon(), set(), and GSkyDir::sun().
double GTime::jd | ( | const std::string & | timesys | ) | const |
Return time in Julian Days for time system.
[in] | timesys | Time system (one of "TT", "TAI", "UTC") |
Returns the time in Julian Days (JD) for the specified time system.
Definition at line 302 of file GTime.cpp.
References jd(), jd_ref, gammalib::sec2day, and secs().
void GTime::jd | ( | const double & | time | ) |
Set time in Julian Days in native reference (TT)
[in] | time | Time in Julian Days (TT) (days). |
Definition at line 750 of file GTime.cpp.
References jd_ref, m_time, and gammalib::sec_in_day.
void GTime::jd | ( | const double & | time, |
const std::string & | timesys | ||
) |
Set time in Julian Days in native reference for time system.
[in] | time | Time in Julian Days (days). |
[in] | timesys | Time system (one of "TT", "TAI", "UTC") |
Definition at line 766 of file GTime.cpp.
References jd_ref, gammalib::sec_in_day, and secs().
double GTime::julian_epoch | ( | void | ) | const |
Return Julian epoch in native reference (TT)
Definition at line 425 of file GTime.cpp.
References jd().
Referenced by julian_epoch(), GSkyDir::moon(), and GSkyDir::sun().
double GTime::julian_epoch | ( | const std::string & | timesys | ) | const |
Return Julian epoch in native reference for time system.
[in] | timesys | Time system (one of "TT", "TAI", "UTC") |
Definition at line 441 of file GTime.cpp.
References jd(), and julian_epoch().
double GTime::last | ( | const double & | geolon | ) | const |
Return local apparent sidereal time in hours in a day.
[in] | geolon | Geographic longitude West of Greenwich (degrees). |
See http://aa.usno.navy.mil/faq/docs/GAST.php
Definition at line 677 of file GTime.cpp.
References gast().
|
inline |
|
protected |
Returns number of leap seconds for a given MJD.
[in] | mjd | Modified Julian Day in UTC time system. |
Return the number of leap seconds for a given MJD specified in the UTC time system. This method returns valid number of leap seconds for the years 1972-2017.
See http://www.nist.gov/pml/div688/grp50/leapsecond.cfm for a table of leap seconds.
double GTime::lmst | ( | const double & | geolon | ) | const |
Return local mean sidereal time in hours in a day.
[in] | geolon | Geographic longitude West of Greenwich (degrees). |
See http://aa.usno.navy.mil/faq/docs/GAST.php
Definition at line 656 of file GTime.cpp.
References gmst().
double GTime::mjd | ( | void | ) | const |
Return time in Modified Julian Days (TT)
Returns the time in Modified Julian Days (MJD) in the Terrestrial Time (TT) system.
Definition at line 320 of file GTime.cpp.
References m_time, mjd_ref, and gammalib::sec2day.
Referenced by gammalib::com_tics(), gammalib::com_time(), gammalib::com_tjd(), convert(), GPulsar::ephemeris(), leap_seconds(), GPulsar::load_fermi(), GPulsar::load_integral(), GPulsar::load_parfile(), GPulsar::load_psrtime(), mjd(), GModelTemporalPhaseCurve::mjd(), GCOMOad::print(), GCOMBvc::print(), GEphemerides::print(), GCOMTim::print(), GPulsar::print(), GCOMHkd::print(), secs(), set(), gammalib::spi_ijd2time(), and utc().
double GTime::mjd | ( | const std::string & | timesys | ) | const |
Return time in Modified Julian Days for time system.
[in] | timesys | Time system (one of "TT", "TAI", "UTC") |
Returns the time in Modified Julian Days (JD) for the specified time system.
Definition at line 339 of file GTime.cpp.
References mjd(), mjd_ref, gammalib::sec2day, and secs().
void GTime::mjd | ( | const double & | time | ) |
Set time in Modified Julian Days in native reference (TT)
[in] | time | Time in Modified Julian Days (TT) (days). |
Definition at line 784 of file GTime.cpp.
References m_time, mjd_ref, and gammalib::sec_in_day.
void GTime::mjd | ( | const double & | time, |
const std::string & | timesys | ||
) |
Set time in Modified Julian Days in native reference for time system.
[in] | time | Time in Modified Julian Days (days). |
[in] | timesys | Time system (one of "TT", "TAI", "UTC") |
Definition at line 801 of file GTime.cpp.
References mjd_ref, gammalib::sec_in_day, and secs().
void GTime::now | ( | void | ) |
Set time to current time.
Sets time to current time.
Definition at line 1126 of file GTime.cpp.
References utc().
Referenced by GDaemon::alive(), GDaemon::create_xml(), GDaemon::recover_valid_xml(), GDaemon::update_dates(), and GDaemon::write_heartbeat().
|
inline |
|
inline |
Assignment operator.
[in] | time | Time. |
Definition at line 222 of file GTime.cpp.
References copy_members(), free_members(), and init_members().
Print time.
[in] | chatter | Chattiness. |
Prints time in seconds in the native reference.
Implements GBase.
Definition at line 1188 of file GTime.cpp.
References m_time, SILENT, and gammalib::str().
Referenced by GModelSpatialRadialGauss::eval(), GModelSpatialRadialGeneralGauss::eval(), GModelSpectralPlaw::eval(), GGti::insert_gti(), GModelSpectralExpPlaw::mc(), GModelSpectralSuperExpPlaw::mc(), GModelSpectralExpInvPlaw::mc(), GCOMEventAtom::print(), GLATEventAtom::print(), GCTAEventAtom::print(), GPhoton::print(), GSource::print(), GCOMEventCube::print(), and GGti::reduce().
GTimeReference GTime::reference | ( | void | ) | const |
Returns native time reference.
Returns the native GammaLib time reference. The GammaLib native time reference (i.e. time=0) is defined as January 1, 2010, 00:00:00 (TT). The time system is Terrestrial Time (TT). Time is stored in seconds.
Definition at line 1170 of file GTime.cpp.
References mjd_ref.
Referenced by GGti::init_members(), set(), and GApplicationPar::time().
|
inline |
Return time in seconds in native reference (TT)
Definition at line 156 of file GTime.hpp.
References m_time.
Referenced by GCOMDris::compute_drws_energy(), GCOMDris::compute_drws_phibar(), days(), GObservation::npred_kern::eval(), GTime(), jd(), GModelTemporalConst::mc(), GModelTemporalPhaseCurve::mc(), mjd(), GPulsarEphemeris::phase(), GGti::set_attributes(), GCOMDris::vetorate_setup(), and GCOMDri::write_attributes().
double GTime::secs | ( | const std::string & | timesys | ) | const |
Return time in seconds in native reference for time system.
[in] | timesys | Time system (one of "TT", "TAI", "UTC") |
Definition at line 355 of file GTime.cpp.
References G_SECS_GET, leap_seconds(), m_time, mjd(), mjd_ref, gammalib::sec2day, and gammalib::tai2tt.
|
inline |
void GTime::secs | ( | const double & | seconds, |
const std::string & | timesys | ||
) |
Set time in seconds in native reference for time system.
[in] | seconds | Time in native reference (seconds). |
[in] | timesys | Time system (one of "TT", "TAI", "UTC") |
Definition at line 820 of file GTime.cpp.
References G_SECS_SET, leap_seconds(), m_time, mjd(), mjd_ref, gammalib::sec2day, and gammalib::tai2tt.
void GTime::set | ( | const double & | time, |
const GTimeReference & | ref | ||
) |
Set time given in specified reference.
[in] | time | Time in given reference system. |
[in] | ref | Reference system. |
Set the time to a value given in a specific reference system.
Definition at line 1005 of file GTime.cpp.
References leap_seconds(), m_time, mjd(), mjd_ref, GTimeReference::mjdref(), gammalib::sec_in_day, gammalib::tai2tt, GTimeReference::timesys(), gammalib::toupper(), and GTimeReference::unitseconds().
Referenced by GGti::extend(), GTime(), GModelTemporalLightCurve::load_nodes(), GGti::read(), GLATEventList::read_events(), and set().
void GTime::set | ( | const std::string & | time, |
const GTimeReference & | ref | ||
) |
Set time from string.
[in] | time | Time string. |
[in] | ref | Reference system. |
Sets the time from a string for a given reference system. The following strings are valid:
"2016-10-05T15:08:56" (UTC string) "1800.0" (MET seconds in specified reference system) "1800.0 (TT)" (MET seconds in specified reference, TT system) "1800.0 (UTC)" (MET seconds in specified reference, UTC time system) "1800.0 (TAI)" (MET seconds in specified reference, TAI time system) "MJD 54609" (Modified Julian Days, TT system) "MJD 54609 (TT)" (Modified Julian Days, TT system) "MJD 54609 (UTC)" (Modified Julian Days, UTC system) "MJD 54609 (TAI)" (Modified Julian Days, TAI system) "JD 54609" (Julian Days, TT system) "JD 54609 (TT)" (Julian Days, TT system) "JD 54609 (UTC)" (Julian Days, UTC system) "JD 54609 (TAI)" (Julian Days, TAI system)
If any other string is encountered, the numerical value is interpreted as time is seconds using the TT system.
Note that the TT, UTC or TAI attributes overwrite the values contained in the specified reference system. The reference system is only used to convert MET times in seconds.
Definition at line 1065 of file GTime.cpp.
References extract_timesys(), extract_timeval(), jd(), mjd(), GTimeReference::mjdref(), set(), gammalib::str(), gammalib::strip_whitespace(), GTimeReference::timeref(), GTimeReference::timesys(), GTimeReference::timeunit(), gammalib::toupper(), and utc().
|
inline |
Set time for string for native time reference system.
[in] | time | Time string. |
Definition at line 424 of file GTime.hpp.
References reference(), and set().
std::string GTime::utc | ( | const int & | precision = 0 | ) | const |
Return time as string in UTC time system.
[in] | precision | Digits of precision to show in the seconds field |
Returns time in the format YYYY-MM-DDThh:mm:ss(.ss...), where YYYY is a four-digit year, MM a two-digit month, DD a two-digit day of month, hh two digits of hour (0 through 23), mm two digits of minutes, and ss(.ss...) two digits of second (ISO 8601 time standard). In case that precision
> 0 digits in the second after the comma will be returned.
The method is only valid for dates from year 1972 on.
Definition at line 465 of file GTime.cpp.
References days(), days_in_year(), G_UTC_GET, is_leap_year(), leap_seconds(), mjd(), gammalib::sec2day, gammalib::sec_in_day, gammalib::str(), and gammalib::tai2tt.
Referenced by GDaemon::alive(), GDaemon::create_xml(), now(), GCOMOad::print(), GCOMBvc::print(), GEphemerides::print(), GCOMTim::print(), GPulsar::print(), GCOMHkd::print(), GDaemon::recover_valid_xml(), set(), GApplicationPar::time(), GDaemon::update_dates(), GCTACubeExposure::write_attributes(), GCOMDri::write_attributes(), GCTAObservation::write_attributes(), and GDaemon::write_heartbeat().
void GTime::utc | ( | const std::string & | time | ) |
Set time as string in UTC time system.
[in] | time | Time string (UTC). |
GException::invalid_argument | Invalid time string specified. |
The time has to be given in the format YYYY-MM-DDThh:mm:ss.s, where YYYY is a four-digit year, MM a two-digit month, DD a two-digit day of month, hh two digits of hour (0 through 23), mm two digits of minutes, ss two digits of second and s one or more digits representing a decimal fraction of a second (ISO 8601 time standard).
The method is only valid for dates from year 1972 on.
Definition at line 902 of file GTime.cpp.
References G_UTC, is_leap_year(), leap_seconds(), mjd(), gammalib::sec2day, gammalib::str(), and gammalib::tai2tt.
|
inline |
Return time difference between UTC and TT (seconds)
Returns the time difference between UTC and TT. The time difference is a positive number and is given by the sum of 32.184 s and the number of leap seconds.
Definition at line 197 of file GTime.hpp.
References leap_seconds(), and gammalib::tai2tt.
Referenced by GPulsar::load_psrtime().
|
protected |
Time in seconds in native reference (TT)
Definition at line 134 of file GTime.hpp.
Referenced by convert(), copy_members(), days(), init_members(), jd(), mjd(), operator!=(), operator+(), operator+=(), operator-(), operator-=(), operator<(), operator<=(), operator==(), operator>(), operator>=(), print(), secs(), and set().