Apache Ignite C++ Client
Loading...
Searching...
No Matches
ignite_period.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_period() noexcept = default;
35
43 constexpr ignite_period(std::int32_t years, std::int32_t months, std::int32_t days)
44 : years(years)
45 , months(months)
46 , days(days) {
47 // TODO: check that arguments are in valid ranges.
48 }
49
53 constexpr std::int32_t get_years() const noexcept { return years; }
54
58 constexpr std::int32_t get_months() const noexcept { return months; }
59
63 constexpr std::int32_t get_days() const noexcept { return days; }
64
71 constexpr int compare(const ignite_period &other) const noexcept {
72 if (years != other.years) {
73 return years - other.years;
74 }
75 if (months != other.months) {
76 return months - other.months;
77 }
78 return days - other.days;
79 }
80
81private:
82 std::int_least32_t years = 0;
83 std::int_least32_t months = 0;
84 std::int_least32_t days = 0;
85};
86
94constexpr bool operator==(const ignite_period &lhs, const ignite_period &rhs) noexcept {
95 return lhs.compare(rhs) == 0;
96}
97
105constexpr bool operator!=(const ignite_period &lhs, const ignite_period &rhs) noexcept {
106 return lhs.compare(rhs) != 0;
107}
108
116constexpr bool operator<(const ignite_period &lhs, const ignite_period &rhs) noexcept {
117 return lhs.compare(rhs) < 0;
118}
119
127constexpr bool operator<=(const ignite_period &lhs, const ignite_period &rhs) noexcept {
128 return lhs.compare(rhs) <= 0;
129}
130
138constexpr bool operator>(const ignite_period &lhs, const ignite_period &rhs) noexcept {
139 return lhs.compare(rhs) > 0;
140}
141
149constexpr bool operator>=(const ignite_period &lhs, const ignite_period &rhs) noexcept {
150 return lhs.compare(rhs) >= 0;
151}
152
153} // namespace ignite
A date-based amount of time.
Definition ignite_period.h:29
constexpr std::int32_t get_days() const noexcept
Definition ignite_period.h:63
constexpr std::int32_t get_years() const noexcept
Definition ignite_period.h:53
constexpr ignite_period() noexcept=default
constexpr int compare(const ignite_period &other) const noexcept
Definition ignite_period.h:71
constexpr std::int32_t get_months() const noexcept
Definition ignite_period.h:58