userver
C++ Async Framework
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
14
USERVER_NAMESPACE_BEGIN
15
16
namespace
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.
22
template
<
typename
Duration
>
23
struct
BufferFormatter
<USERVER_NAMESPACE::
utils
::
datetime
::
TimeOfDay
<
Duration
>>
24
:
detail
::
BufferFormatterBase
<
25
USERVER_NAMESPACE::
utils
::
datetime
::
TimeOfDay
<
Duration
>> {
26
using
BaseType
=
detail
::
BufferFormatterBase
<
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
{
32
Bigint
usec
=
std
::
chrono
::
duration_cast
<
std
::
chrono
::
microseconds
>(
33
this
->
value
.
SinceMidnight
())
34
.
count
();
35
io
::
WriteBuffer
(
types
,
buffer
,
usec
);
36
}
37
};
38
39
/// @brief Binary parser for utils::datetime::TimeOfDay mapped to postgres time
40
template
<
typename
Duration
>
41
struct
BufferParser
<USERVER_NAMESPACE::
utils
::
datetime
::
TimeOfDay
<
Duration
>>
42
:
detail
::
BufferParserBase
<
43
USERVER_NAMESPACE::
utils
::
datetime
::
TimeOfDay
<
Duration
>> {
44
using
BaseType
=
detail
::
BufferParserBase
<
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};
51
io
::
ReadBuffer
(
buffer
,
usec
);
52
this
->
value
=
ValueType
{
53
std
::
chrono
::
duration_cast
<
Duration
>(
std
::
chrono
::
microseconds
{
usec
})};
54
}
55
};
56
57
template
<
typename
Duration>
58
struct
CppToSystemPg<USERVER_NAMESPACE::utils::
datetime
::TimeOfDay<Duration>>
59
: PredefinedOid<PredefinedOids::kTime> {};
60
61
}
// namespace storages::postgres::io
62
63
USERVER_NAMESPACE_END
userver
storages
postgres
io
time_of_day.hpp
Generated on Mon Apr 1 2024 19:01:24 for userver by
Doxygen
1.10.0