userver: proto_structs::Date Class Reference
Loading...
Searching...
No Matches
proto_structs::Date Class Reference

#include </data/code/userver/libraries/proto-structs/include/userver/proto-structs/date.hpp>

Detailed Description

Type to represent google.type.Date in proto structs.

This type is organized in the same way as its protobuf counterpart and allows for the same range of values described here https://github.com/googleapis/googleapis/blob/master/google/type/date.proto :

  • a full date, with non-zero year, month, and day values
  • a year and month value, with a zero day, such as a credit card expiration date
  • a year on its own, with zero month and day values
  • a month and day value, with a zero year, such as an anniversary

The year part of the date must be in the [1, 9999] range. The month should be in the [1, 12] range. The day should be in the [1, 31] range. Altogether, year, month and day must represent a valid date.

Definition at line 31 of file date.hpp.

Public Types

using ProtobufMessage = ::google::type::Date
 

Public Member Functions

constexpr Date ()=default
 Creates empty date with all components unset.
 
constexpr Date (const std::optional< std::chrono::year > &year, const std::optional< std::chrono::month > &month, const std::optional< std::chrono::day > &day)
 Creates date.
 
constexpr Date (const std::chrono::year_month_day &ymd)
 Creates full date.
 
constexpr Date (const std::chrono::year_month &ym)
 Creates date without a day.
 
constexpr Date (const std::chrono::month_day &md)
 Creates date without a year.
 
constexpr Date (const std::chrono::year &year)
 Creates date holding only year.
 
constexpr Date (const utils::datetime::Date &date)
 Creates full date.
 
constexpr Date (const std::chrono::sys_days &sys_days)
 Creates full date from std::chrono::sys_days.
 
 Date (utils::impl::InternalTag, std::int32_t year, std::int32_t month, std::int32_t day)
 
constexpr const std::optional< std::chrono::year > & Year () const noexcept
 Returns year.
 
constexpr const std::optional< std::chrono::month > & Month () const noexcept
 Returns month.
 
constexpr const std::optional< std::chrono::day > & Day () const noexcept
 Returns day.
 
constexpr std::int32_t YearNum () const noexcept
 Returns year as integer.
 
constexpr std::int32_t MonthNum () const noexcept
 Returns month as integer.
 
constexpr std::int32_t DayNum () const noexcept
 Returns day as integer.
 
constexpr std::chrono::year_month_day ToChronoDate () const
 Converts date to std::chrono::year_month_day.
 
constexpr std::chrono::year_month ToChronoYearMonth () const
 Converts date to std::chrono::year_month.
 
constexpr std::chrono::month_day ToChronoMonthDay () const
 Converts date to std::chrono::month_day.
 
constexpr std::chrono::year ToChronoYear () const
 Converts date to std::chrono::year.
 
constexpr std::chrono::sys_days ToChronoSysDays () const
 Converts date to std::chrono::sys_days.
 
utils::datetime::Date ToUserverDate () const
 Converts date to userver::utils::datetime::Date.
 
constexpr bool IsEmpty () const noexcept
 Returns true if date is empty (i.e. all components are not set).
 
constexpr bool HasYearMonthDay () const noexcept
 Returns true if date has all components.
 
constexpr bool HasYearMonth () const noexcept
 Returns true if date is has year and month.
 
constexpr bool HasMonthDay () const noexcept
 Returns true if date is has month and day.
 
constexpr bool HasYear () const noexcept
 Returns true if date is has year.
 
constexpr operator std::chrono::year_month_day () const
 Explicit conversion to std::chrono::year_month_day.
 
constexpr operator std::chrono::year_month () const
 Explicit conversion to std::chrono::year_month.
 
constexpr operator std::chrono::month_day () const
 Explicit conversion to std::chrono::month_day.
 
constexpr operator std::chrono::year () const
 Explicit conversion to std::chrono::year.
 
constexpr operator std::chrono::sys_days () const
 Explicit conversion to std::chrono::sys_days.
 
constexpr operator utils::datetime::Date () const
 Explicit conversion to userver::utils::datetime::Date.
 
constexpr auto operator<=> (const Date &) const =default
 Default three-way comparison operator.
 

Static Public Member Functions

static constexpr bool IsValid (const std::optional< std::chrono::year > &year, const std::optional< std::chrono::month > &month, const std::optional< std::chrono::day > &day) noexcept
 Returns true if year, month and day represent a meaningful and valid date.
 
static bool IsValid (utils::impl::InternalTag, std::int32_t year_num, std::int32_t month_num, std::int32_t day_num) noexcept
 

