userver: userver/utils/datetime/timepoint_tz.hpp Source File
Loading...
Searching...
No Matches
timepoint_tz.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file userver/utils/datetime/timepoint_tz.hpp
4/// @brief Timepoint with timezone
5/// @ingroup userver_universal
6
7#include <chrono>
8
9#include <userver/logging/log_helper.hpp>
10
11USERVER_NAMESPACE_BEGIN
12
13namespace utils::datetime {
14
16 public:
17 using TimePoint = std::chrono::system_clock::time_point;
18
19 constexpr TimePointTzBase() = default;
20 constexpr explicit TimePointTzBase(TimePoint tp) : tp_(tp) {}
21 constexpr TimePointTzBase(TimePoint tp, std::chrono::seconds tz_offset)
22 : tp_(tp), tz_offset_(tz_offset) {}
23 TimePointTzBase(const TimePointTzBase& other);
24 TimePointTzBase(TimePointTzBase&& other) noexcept;
25
26 TimePointTzBase& operator=(const TimePointTzBase& other);
27 TimePointTzBase& operator=(TimePointTzBase&& other) noexcept;
28
29 // Deliberately no 'explicit' to be compatible with legacy util/swaggen's
30 // plain time_point types
31 operator TimePoint() const;
32
33 /// Get timezone in seconds (may be negative)
35
36 /// Get std's time_point
37 TimePoint GetTimePoint() const;
38
39 bool operator==(const TimePointTzBase& other) const;
40
41 bool operator<(const TimePointTzBase& other) const;
42
43 bool operator>(const TimePointTzBase& other) const;
44
45 bool operator<=(const TimePointTzBase& other) const;
46
47 bool operator>=(const TimePointTzBase& other) const;
48
49 private:
50 TimePoint tp_{};
51 std::chrono::seconds tz_offset_{};
52};
53
54bool operator<(const TimePointTzBase::TimePoint& lhs,
55 const TimePointTzBase& rhs);
56
57bool operator>(const TimePointTzBase::TimePoint& lhs,
58 const TimePointTzBase& rhs);
59
60bool operator<=(const TimePointTzBase::TimePoint& lhs,
61 const TimePointTzBase& rhs);
62
63bool operator>=(const TimePointTzBase::TimePoint& lhs,
64 const TimePointTzBase& rhs);
65
66/// Timepoint with timezone parsed in kRfc3339Format
67class TimePointTz final : public TimePointTzBase {
68 using TimePointTzBase::TimePointTzBase;
69};
70
71logging::LogHelper& operator<<(logging::LogHelper& os, const TimePointTz& v);
72
73/// Timepoint with timezone parsed in kDefaultFormat
74class TimePointTzIsoBasic final : public TimePointTzBase {
75 using TimePointTzBase::TimePointTzBase;
76};
77
78logging::LogHelper& operator<<(logging::LogHelper& os,
79 const TimePointTzIsoBasic& v);
80
81} // namespace utils::datetime
82
83USERVER_NAMESPACE_END