#include </data/code/userver/libraries/proto-structs/include/userver/proto-structs/timestamp.hpp>
Type to represent google.protobuf.Timestamp
in proto structs.
This type is organized in the same way as its protobuf counterpart and allows for the same range of values desribed here https://github.com/protocolbuffers/protobuf/blob/main/src/google/protobuf/timestamp.proto : from 0001-01-01 00:00:00
to 9999-12-31 23:59:59
expressed as an offset from Unix epoch 1970-01-01 00:00:00
.
Definition at line 26 of file timestamp.hpp.
|
using | ProtobufMessage = ::google::protobuf::Timestamp |
|
using | TimePoint = std::chrono::time_point<std::chrono::system_clock> |
|
|
constexpr | Timestamp ()=default |
| Create zero (UTC epoch) timestamp.
|
|
constexpr | Timestamp (const std::chrono::seconds &seconds, const std::chrono::nanoseconds &nanos) |
| Creates timestamp from seconds specifying the offset from Unix epoch and nanos which are the non-negative (from 0 to 999'999'999 ) fractions of second.
|
|
constexpr | Timestamp (const Duration &since_epoch) |
| Creates timestamp from duration since_epoch .
|
|
template<typename TRep, typename TPeriod> |
constexpr | Timestamp (const std::chrono::duration< TRep, TPeriod > &since_epoch) |
| Creates timestamp from std::chrono::duration since_epoch.
|
|
constexpr | Timestamp (const TimePoint &time_point) |
| Creates timestamp from std::chrono::system_clock::time_point .
|
|
| Timestamp (utils::impl::InternalTag, std::int64_t seconds, std::int32_t nanos) |
|
constexpr const std::chrono::seconds & | Seconds () const noexcept |
| Returns offset from Unix epoch in seconds.
|
|
constexpr const std::chrono::nanoseconds & | Nanos () const noexcept |
| Returns fractions of second (from 0 to 999'999'999 ) of the Unix epoch offset.
|
|
constexpr TimePoint | ToTimePoint () const noexcept |
| Converts timestamp to std::chrono::system_clock::time_point .
|
|
constexpr bool | FitsInChronoTimePoint () const noexcept |
| Returns true if timestamp value fits in to the std::chrono::system_clock::time_point .
|
|
constexpr Duration | GetTimeSinceEpoch () const noexcept |
| Returns duration since epoch.
|
|
constexpr | operator TimePoint () const noexcept |
| Explicit conversion to std::chrono::system_clock::time_point .
|
|
auto | operator<=> (const Timestamp &) const =default |
| Default three-way comparison operator.
|
|
|
static constexpr Timestamp | Min () noexcept |
| Returns minimum allowed timestamp.
|
|
static constexpr Timestamp | Max () noexcept |
| Returns maximum allowed timestamp.
|
|
static constexpr bool | IsValid (const std::chrono::seconds &seconds, const std::chrono::nanoseconds &nanos) |
| Returns true if seconds and nanos represent a valid google.protobuf.Timestamp value.
|
|
|
static constexpr std::chrono::seconds | kMinSeconds {-62'135'596'800LL} |
| Minimum allowed number of seconds.
|
|
static constexpr std::chrono::seconds | kMaxSeconds {253'402'300'799LL} |
| Maximum allowed number of seconds.
|
|
◆ ProtobufMessage
using proto_structs::Timestamp::ProtobufMessage = ::google::protobuf::Timestamp |
◆ TimePoint
using proto_structs::Timestamp::TimePoint = std::chrono::time_point<std::chrono::system_clock> |
◆ Timestamp() [1/5]
proto_structs::Timestamp::Timestamp |
( |
const std::chrono::seconds & | seconds, |
|
|
const std::chrono::nanoseconds & | nanos ) |
|
inlineconstexpr |
Creates timestamp from seconds specifying the offset from Unix epoch and nanos which are the non-negative (from 0
to 999'999'999
) fractions of second.
- Exceptions
-
ValueError | if seconds and nanos does not satisty the requirements or outside the allowed range. |
- Warning
- Note that proto_structs::Duration treats nanos in a different way than
Timestamp
, which means it is not correct in general to create timestamp from duration's Seconds
and Nanos
- use specific constructor instead.
Definition at line 48 of file timestamp.hpp.
◆ Timestamp() [2/5]
proto_structs::Timestamp::Timestamp |
( |
const Duration & | since_epoch | ) |
|
|
inlineexplicitconstexpr |
Creates timestamp from duration since_epoch .
- Exceptions
-
ValueError | if since_epoch is outside the allowed range. |
Definition at line 57 of file timestamp.hpp.
◆ Timestamp() [3/5]
template<typename TRep, typename TPeriod>
proto_structs::Timestamp::Timestamp |
( |
const std::chrono::duration< TRep, TPeriod > & | since_epoch | ) |
|
|
inlineexplicitconstexpr |
Creates timestamp from std::chrono::duration
since_epoch.
- Exceptions
-
ValueError | if since_epoch is outside the allowed range. |
Definition at line 69 of file timestamp.hpp.
◆ Timestamp() [4/5]
proto_structs::Timestamp::Timestamp |
( |
const TimePoint & | time_point | ) |
|
|
inlineconstexpr |
Creates timestamp from std::chrono::system_clock::time_point
.
- Exceptions
-
ValueError | if time_point is outside the allowed range. |
Definition at line 85 of file timestamp.hpp.
◆ Timestamp() [5/5]
proto_structs::Timestamp::Timestamp |
( |
utils::impl::InternalTag | , |
|
|
std::int64_t | seconds, |
|
|
std::int32_t | nanos ) |
◆ FitsInChronoTimePoint()
bool proto_structs::Timestamp::FitsInChronoTimePoint |
( |
| ) |
const |
|
inlinenodiscardconstexprnoexcept |
Returns true
if timestamp value fits in to the std::chrono::system_clock::time_point
.
Definition at line 107 of file timestamp.hpp.
◆ GetTimeSinceEpoch()
Duration proto_structs::Timestamp::GetTimeSinceEpoch |
( |
| ) |
const |
|
inlinenodiscardconstexprnoexcept |
◆ IsValid()
static constexpr bool proto_structs::Timestamp::IsValid |
( |
const std::chrono::seconds & | seconds, |
|
|
const std::chrono::nanoseconds & | nanos ) |
|
inlinestaticnodiscardconstexpr |
Returns true
if seconds and nanos represent a valid google.protobuf.Timestamp
value.
Definition at line 154 of file timestamp.hpp.
◆ Max()
static constexpr Timestamp proto_structs::Timestamp::Max |
( |
| ) |
|
|
inlinestaticnodiscardconstexprnoexcept |
Returns maximum allowed timestamp.
- Note
- Maximum timestamp does not fit in 'std::chrono::system_clock::time_point'.
Definition at line 145 of file timestamp.hpp.
◆ Min()
static constexpr Timestamp proto_structs::Timestamp::Min |
( |
| ) |
|
|
inlinestaticnodiscardconstexprnoexcept |
Returns minimum allowed timestamp.
- Note
- Minimum timestamp may not fit in 'std::chrono::system_clock' time point type.
Definition at line 136 of file timestamp.hpp.
◆ Nanos()
const std::chrono::nanoseconds & proto_structs::Timestamp::Nanos |
( |
| ) |
const |
|
inlinenodiscardconstexprnoexcept |
Returns fractions of second (from 0
to 999'999'999
) of the Unix epoch offset.
Definition at line 93 of file timestamp.hpp.
◆ operator TimePoint()
proto_structs::Timestamp::operator TimePoint |
( |
| ) |
const |
|
inlinenodiscardconstexprnoexcept |
Explicit conversion to std::chrono::system_clock::time_point
.
- Warning
- If stored value does not fit in the
std::chrono::system_clock::time_point
it is capped at std::chrono::system_clock::time_point
min/max value.
Definition at line 129 of file timestamp.hpp.
◆ Seconds()
const std::chrono::seconds & proto_structs::Timestamp::Seconds |
( |
| ) |
const |
|
inlinenodiscardconstexprnoexcept |
Returns offset from Unix epoch in seconds.
Definition at line 90 of file timestamp.hpp.
◆ ToTimePoint()
TimePoint proto_structs::Timestamp::ToTimePoint |
( |
| ) |
const |
|
inlinenodiscardconstexprnoexcept |
Converts timestamp to std::chrono::system_clock::time_point
.
- Warning
- If stored value does not fit in the
std::chrono::system_clock::time_point
it is capped at time point min/max value.
Definition at line 98 of file timestamp.hpp.
◆ kMaxSeconds
std::chrono::seconds proto_structs::Timestamp::kMaxSeconds {253'402'300'799LL} |
|
staticconstexpr |
Maximum allowed number of seconds.
- Note
- Represents
9999-12-31 23:59:59
.
Definition at line 37 of file timestamp.hpp.
◆ kMinSeconds
std::chrono::seconds proto_structs::Timestamp::kMinSeconds {-62'135'596'800LL} |
|
staticconstexpr |
Minimum allowed number of seconds.
- Note
- Represents
0001-01-01 00:00:00
.
Definition at line 33 of file timestamp.hpp.
The documentation for this class was generated from the following files:
- /data/code/userver/libraries/proto-structs/include/userver/proto-structs/timestamp.hpp
- /data/code/userver/libraries/proto-structs/src/proto-structs/timestamp.cpp