21 enum TimeOption { USE_DOY, DAYS_360, COUNT };
24 static bool& useDOY() {
return m_opt[USE_DOY]; }
27 static std::array<bool, COUNT> m_opt;
30typedef std::chrono::system_clock SystemClock;
31typedef SystemClock::duration SystemDuration;
37 typedef SystemDuration Basis;
72 double seconds()
const {
return std::chrono::duration_cast<std::chrono::seconds>(m_d).count(); }
74 std::istream& parse(std::istream& is);
76 Duration& parse(
const std::string& str)
78 std::stringstream is(str);
83 std::ostream& format(std::ostream& os)
const {
return os << seconds(); }
85 std::string format()
const
93 friend Duration durationFromISO(
const std::string&,
int);
101 void setDurationSeconds(
double);
115std::time_t
mkgmtime(std::tm* time,
bool recalculateDoy =
true);
140 typedef SystemClock Clock;
141 typedef std::chrono::time_point<Clock, Duration::Basis> Basis;
145 TimePoint(
const std::string& str) { this->parse(str); }
165 bool operator<=(
const TimePoint& a)
const {
return m_t <= a.m_t; }
166 bool operator<(
const TimePoint& a)
const {
return m_t < a.m_t; }
167 bool operator>=(
const TimePoint& a)
const {
return m_t >= a.m_t; }
168 bool operator>(
const TimePoint& a)
const {
return m_t > a.m_t; }
169 bool operator==(
const TimePoint& a)
const {
return m_t == a.m_t; }
170 bool operator!=(
const TimePoint& a)
const {
return m_t != a.m_t; }
172 std::istream& parse(std::istream& is)
174 auto fromTime = Clock::from_time_t(
timeFromISO(is));
181 std::stringstream is(str);
186 std::ostream& format(std::ostream& os)
const
189 auto tt = Clock::to_time_t(m_t);
190 os << std::put_time(std::gmtime(&tt), ymdhmsFormat.c_str());
194 std::string format()
const
196 std::stringstream ss;
201 std::tm* gmtime()
const;
203 static const std::string ymdFormat;
204 static const std::string doyFormat;
205 static const std::string ymdhmsFormat;
206 static const std::string doyhmsFormat;
207 static const std::string hmsFormat;
234 inline bool isIn(
const TimePoint& query) {
return query >= m_start && query < m_stop; }
236 inline bool doStep(
const TimePoint& query)
238 if (m_last + m_step <= query) {
252inline double operator*(
double a,
const Duration& b) {
return a * b.seconds(); }
253inline double operator/(
double a,
const Duration& b) {
return a / b.seconds(); }
254inline double operator*(
const Duration& a,
double b) {
return b * a; }
255inline double operator/(
const Duration& a,
double b) {
return a.seconds() / b; }
257inline std::istream&
operator>>(std::istream& is, TimePoint& tp) {
return tp.parse(is); }
258inline std::istream&
operator>>(std::istream& is, Duration& dur) {
return dur.parse(is); }
259inline std::ostream& operator<<(std::ostream& os,
const TimePoint& tp) {
return tp.format(os); }
260inline std::ostream& operator<<(std::ostream& os,
const Duration& dur) {
return dur.format(os); }
std::istream & operator>>(std::istream &, EnumWrapper< E > &)
A templated input operator that uses the defined map to set the value of the wrapped enum.
std::time_t timeFromISO(const std::string &iso)
Returns a std::time_t from a given ISO date string of a specific format.
int julianGregorianShiftDays(int year)
Returns the number of days between the Julian and Gregorian years.
std::time_t mkgmtime(std::tm *time, bool recalculateDoy=true)
converts the std::tm struct to a std::time_t value assuming UTC.