11#include <cctz/civil_time.h>
13USERVER_NAMESPACE_BEGIN
18inline const std::string kRfc3339Format =
"%Y-%m-%dT%H:%M:%E*S%Ez";
19inline const std::string kTaximeterFormat =
"%Y-%m-%dT%H:%M:%E6SZ";
20inline constexpr std::time_t kStartOfTheEpoch = 0;
21inline const std::string kDefaultDriverTimezone =
"Europe/Moscow";
22inline const std::string kDefaultTimezone =
"UTC";
23inline const std::string kDefaultFormat =
"%Y-%m-%dT%H:%M:%E*S%z";
24inline const std::string kIsoFormat =
"%Y-%m-%dT%H:%M:%SZ";
27using timepair_t = std::pair<uint8_t, uint8_t>;
32 DateParseError(
const std::string& timestring);
38 TimezoneLookupError(
const std::string& tzname);
42std::chrono::system_clock::time_point
Now()
noexcept;
46std::chrono::system_clock::time_point
Epoch()
noexcept;
54std::chrono::steady_clock::time_point
SteadyNow()
noexcept;
59 using time_point = std::chrono::steady_clock::time_point;
61 static time_point now() {
return SteadyNow(); }
65bool IsTimeBetween(
int hour,
int min,
int hour_from,
int min_from,
int hour_to,
66 int min_to,
bool include_time_to =
false)
noexcept;
71 const std::string& timezone = kDefaultTimezone,
72 const std::string& format = kDefaultFormat);
76 const std::string& format = kDefaultFormat);
80std::string
Timestring(std::chrono::system_clock::time_point tp,
81 const std::string& timezone = kDefaultTimezone,
82 const std::string& format = kDefaultFormat);
86 const std::string& format = kDefaultFormat);
92 const std::string& timestring,
93 const std::string& timezone = kDefaultTimezone,
94 const std::string& format = kDefaultFormat);
99 const std::string& timestring,
const std::string& format = kDefaultFormat);
105 const std::string& timestamp,
const std::string& timezone);
110 const std::string& timestamp);
113std::time_t
Timestamp(std::chrono::system_clock::time_point tp)
noexcept;
126cctz::civil_second
Localize(
const std::chrono::system_clock::time_point& tp,
127 const std::string& timezone);
132 const std::chrono::system_clock::time_point& tp);
137 const std::string& timezone);
150 const std::chrono::system_clock::time_point& tp)
noexcept;
156template <
class Duration,
class Clock>
158 const std::chrono::time_point<Clock>& b) {
159 const auto duration_a = a.time_since_epoch();
160 const auto duration_b = b.time_since_epoch();
161 return std::chrono::duration_cast<Duration>(duration_a - duration_b).count();