23 #include "../globals.hpp"
24 #include "../misc.hpp"
26 #include "interval.hpp"
31 template <
class Rep,
class Period,
class = std::enable_if_t<
32 std::chrono::duration<Rep, Period>::min() < std::chrono::duration<Rep, Period>::zero()>>
33 constexpr std::chrono::duration<Rep, Period> abs(std::chrono::duration<Rep, Period> d)
35 return d >= d.zero() ? d : -d;
38 Global::duration duration_from_string2(
const std::string& s);
41 std::string to_string(Global::dtime dt,
42 const std::string& format,
44 const std::string& timezone_str,
46 bool fractional=
false);
48 Global::dtime dtime_from_numbers(
int year,
57 Global::dtime dtime_from_string(
const std::string& s,
59 const std::string& fmt =
"%Y-%m-%d %H:%M:%S[.%s] %Z",
60 const std::string&
tz =
"");
63 const std::string& format,
65 const std::string& timezone_str,
67 bool fractional=
false);
69 interval interval_from_string(
const std::string& s,
71 const std::string& fmt =
"%Y-%m-%d %H:%M:%S[.%s] %Z",
72 const std::string&
tz =
"");
74 std::string to_string(Global::duration d);
76 enum class Period : uint64_t { NANO, MICRO, MILLI, SECOND, MINUTE, HOUR, DAY, WEEK, MONTH, YEAR };
78 tz::Period unqualified_period_from_string(
const std::string& s);
85 struct multiplies<Global::duration, double, Global::duration> {
86 inline Global::duration operator()(
const Global::duration& t,
const double& u)
const {
88 throw std::range_error(
"duration multiply by NaN");
90 else if (std::isinf(u)) {
91 throw std::range_error(
"duration multiply by Inf");
93 return Global::duration(
static_cast<Global::duration::rep
>(t.count() * u));
98 struct multiplies<double, Global::duration, Global::duration> {
99 inline Global::duration operator()(
const double& u,
const Global::duration& t)
const {
101 throw std::range_error(
"duration multiply by NaN");
103 else if (std::isinf(u)) {
104 throw std::range_error(
"duration multiply by Inf");
106 return Global::duration(
static_cast<Global::duration::rep
>(t.count() * u));
111 struct divides<Global::duration, double, Global::duration> {
112 inline Global::duration operator()(
const Global::duration& t,
const double& u)
const {
114 throw std::range_error(
"duration divide by NaN");
117 throw std::range_error(
"duration divide by 0");
119 else if (std::isinf(u)) {
120 throw std::range_error(
"duration divide by Inf");
122 return Global::duration(
static_cast<Global::duration::rep
>(t.count() / u));
126 Global::dtime floor(Global::dtime t, tz::Period p);
129 Global::dtime floor_tz(Global::dtime t, tz::Period p,
const tz::Zone& z);
132 Global::dtime ceiling(Global::dtime t, tz::Period p);
135 Global::dtime ceiling_tz(Global::dtime t, tz::Period p,
const tz::Zone& z);
138 size_t dayweek(Global::dtime,
const tz::Zone& z);
139 size_t daymonth(Global::dtime t,
const tz::Zone& z);
140 size_t month(Global::dtime t,
const tz::Zone& z);
141 ssize_t year(Global::dtime t,
const tz::Zone& z);