Member Typedef Documentation

◆ ProtobufMessage

using proto_structs::Date::ProtobufMessage = ::google::type::Date

Definition at line 33 of file date.hpp.

Constructor & Destructor Documentation

◆ Date() [1/8]

proto_structs::Date::Date ( const std::optional< std::chrono::year > & year,
const std::optional< std::chrono::month > & month,
const std::optional< std::chrono::day > & day )
inlineconstexpr

Creates date.

Exceptions
ValueErrorif year, month and day do not represent a meaningful and valid date.

Definition at line 40 of file date.hpp.

◆ Date() [2/8]

proto_structs::Date::Date ( const std::chrono::year_month_day & ymd)
inlineconstexpr

Creates full date.

Exceptions
ValueErrorif ymd is not valid or outside the allowed range.

Definition at line 53 of file date.hpp.

◆ Date() [3/8]

proto_structs::Date::Date ( const std::chrono::year_month & ym)
inlineconstexpr

Creates date without a day.

Exceptions
ValueErrorif ym is not valid or outside the allowed range.

Definition at line 57 of file date.hpp.

◆ Date() [4/8]

proto_structs::Date::Date ( const std::chrono::month_day & md)
inlineconstexpr

Creates date without a year.

Exceptions
ValueErrorif md is not valid.

Definition at line 61 of file date.hpp.

◆ Date() [5/8]

proto_structs::Date::Date ( const std::chrono::year & year)
inlineconstexpr

Creates date holding only year.

Exceptions
ValueErrorif year is outside the allowed range.

Definition at line 65 of file date.hpp.

◆ Date() [6/8]

proto_structs::Date::Date ( const utils::datetime::Date & date)
inlineconstexpr

Creates full date.

Exceptions
ValueErrorif date is outside the allowed range.

Definition at line 69 of file date.hpp.

◆ Date() [7/8]

proto_structs::Date::Date ( const std::chrono::sys_days & sys_days)
inlineconstexpr

Creates full date from std::chrono::sys_days.

Exceptions
ValueErrorif sys_days is outside the allowed range.

Definition at line 73 of file date.hpp.

◆ Date() [8/8]

proto_structs::Date::Date ( utils::impl::InternalTag ,
std::int32_t year,
std::int32_t month,
std::int32_t day )

Definition at line 12 of file date.cpp.

Member Function Documentation

◆ Day()

const std::optional< std::chrono::day > & proto_structs::Date::Day ( ) const
inlinenodiscardconstexprnoexcept

Returns day.

Definition at line 84 of file date.hpp.

◆ DayNum()

std::int32_t proto_structs::Date::DayNum ( ) const
inlinenodiscardconstexprnoexcept

Returns day as integer.

Note
Zero value means that day is not set.

Definition at line 100 of file date.hpp.

◆ HasMonthDay()

bool proto_structs::Date::HasMonthDay ( ) const
inlinenodiscardconstexprnoexcept

Returns true if date is has month and day.

Definition at line 177 of file date.hpp.

◆ HasYear()

bool proto_structs::Date::HasYear ( ) const
inlinenodiscardconstexprnoexcept

Returns true if date is has year.

Definition at line 180 of file date.hpp.

◆ HasYearMonth()

bool proto_structs::Date::HasYearMonth ( ) const
inlinenodiscardconstexprnoexcept

Returns true if date is has year and month.

Definition at line 174 of file date.hpp.

◆ HasYearMonthDay()

bool proto_structs::Date::HasYearMonthDay ( ) const
inlinenodiscardconstexprnoexcept

Returns true if date has all components.

Definition at line 171 of file date.hpp.

◆ IsEmpty()

bool proto_structs::Date::IsEmpty ( ) const
inlinenodiscardconstexprnoexcept

Returns true if date is empty (i.e. all components are not set).

Definition at line 168 of file date.hpp.

◆ IsValid() [1/2]

static constexpr bool proto_structs::Date::IsValid ( const std::optional< std::chrono::year > & year,
const std::optional< std::chrono::month > & month,
const std::optional< std::chrono::day > & day )
inlinestaticnodiscardconstexprnoexcept

Returns true if year, month and day represent a meaningful and valid date.

Definition at line 211 of file date.hpp.

◆ IsValid() [2/2]

bool proto_structs::Date::IsValid ( utils::impl::InternalTag ,
std::int32_t year_num,
std::int32_t month_num,
std::int32_t day_num )
staticnodiscardnoexcept

Definition at line 30 of file date.cpp.

◆ Month()

