#include </data/code/userver/libraries/proto-structs/include/userver/proto-structs/duration.hpp>
Type to represent google.protobuf.Duration in proto structs.
This type is organized in the same way as its protobuf counterpart and allows for the same range of values (approximately +-10'000 years) as described here https://github.com/protocolbuffers/protobuf/blob/main/src/google/protobuf/duration.proto .
Definition at line 27 of file duration.hpp.
Public Types | |
| using | ProtobufMessage = ::google::protobuf::Duration |
Public Member Functions | |
| constexpr | Duration ()=default |
| Creates zero duration. | |
| constexpr | Duration (const std::chrono::seconds &seconds, const std::chrono::nanoseconds &nanos) |
Creates duration from seconds and nanos which are the fractions of second (from -999'999'999 to 999'999'999) of the same sign as seconds. | |
| template<typename TRep, typename TPeriod> | |
| constexpr | Duration (const std::chrono::duration< TRep, TPeriod > &duration) |
| Creates duration. | |
| Duration (utils::impl::InternalTag, std::int64_t seconds, std::int32_t nanos) | |
| const std::chrono::seconds & | Seconds () const noexcept |
| Returns seconds. | |
| const std::chrono::nanoseconds & | Nanos () const noexcept |
Returns fractions of second (from -999'999'999 to 999'999'999). | |
| template<typename TDuration> | |
| requires ::meta::kIsInstantiationOf< std::chrono::duration, TDuration > constexpr TDuration | ToChronoDuration () const noexcept |
Converts duration to std::chrono::duration. | |
| std::chrono::nanoseconds | ToNanos () const noexcept |
Converts duration to std::chrono::nanoseconds. | |
| std::chrono::microseconds | ToMicros () const noexcept |
Converts duration to std::chrono::microseconds. | |
| std::chrono::milliseconds | ToMillis () const noexcept |
Converts duration to std::chrono::milliseconds. | |
| std::chrono::seconds | ToSeconds () const noexcept |
Converts duration to std::chrono::seconds. Simply returns stored seconds, added for completeness. | |
| template<typename TDuration> | |
| requires ::meta::kIsInstantiationOf< std::chrono::duration, TDuration > constexpr bool | FitsInChronoDuration () const noexcept |
Returns true if duration value fits in to the std::chrono::duration type. | |
| template<typename TDuration> | |
| requires ::meta::kIsInstantiationOf< std::chrono::duration, TDuration > constexpr | operator TDuration () const noexcept |
Explicit conversion to std::chrono::duration. | |
| auto | operator<=> (const Duration &) const =default |
| Default three-way comparison operator. | |
Static Public Member Functions | |
| static constexpr Duration | Min () noexcept |
| Returns minimum allowed duration. | |
| static constexpr Duration | Max () noexcept |
| Returns maximum allowed duration. | |
| static constexpr bool | IsValid (const std::chrono::seconds &seconds, const std::chrono::nanoseconds &nanos) noexcept |
Returns true if seconds and nanos represent a valid google.protobuf.Duration value. | |
Static Public Attributes | |
| static constexpr std::chrono::seconds | kMinSeconds {-315'576'000'000LL} |
| Minimum allowed number of seconds. | |
| static constexpr std::chrono::seconds | kMaxSeconds {315'576'000'000LL} |
| Maximum allowed number of seconds. | |
| using proto_structs::Duration::ProtobufMessage = ::google::protobuf::Duration |
Definition at line 29 of file duration.hpp.
|
inlineconstexpr |
Creates duration from seconds and nanos which are the fractions of second (from -999'999'999 to 999'999'999) of the same sign as seconds.
| ValueError | if seconds and nanos does not have the same sign (when seconds is not 0) or outside the allowed range: [-315'576'000'000, 315'576'000'000] for seconds and [-999'999'999, 999'999'999] for nanos. |
Definition at line 47 of file duration.hpp.
|
inlineconstexpr |
Creates duration.
| ValueError | if duration is outside the allowed range. |
Definition at line 57 of file duration.hpp.
| proto_structs::Duration::Duration | ( | utils::impl::InternalTag | , |
| std::int64_t | seconds, | ||
| std::int32_t | nanos ) |
Definition at line 12 of file duration.cpp.
|
inlinenodiscardconstexprnoexcept |
Returns true if duration value fits in to the std::chrono::duration type.
| TDuration | std::chrono::duration type |
Definition at line 121 of file duration.hpp.
|
inlinestaticnodiscardconstexprnoexcept |
Returns true if seconds and nanos represent a valid google.protobuf.Duration value.
Definition at line 179 of file duration.hpp.
|
inlinestaticnodiscardconstexprnoexcept |
Returns maximum allowed duration.
Definition at line 170 of file duration.hpp.
|
inlinestaticnodiscardconstexprnoexcept |
Returns minimum allowed duration.
Definition at line 162 of file duration.hpp.
|
inlinenodiscardnoexcept |
Returns fractions of second (from -999'999'999 to 999'999'999).
Definition at line 76 of file duration.hpp.
|
inlinenodiscardconstexprnoexcept |
Explicit conversion to std::chrono::duration.
std::chrono::duration type it is capped at std::chrono::duration min/max value. Definition at line 154 of file duration.hpp.
|
inlinenodiscardnoexcept |
Returns seconds.
Definition at line 73 of file duration.hpp.
|
inlinenodiscardconstexprnoexcept |
Converts duration to std::chrono::duration.
| TDuration | std::chrono::duration type |
std::chrono::duration type it is capped at std::chrono::duration min/max value. Definition at line 84 of file duration.hpp.
|
inlinenodiscardnoexcept |
Converts duration to std::chrono::microseconds.
Definition at line 100 of file duration.hpp.
|
inlinenodiscardnoexcept |
Converts duration to std::chrono::milliseconds.
Definition at line 107 of file duration.hpp.
|
inlinenodiscardnoexcept |
Converts duration to std::chrono::nanoseconds.
std::chrono::nanoseconds type it is capped at std::chrono::nanoseconds min/max value. Definition at line 95 of file duration.hpp.
|
inlinenodiscardnoexcept |
Converts duration to std::chrono::seconds. Simply returns stored seconds, added for completeness.
Definition at line 115 of file duration.hpp.
|
staticconstexpr |
Maximum allowed number of seconds.
10'000 years. Definition at line 37 of file duration.hpp.
|
staticconstexpr |
Minimum allowed number of seconds.
-10'000 years. Definition at line 33 of file duration.hpp.