userver: /data/code/userver/libraries/proto-structs/src/proto-structs/time_of_day.cpp Source File
Loading...
Searching...
No Matches
time_of_day.cpp
1#include <userver/proto-structs/time_of_day.hpp>
2
3#include <fmt/format.h>
4
5#include <userver/proto-structs/exceptions.hpp>
6#include <userver/utils/impl/internal_tag.hpp>
7
8USERVER_NAMESPACE_BEGIN
9
10namespace proto_structs {
11
12TimeOfDay::TimeOfDay(
13 ::utils::impl::InternalTag,
14 std::int32_t hours,
15 std::int32_t minutes,
16 std::int32_t seconds,
17 std::int32_t nanos
18)
19 : TimeOfDay(
20 std::chrono::hours{hours},
21 std::chrono::minutes{minutes},
22 std::chrono::seconds{seconds},
23 std::chrono::nanoseconds{nanos}
24 )
25{}
26
27void TimeOfDay::ThrowError(
28 const std::chrono::hours& hours,
29 const std::chrono::minutes& minutes,
30 const std::chrono::seconds& seconds,
31 const std::chrono::nanoseconds& nanos
32) {
33 throw ValueError(fmt::format(
34 "Time of the day '{}:{}:{}.{}ns' is invalid or out of range",
35 hours.count(),
36 minutes.count(),
37 seconds.count(),
38 nanos.count()
39 ));
40}
41
42void TimeOfDay::ThrowError(const char* reason) { throw ValueError(reason); }
43
44} // namespace proto_structs
45
46USERVER_NAMESPACE_END