Apache Ignite C++ Client
Loading...
Searching...
No Matches
ignite_timestamp.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_timestamp() noexcept = default;
35
42 constexpr ignite_timestamp(std::int64_t seconds, std::int32_t nanos)
43 : m_seconds(seconds)
44 , m_nanos(nanos) {
45 // TODO: check that arguments are in valid ranges.
46 }
47
51 [[nodiscard]] constexpr std::int64_t get_epoch_second() const noexcept { return m_seconds; }
52
56 [[nodiscard]] constexpr std::int32_t get_nano() const noexcept { return m_nanos; }
57
64 [[nodiscard]] constexpr int compare(const ignite_timestamp &other) const noexcept {
65 if (m_seconds != other.m_seconds) {
66 return m_seconds < other.m_seconds ? -1 : 1;
67 }
68 return m_nanos - other.m_nanos;
69 }
70
71private:
73 std::int64_t m_seconds = 0;
74
76 std::int32_t m_nanos = 0;
77};
78
86constexpr bool operator==(const ignite_timestamp &lhs, const ignite_timestamp &rhs) noexcept {
87 return lhs.compare(rhs) == 0;
88}
89
97constexpr bool operator!=(const ignite_timestamp &lhs, const ignite_timestamp &rhs) noexcept {
98 return lhs.compare(rhs) != 0;
99}
100
108constexpr bool operator<(const ignite_timestamp &lhs, const ignite_timestamp &rhs) noexcept {
109 return lhs.compare(rhs) < 0;
110}
111
119constexpr bool operator<=(const ignite_timestamp &lhs, const ignite_timestamp &rhs) noexcept {
120 return lhs.compare(rhs) <= 0;
121}
122
130constexpr bool operator>(const ignite_timestamp &lhs, const ignite_timestamp &rhs) noexcept {
131 return lhs.compare(rhs) > 0;
132}
133
141constexpr bool operator>=(const ignite_timestamp &lhs, const ignite_timestamp &rhs) noexcept {
142 return lhs.compare(rhs) >= 0;
143}
144
145} // namespace ignite
A moment of time.
Definition ignite_timestamp.h:29
constexpr std::int64_t get_epoch_second() const noexcept
Definition ignite_timestamp.h:51
constexpr ignite_timestamp() noexcept=default
constexpr int compare(const ignite_timestamp &other) const noexcept
Definition ignite_timestamp.h:64
constexpr std::int32_t get_nano() const noexcept
Definition ignite_timestamp.h:56