13#include <cctz/civil_time.h>
15USERVER_NAMESPACE_BEGIN
22inline constexpr std::time_t kStartOfTheEpoch = 0;
30inline const std::string
kIsoFormat =
"%Y-%m-%dT%H:%M:%SZ";
32using timepair_t = std::pair<std::uint8_t, std::uint8_t>;
37 DateParseError(
const std::string& timestring);
43 TimezoneLookupError(
const std::string& tzname);
72 static time_point now() {
return SteadyNow(); }
83 bool include_time_to =
false
96std::string Timestring(
97 std::time_t timestamp,
105std::string LocalTimezoneTimestring(std::time_t timestamp,
const std::string& format =
kDefaultFormat);
115std::string Timestring(
116 std::chrono::system_clock::time_point tp,
125LocalTimezoneTimestring(std::chrono::system_clock::time_point tp,
const std::string& format =
kDefaultFormat);
136std::chrono::system_clock::time_point Stringtime(
137 const std::string& timestring,
138 const std::string& timezone = kDefaultTimezone,
139 const std::string& format = kDefaultFormat
146std::chrono::system_clock::time_point
147LocalTimezoneStringtime(
const std::string& timestring,
const std::string& format = kDefaultFormat);
156std::chrono::system_clock::time_point GuessStringtime(
const std::string& timestamp,
const std::string& timezone);
160std::chrono::system_clock::time_point GuessLocalTimezoneStringtime(
const std::string& timestamp);
169std::optional<std::chrono::system_clock::time_point> OptionalStringtime(
170 const std::string& timestring,
171 const std::string& timezone = kDefaultTimezone,
172 const std::string& format = kDefaultFormat
180std::time_t Timestamp(std::chrono::system_clock::time_point tp)
noexcept;
188std::uint32_t ParseDayTime(
const std::string& str);
197cctz::civil_second Localize(
const std::chrono::system_clock::time_point& tp,
const std::string& timezone);
201cctz::civil_second LocalTimezoneLocalize(
const std::chrono::system_clock::time_point& tp);
209std::time_t Unlocalize(
const cctz::civil_second& local_tp,
const std::string& timezone);
216std::string TimestampToString(std::time_t timestamp);
225std::int64_t TimePointToTicks(
const std::chrono::system_clock::time_point& tp)
noexcept;
231template <
class Duration,
class Clock>
232double CalcTimeDiff(
const std::chrono::time_point<Clock>& a,
const std::chrono::time_point<Clock>& b) {
233 const auto duration_a = a.time_since_epoch();
234 const auto duration_b = b.time_since_epoch();
235 return std::chrono::duration_cast<Duration>(duration_a - duration_b).count();