41 #include "../ioutils/stringUtils.hpp"
42 #include "../astro/sofa.hpp"
62 template<
typename typeT=
double, clock
id_t clk_
id=CLOCK_REALTIME>
65 clock_gettime(clk_id, &tsp);
67 return ((typeT)tsp.tv_sec) + ((typeT)tsp.tv_nsec)/1e9;
72 double get_curr_time<double, CLOCK_REALTIME>(timespec & tsp);
90 template<
typename typeT=
double, clock
id_t clk_
id=CLOCK_REALTIME>
94 return get_curr_time<typeT, clk_id>(tsp);
99 double get_curr_time<double, CLOCK_REALTIME>();
108 void sleep(
unsigned sec );
154 template<
typename floatT>
158 const std::string & hmsstr
166 en = hmsstr.find(
':', st);
168 h = ioutils::convertFromString<floatT>(hmsstr.substr(st, en-st).c_str());
171 if(std::signbit(
h)) sgn = -1;
175 en = hmsstr.find(
':', st);
177 m = sgn*ioutils::convertFromString<floatT>(hmsstr.substr(st, en-st));
181 s = sgn*ioutils::convertFromString<floatT>(hmsstr.substr(st, hmsstr.length()-st).c_str());
220 const std::string & fdate
244 template<
typename timeT>
331 const timespec & tsp,
426 template<
typename arithT>
431 ts.tv_sec += floor(add);
433 ts.tv_nsec += (add - floor(add))*1e9;
435 if(ts.tv_nsec >= 1e9)
448 template<
typename arithT>
453 ts.tv_sec -= floor(sub);
455 ts.tv_nsec -= (sub - floor(sub))*1e9;
constexpr units::realT h()
Planck Constant.
constexpr units::realT day()
Length of day.
void nanoSleep(unsigned nsec)
Sleep for a specified period in nanoseconds.
void sleep(unsigned sec)
Sleep for a specified period in seconds.
void milliSleep(unsigned msec)
Sleep for a specified period in milliseconds.
void microSleep(unsigned usec)
Sleep for a specified period in microseconds.
bool operator<(timespec const &tsL, timespec const &tsR)
Timespec comparison operator < (see caveats)
bool operator==(timespec const &tsL, timespec const &tsR)
Timespec comparison operator == (see caveats)
bool operator>(timespec const &tsL, timespec const &tsR)
Timespec comparison operator > (see caveats)
bool operator>=(timespec const &tsL, timespec const &tsR)
Timespec comparison operator >= (see caveats)
bool operator<=(timespec const &tsL, timespec const &tsR)
Timespec comparison operator <= (see caveats)
int ISO8601dateBreakdown(int &yr, int &mon, int &day, int &hr, int &min, double &sec, const std::string &fdate)
Parse an ISO8601 date of the form "YYYY-MM-DDTHH:MM:SS.S" into the individual components.
std::string ISO8601DateTimeStr(int timeZone=0)
Get a date-time string in ISO 8601 format for the current UTC time.
std::string ISO8601DateTimeStrMJD(const double &timeIn, int timeZone=0)
Get a date-time string in ISO 8601 format for an MJD.
int timespecUTC2TAIMJD(double &djm, double &djmf, const timespec &tsp, tm *tm0)
Convert a UTC timespec to TAI modified Julian date.
std::string ISO8601DateTimeStr< timespec >(const timespec &timeIn, int timeZone)
Get a date-time string in ISO 8601 format for timespec.
void timespecAddNsec(timespec &ts, unsigned nsec)
Adds a time offset to an existing timespec.
void parse_hms(floatT &h, floatT &m, floatT &s, const std::string &hmsstr)
typeT get_curr_time()
Get the current system time in seconds.
int timeStamp(std::string &tstamp, timespec &ts)
Get a timestamp string in the form YYYYMMDDHHMMSS.SSSSSSSSS.
double Cal2mjd(int yr, int mon, int day, int hr, int min, double sec)
Converts a Gregorian calendar date into modified Julian date (MJD).
double ISO8601date2mjd(const std::string &fdate)
Parse an ISO8601 date of the form "YYYY-MM-DDTHH:MM:SS.S" and return the modified Julian date (MJD)
std::string ISO8601DateTimeStr< time_t >(const time_t &timeIn, int timeZone)
Get a date-time string in ISO 8601 format for time_t.
timespec operator-(timespec ts, arithT sub)
Subtract an amount of time specified in seconds from a timespec.
timespec operator+(timespec ts, arithT add)
Add an amount of time specified in seconds to a timespec.
timespec meanTimespec(timespec ts1, timespec ts2)
Calculate the mean time of two times given by timespecs.