const std::optional< std::chrono::month > & proto_structs::Date::Month ( ) const
inlinenodiscardconstexprnoexcept

Returns month.

Definition at line 81 of file date.hpp.

◆ MonthNum()

std::int32_t proto_structs::Date::MonthNum ( ) const
inlinenodiscardconstexprnoexcept

Returns month as integer.

Note
Zero value means that month is not set.

Definition at line 94 of file date.hpp.

◆ operator std::chrono::month_day()

proto_structs::Date::operator std::chrono::month_day ( ) const
inlineexplicitnodiscardconstexpr

Explicit conversion to std::chrono::month_day.

Exceptions
ValueErrorif month or day is not set.

Definition at line 192 of file date.hpp.

◆ operator std::chrono::sys_days()

proto_structs::Date::operator std::chrono::sys_days ( ) const
inlineexplicitnodiscardconstexpr

Explicit conversion to std::chrono::sys_days.

Exceptions
ValueErrorif year is not set.
Note
If day is not set, 1d is assumed. If month is also not set, January is assumed.

Definition at line 201 of file date.hpp.

◆ operator std::chrono::year()

proto_structs::Date::operator std::chrono::year ( ) const
inlineexplicitnodiscardconstexpr

Explicit conversion to std::chrono::year.

Exceptions
ValueErrorif year is not set.

Definition at line 196 of file date.hpp.

◆ operator std::chrono::year_month()

proto_structs::Date::operator std::chrono::year_month ( ) const
inlineexplicitnodiscardconstexpr

Explicit conversion to std::chrono::year_month.

Exceptions
ValueErrorif year or month is not set.

Definition at line 188 of file date.hpp.

◆ operator std::chrono::year_month_day()

proto_structs::Date::operator std::chrono::year_month_day ( ) const
inlineexplicitnodiscardconstexpr

Explicit conversion to std::chrono::year_month_day.

Exceptions
ValueErrorif any date component is not set.

Definition at line 184 of file date.hpp.

◆ operator utils::datetime::Date()

proto_structs::Date::operator utils::datetime::Date ( ) const
inlineexplicitnodiscardconstexpr

Explicit conversion to userver::utils::datetime::Date.

Exceptions
ValueErrorif any date component is not set.

Definition at line 205 of file date.hpp.

◆ ToChronoDate()

std::chrono::year_month_day proto_structs::Date::ToChronoDate ( ) const
inlinenodiscardconstexpr

Converts date to std::chrono::year_month_day.

Exceptions
ValueErrorif any date component is not set.

Definition at line 106 of file date.hpp.

◆ ToChronoMonthDay()

std::chrono::month_day proto_structs::Date::ToChronoMonthDay ( ) const
inlinenodiscardconstexpr

Converts date to std::chrono::month_day.

Exceptions
ValueErrorif month or day is not set.

Definition at line 126 of file date.hpp.

◆ ToChronoSysDays()

std::chrono::sys_days proto_structs::Date::ToChronoSysDays ( ) const
inlinenodiscardconstexpr

Converts date to std::chrono::sys_days.

Exceptions
ValueErrorif year is not set.
Note
If day is not set, 1d is assumed. If month is also not set, January is assumed.

Definition at line 147 of file date.hpp.

◆ ToChronoYear()

std::chrono::year proto_structs::Date::ToChronoYear ( ) const
inlinenodiscardconstexpr

Converts date to std::chrono::year.

Exceptions
ValueErrorif year is not set.

Definition at line 136 of file date.hpp.

◆ ToChronoYearMonth()

std::chrono::year_month proto_structs::Date::ToChronoYearMonth ( ) const
inlinenodiscardconstexpr

Converts date to std::chrono::year_month.

Exceptions
ValueErrorif year or month is not set.

Definition at line 116 of file date.hpp.

◆ ToUserverDate()

utils::datetime::Date proto_structs::Date::ToUserverDate ( ) const
inlinenodiscard

Converts date to userver::utils::datetime::Date.

Exceptions
ValueErrorif any date component is not set.

Definition at line 158 of file date.hpp.

◆ Year()

const std::optional< std::chrono::year > & proto_structs::Date::Year ( ) const
inlinenodiscardconstexprnoexcept

Returns year.

Definition at line 78 of file date.hpp.

◆ YearNum()

std::int32_t proto_structs::Date::YearNum ( ) const
inlinenodiscardconstexprnoexcept

Returns year as integer.

Note
Zero value means that year is not set.

Definition at line 88 of file date.hpp.


The documentation for this class was generated from the following files: