userver
C++ Async Framework
Toggle main menu visibility
Loading...
Searching...
No Matches
dates.hpp
Go to the documentation of this file.
1
#
pragma
once
2
3
/// @file userver/storages/mysql/dates.hpp
4
5
#
include
<
chrono
>
6
#
include
<
cstdint
>
7
8
USERVER_NAMESPACE_BEGIN
9
10
namespace
storages::
mysql
{
11
12
/// @brief a class that represent MySQL DATE type.
13
class
Date
final
{
14
public
:
15
/// @brief constructs a DATE with year/month/day being zero.
16
Date
();
17
18
/// @brief constructs a DATE from provided year, month and day.
19
Date
(std::uint32_t year, std::uint32_t month, std::uint32_t day);
20
21
/// @brief constructs a DATE from provided timepoint.
22
explicit
Date
(std::chrono::system_clock::time_point tp);
23
24
/// @brief converts the DATE to timepoint in UTC time zone.
25
/// throws if stored date is out of timepoint range.
26
std::chrono::system_clock::time_point
ToTimePoint
()
const
;
27
28
/// @brief Returns the year part of the date.
29
std::
uint32_t
GetYear
()
const
noexcept
;
30
31
/// @brief Returns the month part of the date.
32
std::
uint32_t
GetMonth
()
const
noexcept
;
33
34
/// @brief Returns the day part of the date.
35
std::
uint32_t
GetDay
()
const
noexcept
;
36
37
bool
operator==(
const
Date& other)
const
noexcept
;
38
39
private
:
40
std::uint32_t year_;
41
std::uint32_t month_;
42
std::uint32_t day_;
43
};
44
45
/// @brief a class that represents MySQL DATETIME type.
46
class
DateTime
final
{
47
public
:
48
/// @brief constructs a DATETIME with DATE/hour/minute/second/microsecond
49
/// being zero.
50
DateTime
();
51
52
/// @brief constructs a DATETIME from provided DATE, hour, minute, second and
53
/// microsecond.
54
DateTime
(Date date, std::uint32_t hour, std::uint32_t minute, std::uint32_t second, std::uint64_t microsecond);
55
56
/// @brief constructs a DATETIME from provided year, month, day, hour, minute,
57
/// second and microsecond.
58
DateTime
(
59
std::uint32_t year,
60
std::uint32_t month,
61
std::uint32_t day,
62
std::uint32_t hour,
63
std::uint32_t minute,
64
std::uint32_t second,
65
std::uint64_t microsecond
66
);
67
68
/// @brief constructs a DATETIME from provided timepoint.
69
explicit
DateTime
(std::chrono::system_clock::time_point tp);
70
71
/// @brief converts the DATETIME to timepoint in UTC time zone.
72
/// throws if stored datetime is out of timepoint range.
73
std::chrono::system_clock::time_point
ToTimePoint
()
const
;
74
75
/// @brief Returns the date part of the datetime.
76
const
Date&
GetDate
()
const
noexcept
;
77
78
/// @brief Returns the hour part of the datetime.
79
std::
uint32_t
GetHour
()
const
noexcept
;
80
81
/// @brief Returns the minute part of the datetime.
82
std::
uint32_t
GetMinute
()
const
noexcept
;
83
84
/// @brief Returns the second part of the datetime.
85
std::
uint32_t
GetSecond
()
const
noexcept
;
86
87
/// @brief Returns the microsecond part of the datetime.
88
std::
uint64_t
GetMicrosecond
()
const
noexcept
;
89
90
bool
operator==(
const
DateTime& other)
const
noexcept
;
91
92
private
:
93
Date date_;
94
std::uint32_t hour_;
95
std::uint32_t minute_;
96
std::uint32_t second_;
97
std::uint64_t microsecond_;
98
};
99
100
}
// namespace storages::mysql
101
102
USERVER_NAMESPACE_END
userver
storages
mysql
dates.hpp
Generated on
for userver by
Doxygen
1.17.0