userver: userver/storages/postgres/io/time_of_day.hpp Source File
Loading...
Searching...
No Matches
time_of_day.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file userver/storages/postgres/io/time_of_day.hpp
4/// @brief utils::datetime::TimeOfDay I/O support
5/// @ingroup userver_postgres_parse_and_format
6
7#include <userver/utils/time_of_day.hpp>
8
9#include <userver/storages/postgres/exceptions.hpp>
10#include <userver/storages/postgres/io/buffer_io.hpp>
11#include <userver/storages/postgres/io/buffer_io_base.hpp>
12#include <userver/storages/postgres/io/type_mapping.hpp>
13
14USERVER_NAMESPACE_BEGIN
15
16namespace storages::postgres::io {
17
18/// @brief Binary formatter for utils::datetime::TimeOfDay mapped to postgres
19/// time
20/// This datatype is time-zone agnostic, it should't be mixed with timetz type
21/// or sudden TZ adjustments will be applied.
22template <typename Duration>
23struct BufferFormatter<USERVER_NAMESPACE::utils::datetime::TimeOfDay<Duration>>
25 USERVER_NAMESPACE::utils::datetime::TimeOfDay<Duration>> {
27 USERVER_NAMESPACE::utils::datetime::TimeOfDay<Duration>>;
28 using BaseType::BaseType;
29
30 template <typename Buffer>
31 void operator()(const UserTypes& types, Buffer& buffer) const {
33 this->value.SinceMidnight())
34 .count();
36 }
37};
38
39/// @brief Binary parser for utils::datetime::TimeOfDay mapped to postgres time
40template <typename Duration>
41struct BufferParser<USERVER_NAMESPACE::utils::datetime::TimeOfDay<Duration>>
43 USERVER_NAMESPACE::utils::datetime::TimeOfDay<Duration>> {
45 USERVER_NAMESPACE::utils::datetime::TimeOfDay<Duration>>;
46 using ValueType = typename BaseType::ValueType;
47 using BaseType::BaseType;
48
49 void operator()(const FieldBuffer& buffer) {
50 Bigint usec{0};
52 this->value = ValueType{
54 }
55};
56
57template <typename Duration>
58struct CppToSystemPg<USERVER_NAMESPACE::utils::datetime::TimeOfDay<Duration>>
59 : PredefinedOid<PredefinedOids::kTime> {};
60
61} // namespace storages::postgres::io
62
63USERVER_NAMESPACE_END