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
26void TimeOfDay::ThrowError(
27 const std::chrono::hours& hours,
28 const std::chrono::minutes& minutes,
29 const std::chrono::seconds& seconds,
30 const std::chrono::nanoseconds& nanos
31) {
32 throw ValueError(fmt::format(
33 "Time of the day '{}:{}:{}.{}ns' is invalid or out of range",
34 hours.count(),
35 minutes.count(),
36 seconds.count(),
37 nanos.count()
38 ));
39}
40
41void TimeOfDay::ThrowError(const char* reason) { throw ValueError(reason); }
42
43} // namespace proto_structs
44
45USERVER_NAMESPACE_END