Stroika Library 3.0d16
 
Loading...
Searching...
No Matches
TimeOfDay.inl
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2025. All rights reserved
3 */
4
5namespace Stroika::Foundation::Time {
6
7 /*
8 ********************************************************************************
9 ************************************ TimeOfDay *********************************
10 ********************************************************************************
11 */
12 inline constexpr TimeOfDay::TimeOfDay (uint32_t t)
13 : fTime_{t}
14 {
15 Require (t < kMaxSecondsPerDay);
16 Assert (fTime_ < kMaxSecondsPerDay);
17 }
18 inline constexpr TimeOfDay::TimeOfDay (unsigned int hour, unsigned int minute, unsigned int seconds)
19 : TimeOfDay{static_cast<uint32_t> (((hour * 60) + minute) * 60 + seconds)}
20 {
21 Assert (fTime_ < kMaxSecondsPerDay);
22 }
23 inline constexpr TimeOfDay TimeOfDay::kMin{0};
24 inline constexpr TimeOfDay TimeOfDay::kMax{TimeOfDay::kMaxSecondsPerDay - 1};
25 inline constexpr unsigned int TimeOfDay::GetAsSecondsCount () const
26 {
27 Ensure (fTime_ < kMaxSecondsPerDay);
28 return fTime_;
29 }
30 constexpr uint8_t TimeOfDay::GetHours () const
31 {
32 uint32_t n = GetAsSecondsCount () / (60 * 60);
33 Ensure (0 <= n and n <= 23);
34 return static_cast<uint8_t> (n);
35 }
36 constexpr uint8_t TimeOfDay::GetMinutes () const
37 {
38 uint32_t n = GetAsSecondsCount ();
39 n -= GetHours () * 60 * 60;
40 n /= 60;
41 Ensure (0 <= n and n <= 59);
42 return static_cast<uint8_t> (n);
43 }
44 constexpr uint8_t TimeOfDay::GetSeconds () const
45 {
46 uint32_t n = GetAsSecondsCount ();
47 n -= GetHours () * 60 * 60;
48 n -= GetMinutes () * 60;
49 Ensure (0 <= n and n <= 59);
50 return static_cast<uint8_t> (n);
51 }
52 inline String TimeOfDay::ToString () const
53 {
54 return Format ();
55 }
56
57}
String is like std::u32string, except it is much easier to use, often much more space efficient,...
Definition String.h:201
constexpr TimeOfDay(TimeOfDay &&src) noexcept=default