|
16 | 16 |
|
17 | 17 | #include "utc.h" |
18 | 18 |
|
| 19 | +namespace global { |
| 20 | + |
19 | 21 | /** |
20 | | - * @class Global |
21 | | - * @brief Singleton class for managing and validating UTC offsets. |
22 | | - * |
23 | | - * The Global class provides methods to set and get the UTC offset in seconds. |
24 | | - * It also includes validation logic for standard UTC time zones. |
| 22 | + * @brief Gets the current UTC offset in seconds. |
| 23 | + * @return UTC offset in seconds. |
25 | 24 | */ |
26 | | -class Global { |
27 | | - public: |
28 | | - /** |
29 | | - * @brief Get the singleton instance of the Global class. |
30 | | - * @return Reference to the singleton Global object. |
31 | | - */ |
32 | | - static Global& Instance() { |
33 | | - static Global instance; |
34 | | - return instance; |
35 | | - } |
| 25 | +inline int32_t GetUtcOffset() { |
| 26 | + return global::g_utc_offset; |
| 27 | +} |
36 | 28 |
|
37 | | - /** |
38 | | - * @brief Gets the current UTC offset in seconds. |
39 | | - * @return UTC offset in seconds. |
40 | | - */ |
41 | | - int32_t GetUtcOffset() const { return global::g_utc_offset; } |
42 | | - |
43 | | - /** |
44 | | - * @brief Gets the current UTC offset as (hours, minutes). |
45 | | - * @param[out] hours Signed hour component. |
46 | | - * @param[out] minutes Unsigned minute component. |
47 | | - */ |
48 | | - void GetUtcOffset(int32_t& hours, uint32_t& minutes) { utc::SplitOffset(global::g_utc_offset, hours, minutes); } |
| 29 | +/** |
| 30 | + * @brief Gets the current UTC offset as (hours, minutes). |
| 31 | + * @param[out] hours Signed hour component. |
| 32 | + * @param[out] minutes Unsigned minute component. |
| 33 | + */ |
| 34 | +inline void GetUtcOffset(int32_t& hours, uint32_t& minutes) { |
| 35 | + utc::SplitOffset(global::g_utc_offset, hours, minutes); |
| 36 | +} |
49 | 37 |
|
50 | | - /** |
51 | | - * @brief Sets the global UTC offset if the value is valid. |
52 | | - * @param utc_offset_seconds Offset in seconds |
53 | | - * @return true if successfully set; false otherwise |
54 | | - */ |
55 | | - bool SetUtcOffsetIfValid(int32_t utc_offset_seconds) { |
56 | | - if (utc::IsValidOffset(utc_offset_seconds)) { |
57 | | - ::global::g_utc_offset = utc_offset_seconds; |
58 | | - return true; |
59 | | - } |
60 | | - return false; |
| 38 | +/** |
| 39 | + * @brief Sets the global UTC offset if the value is valid. |
| 40 | + * @param utc_offset_seconds Offset in seconds |
| 41 | + * @return true if successfully set; false otherwise |
| 42 | + */ |
| 43 | +inline bool SetUtcOffsetIfValid(int32_t utc_offset_seconds) { |
| 44 | + if (utc::IsValidOffset(utc_offset_seconds)) { |
| 45 | + ::global::g_utc_offset = utc_offset_seconds; |
| 46 | + return true; |
61 | 47 | } |
| 48 | + return false; |
| 49 | +} |
62 | 50 |
|
63 | | - /** |
64 | | - * @brief Sets the global UTC offset from (hours, minutes) if valid. |
65 | | - * @param hours Signed hour component |
66 | | - * @param minutes Unsigned minute component |
67 | | - * @return true if valid and set; false otherwise |
68 | | - */ |
69 | | - bool SetUtcOffsetIfValid(int32_t hours, uint32_t minutes) { |
70 | | - int32_t offset_seconds; |
71 | | - if (utc::ValidateOffset(hours, minutes, offset_seconds)) { |
72 | | - return SetUtcOffsetIfValid(offset_seconds); |
73 | | - } |
74 | | - return false; |
| 51 | +/** |
| 52 | + * @brief Sets the global UTC offset from (hours, minutes) if valid. |
| 53 | + * @param hours Signed hour component |
| 54 | + * @param minutes Unsigned minute component |
| 55 | + * @return true if valid and set; false otherwise |
| 56 | + */ |
| 57 | +inline bool SetUtcOffsetIfValid(int32_t hours, uint32_t minutes) { |
| 58 | + int32_t offset_seconds; |
| 59 | + if (utc::ValidateOffset(hours, minutes, offset_seconds)) { |
| 60 | + return SetUtcOffsetIfValid(offset_seconds); |
75 | 61 | } |
76 | | - |
77 | | - private: |
78 | | - Global() = default; |
79 | | - // Delete copy/move constructors and assignment operators |
80 | | - Global(const Global&) = delete; |
81 | | - Global& operator=(const Global&) = delete; |
82 | | - Global(Global&&) = delete; |
83 | | - Global& operator=(Global&&) = delete; |
84 | | -}; |
| 62 | + return false; |
| 63 | +} |
| 64 | +} // namespace global |
85 | 65 |
|
86 | 66 | #endif // GLOBAL_H_ |
0 commit comments