userver: userver/ugrpc/datetime_utils.hpp File Reference
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
datetime_utils.hpp File Reference

Detailed Description

Utilities for google::protobuf::Timestamp, google::type::Date, and google::protobuf::Duration types.

Definition in file datetime_utils.hpp.

Go to the source code of this file.

#include <chrono>
#include <stdexcept>
#include <version>
#include <google/protobuf/duration.pb.h>
#include <google/protobuf/timestamp.pb.h>
#include <google/type/date.pb.h>
#include <userver/formats/json_fwd.hpp>
#include <userver/formats/parse/to.hpp>
#include <userver/formats/serialize/to.hpp>
#include <userver/utils/assert.hpp>
#include <userver/utils/datetime/cpp_20_calendar.hpp>
#include <userver/utils/datetime/date.hpp>

Classes

class  ugrpc::TimestampConversionError
 Exception thrown when timestamp conversion functions receive/produce invalid google::protobuf::Timestamp accrording to IsValid or otherwise lead to undefined behavior due to integer overflow. More...
 
class  ugrpc::DateConversionError
 Exception thrown when date conversion functions receive/produce invalid google::type::Date accrording to IsValid or otherwise lead to undefined behavior due to integer overflow. More...
 
class  ugrpc::DurationConversionError
 Exception thrown when duration conversion functions receive/produce invalid google::protobuf::Duration accrording to IsValid or otherwise lead to undefined behavior due to integer overflow. More...
 

Namespaces

namespace  ugrpc
 Asynchronous gRPC driver.
 
namespace  formats
 Value formats representation, parsing and serialization.
 
namespace  formats::parse
 Generic parsers and converters.
 
namespace  formats::serialize
 Common serializers.
 

Functions

bool ugrpc::IsValid (const google::protobuf::Timestamp &grpc_ts)
 Checks if google::protobuf::Timestamp contains a valid value according to protobuf documentation.
 
template<class Duration >
google::protobuf::Timestamp ugrpc::ToProtoTimestamp (const std::chrono::time_point< std::chrono::system_clock, Duration > &system_tp)
 Creates google::protobuf::Timestamp from std::chrono::time_point.
 
template<class Duration = std::chrono::system_clock::duration>
std::chrono::time_point< std::chrono::system_clock, Duration > ugrpc::ToTimePoint (const google::protobuf::Timestamp &grpc_ts)
 Creates std::chrono::system_clock::time_point from google::protobuf::Timestamp.
 
google::protobuf::Timestamp ugrpc::NowTimestamp ()
 Returns current (possibly, mocked) timestamp as a google::protobuf::Timestamp.
 
bool ugrpc::IsValid (const google::type::Date &grpc_date)
 Checks if google::type::Date contains a valid value according to protobuf documentation.
 
google::type::Date ugrpc::ToProtoDate (const utils::datetime::Date &utils_date)
 Creates google::type::Date from utils::datetime::Date.
 
utils::datetime::Date ugrpc::ToUtilsDate (const google::type::Date &grpc_date)
 Creates utils::datetime::Date from google::type::Date.
 
template<class Duration >
google::type::Date ugrpc::ToProtoDate (const std::chrono::time_point< std::chrono::system_clock, Duration > &system_tp)
 Creates google::type::Date from std::chrono::time_point.
 
std::chrono::time_point< std::chrono::system_clock, utils::datetime::Days > ugrpc::ToTimePoint (const google::type::Date &grpc_date)
 Creates std::chrono::system_clock::time_point from google::type::Date.
 
google::type::Date ugrpc::NowDate ()
 Returns current (possibly, mocked) timestamp as a google::type::Date.
 
bool ugrpc::IsValid (const google::protobuf::Duration &grpc_duration)
 Checks if google::protobuf::Duration contains a valid value according to protobuf documentation.
 
template<class Duration = std::chrono::microseconds>
Duration ugrpc::ToDuration (const google::protobuf::Duration &grpc_duration)
 Creates std::chrono::duration from google::protobuf::Duration.
 
template<class Rep , class Period >
google::protobuf::Duration ugrpc::ToProtoDuration (const std::chrono::duration< Rep, Period > &duration)
 Creates google::protobuf::Duration from std::chrono::duration.