HOPS
HOPS class reference
MHO_DiFXTimeUtilities.hh
Go to the documentation of this file.
1 #ifndef MHO_DiFXTimeUtilities_HH__
2 #define MHO_DiFXTimeUtilities_HH__
3 
4 #include "MHO_Clock.hh"
5 
6 //this is the nominal DiFX MJD epoch start...however, it will be off by however
7 //many leap seconds have been inserted between this time and the time point of
8 //interest...so when UTC times are calculated from DiFX MJD values, this epoch
9 //start must be corrected by the number of leap seconds inserted (total of 5 as of 2025)
10 #define DIFX_J2000_MJD_EPOCH_UTC_ISO8601 "2000-01-01T12:00:00.000000000Z"
11 #define DIFX_J2000_MJD_EPOCH_OFFSET 51544.50000
12 
13 namespace hops
14 {
15 
16 //given a mjd date and number of seconds, compute the vex string representation
31 static std::string get_vexdate_from_mjd_sec(double mjd, double sec)
32 {
33  double total_mjd = (double)mjd + (double)sec / 86400.0;
35  //figure out the approximate time of this mjd (ignoring leap seconds)
36  auto approx_tp = hops_clock::from_mjd(difx_mjd_epoch, DIFX_J2000_MJD_EPOCH_OFFSET, total_mjd);
37  //calculate the number of leap seconds
38  auto n_leaps = hops_clock::get_leap_seconds_between(difx_mjd_epoch, approx_tp);
39  //now correct the nominal difx start epoch to deal with the number of leap seconds
40  auto actual_epoch_start = difx_mjd_epoch + n_leaps;
41  msg_debug("difx_interface", "the leap-second corrected difx mjd epoch start is: "
42  << hops_clock::to_iso8601_format(actual_epoch_start) << eom);
43  auto mjd_tp = hops_clock::from_mjd(actual_epoch_start, DIFX_J2000_MJD_EPOCH_OFFSET, total_mjd);
44  msg_debug("difx_interface",
45  "the MJD value: " << total_mjd << " as a vex timestamp is: " << hops_clock::to_vex_format(mjd_tp) << eom);
46  return hops_clock::to_vex_format(mjd_tp);
47 }
48 
49 } // namespace hops
50 
51 #endif /* end of include guard: MHO_DiFXTimeUtilities_HH__ */
#define DIFX_J2000_MJD_EPOCH_OFFSET
Definition: MHO_DiFXTimeUtilities.hh:11
#define DIFX_J2000_MJD_EPOCH_UTC_ISO8601
Definition: MHO_DiFXTimeUtilities.hh:10
#define msg_debug(xKEY, xCONTENT)
Definition: MHO_Message.hh:291
static std::string to_iso8601_format(const time_point &tp)
Converts a time_point to ISO8601 formatted string.
Definition: MHO_Clock.hh:614
static time_point from_iso8601_format(const std::string &timestamp)
Converts an ISO8601 formatted timestamp string to a hops_clock time_point object.
Definition: MHO_Clock.hh:596
static std::string to_vex_format(const time_point &tp, bool truncate_to_nearest_second=false)
Converts a hops_clock time_point to VEX-style formatted string (e.g. 2019y106d18h30m15s)
Definition: MHO_Clock.hh:792
static std::chrono::seconds get_leap_seconds_between(const time_point &t_start, const time_point &t_end)
calculates the number of leap seconds inserted between two hops time points (UTC based clock)
Definition: MHO_Clock.hh:320
static time_point from_mjd(const time_point &mjd_epoch, double epoch_offset, double mjd)
Converts a Modified Julian date (floating point epoch and day) timestamp to a hops_clock time_point.
Definition: MHO_Clock.hh:760
Definition: MHO_AdhocFlagging.hh:18