Apache Ignite C++ Client
Loading...
Searching...
No Matches
ignite_date.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_date() noexcept = default;
35
43 constexpr ignite_date(std::int32_t year, std::int32_t month, std::int32_t day_of_month)
44 : m_year(year)
45 , m_month(std::int8_t(month))
46 , m_day(std::int8_t(day_of_month)) {
47 // TODO: check that arguments are in valid ranges.
48 }
49
53 [[nodiscard]] constexpr std::int32_t get_year() const noexcept { return m_year; }
54
58 [[nodiscard]] constexpr std::int_fast8_t get_month() const noexcept { return m_month; }
59
63 [[nodiscard]] constexpr std::int_fast8_t get_day_of_month() const noexcept { return m_day; }
64
71 [[nodiscard]] constexpr int compare(const ignite_date &other) const noexcept {
72 if (m_year != other.m_year) {
73 return m_year - other.m_year;
74 }
75 if (m_month != other.m_month) {
76 return m_month - other.m_month;
77 }
78 return m_day - other.m_day;
79 }
80
81private:
82 std::int_least32_t m_year = 0;
83 std::int_least8_t m_month = 1;
84 std::int_least8_t m_day = 1;
85};
86
94constexpr bool operator==(const ignite_date &lhs, const ignite_date &rhs) noexcept {
95 return lhs.compare(rhs) == 0;
96}
97
105constexpr bool operator!=(const ignite_date &lhs, const ignite_date &rhs) noexcept {
106 return lhs.compare(rhs) != 0;
107}
108
116constexpr bool operator<(const ignite_date &lhs, const ignite_date &rhs) noexcept {
117 return lhs.compare(rhs) < 0;
118}
119
127constexpr bool operator<=(const ignite_date &lhs, const ignite_date &rhs) noexcept {
128 return lhs.compare(rhs) <= 0;
129}
130
138constexpr bool operator>(const ignite_date &lhs, const ignite_date &rhs) noexcept {
139 return lhs.compare(rhs) > 0;
140}
141
149constexpr bool operator>=(const ignite_date &lhs, const ignite_date &rhs) noexcept {
150 return lhs.compare(rhs) >= 0;
151}
152
153} // namespace ignite
A date.
Definition ignite_date.h:29
constexpr ignite_date() noexcept=default
constexpr std::int_fast8_t get_day_of_month() const noexcept
Definition ignite_date.h:63
constexpr std::int32_t get_year() const noexcept
Definition ignite_date.h:53
constexpr std::int_fast8_t get_month() const noexcept
Definition ignite_date.h:58
constexpr int compare(const ignite_date &other) const noexcept
Definition ignite_date.h:71