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 
5 #include "MHO_Clock.hh"
6 
7 //this is the nominal DiFX MJD epoch start...however, it will be off by however
8 //many leap seconds have been inserted between this time and the time point of
9 //interest...so when UTC times are calculated from DiFX MJD values, this epoch
10 //start must be corrected by the number of leap seconds inserted (total of 5 as of 2025)
11 #define DIFX_J2000_MJD_EPOCH_UTC_ISO8601 "2000-01-01T12:00:00.000000000Z"
12 #define DIFX_J2000_MJD_EPOCH_OFFSET 51544.50000
13 
14 namespace hops
15 {
16 
17 //given a mjd date and number of seconds, compute the vex string representation
32 static std::string get_vexdate_from_mjd_sec(double mjd, double sec)
33 {
34  double total_mjd = (double)mjd + (double)sec / 86400.0;
36  //figure out the approximate time of this mjd (ignoring leap seconds)
37  auto approx_tp = hops_clock::from_mjd(difx_mjd_epoch, DIFX_J2000_MJD_EPOCH_OFFSET, total_mjd);
38  //calculate the number of leap seconds
39  auto n_leaps = hops_clock::get_leap_seconds_between(difx_mjd_epoch, approx_tp);
40  //now correct the nominal difx start epoch to deal with the number of leap seconds
41  auto actual_epoch_start = difx_mjd_epoch + n_leaps;
42  msg_debug("difx_interface", "the leap-second corrected difx mjd epoch start is: "
43  << hops_clock::to_iso8601_format(actual_epoch_start) << eom);
44  auto mjd_tp = hops_clock::from_mjd(actual_epoch_start, DIFX_J2000_MJD_EPOCH_OFFSET, total_mjd);
45  msg_debug("difx_interface",
46  "the MJD value: " << total_mjd << " as a vex timestamp is: " << hops_clock::to_vex_format(mjd_tp) << eom);
47  return hops_clock::to_vex_format(mjd_tp);
48 }
49 
50 }
51 
52 
53 #endif /* end of include guard: MHO_DiFXTimeUtilities_HH__ */
#define DIFX_J2000_MJD_EPOCH_OFFSET
Definition: MHO_DiFXTimeUtilities.hh:12
#define DIFX_J2000_MJD_EPOCH_UTC_ISO8601
Definition: MHO_DiFXTimeUtilities.hh:11
#define msg_debug(xKEY, xCONTENT)
Definition: MHO_Message.hh:297
static std::string to_iso8601_format(const time_point &tp)
Converts a time_point to ISO8601 formatted string.
Definition: MHO_Clock.hh:617
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:599
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:797
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:322
static time_point from_mjd(const time_point &mjd_epoch, const double &epoch_offset, const double &mjd)
Converts a Modified Julian date (floating point epoch and day) timestamp to a hops_clock time_point.
Definition: MHO_Clock.hh:765
Definition: MHO_ChannelLabeler.hh:17