1#include <userver/proto-structs/io/std/chrono/year_month_day_conv.hpp>
3#include <google/type/date.pb.h>
5#include <userver/proto-structs/date.hpp>
6#include <userver/proto-structs/exceptions.hpp>
7#include <userver/proto-structs/io/context.hpp>
8#include <userver/utils/impl/internal_tag.hpp>
10USERVER_NAMESPACE_BEGIN
12namespace proto_structs::io {
14std::chrono::year_month_day ReadProtoStruct(
16 To<std::chrono::year_month_day>,
17 const ::google::type::Date& msg
20 Date date(utils::
impl::InternalTag{}, msg.year(), msg.month(), msg.day());
22 if (!date.HasYearMonthDay()) {
23 ctx.AddError(
"full date is expected for 'std::chrono::year_month_day' proto struct field");
24 return std::chrono::year_month_day{std::chrono::year{0}, std::chrono::month{0}, std::chrono::day{0}};
27 return date.ToChronoDate();
28 }
catch (
const ValueError& e) {
29 ctx.AddError(e.what());
30 return std::chrono::year_month_day{std::chrono::year{0}, std::chrono::month{0}, std::chrono::day{0}};
34void WriteProtoStruct(WriteContext& ctx,
const std::chrono::year_month_day& obj, ::google::type::Date& msg) {
37 msg.set_year(date.YearNum());
38 msg.set_month(date.MonthNum());
39 msg.set_day(date.DayNum());
40 }
catch (
const ValueError& e) {
41 ctx.AddError(e.what());