Apache Ignite C++ Client
Loading...
Searching...
No Matches
ignite_time.h
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#pragma once
19
20#include <cstdint>
21
22namespace ignite {
23
30public:
34 constexpr ignite_time() noexcept = default;
35
44 constexpr ignite_time(
45 std::int_fast8_t hour, std::int_fast8_t minute, std::int_fast8_t second = 0, std::int32_t nano = 0)
46 : m_hour(hour)
47 , m_minute(minute)
48 , m_second(second)
49 , m_nano(nano) {
50 // TODO: check that arguments are in valid ranges.
51 }
52
56 [[nodiscard]] constexpr std::int_fast8_t get_hour() const noexcept { return m_hour; }
57
61 [[nodiscard]] constexpr std::int_fast8_t get_minute() const noexcept { return m_minute; }
62
66 [[nodiscard]] constexpr std::int_fast8_t get_second() const noexcept { return m_second; }
67
71 [[nodiscard]] constexpr std::int32_t get_nano() const noexcept { return m_nano; }
72
79 [[nodiscard]] constexpr int compare(const ignite_time &other) const noexcept {
80 if (m_hour != other.m_hour) {
81 return m_hour - other.m_hour;
82 }
83 if (m_minute != other.m_minute) {
84 return m_minute - other.m_minute;
85 }
86 if (m_second != other.m_second) {
87 return m_second - other.m_second;
88 }
89 return m_nano - other.m_nano;
90 }
91
92private:
93 std::int_least8_t m_hour = 0;
94 std::int_least8_t m_minute = 0;
95 std::int_least8_t m_second = 0;
96 std::int_least32_t m_nano = 0;
97};
98
106constexpr bool operator==(const ignite_time &lhs, const ignite_time &rhs) noexcept {
107 return lhs.compare(rhs) == 0;
108}
109
117constexpr bool operator!=(const ignite_time &lhs, const ignite_time &rhs) noexcept {
118 return lhs.compare(rhs) != 0;
119}
120
128constexpr bool operator<(const ignite_time &lhs, const ignite_time &rhs) noexcept {
129 return lhs.compare(rhs) < 0;
130}
131
139constexpr bool operator<=(const ignite_time &lhs, const ignite_time &rhs) noexcept {
140 return lhs.compare(rhs) <= 0;
141}
142
150constexpr bool operator>(const ignite_time &lhs, const ignite_time &rhs) noexcept {
151 return lhs.compare(rhs) > 0;
152}
153
161constexpr bool operator>=(const ignite_time &lhs, const ignite_time &rhs) noexcept {
162 return lhs.compare(rhs) >= 0;
163}
164
165} // namespace ignite
A time of day with nanosecond precision.
Definition ignite_time.h:29
constexpr std::int_fast8_t get_second() const noexcept
Definition ignite_time.h:66
constexpr std::int_fast8_t get_minute() const noexcept
Definition ignite_time.h:61
constexpr std::int_fast8_t get_hour() const noexcept
Definition ignite_time.h:56
constexpr ignite_time() noexcept=default
constexpr int compare(const ignite_time &other) const noexcept
Definition ignite_time.h:79
constexpr std::int32_t get_nano() const noexcept
Definition ignite_time.h:71