Google Cloud Spanner C++ Client
A C++ Client Library for Google Cloud Spanner
date.h
Go to the documentation of this file.
1 // Copyright 2019 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_SPANNER_DATE_H
16 #define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_SPANNER_DATE_H
17 
19 #include <cstdint>
20 #include <ostream>
21 #include <tuple>
22 
23 namespace google {
24 namespace cloud {
25 namespace spanner {
26 inline namespace SPANNER_CLIENT_NS {
27 
35 class Date {
36  public:
37  Date(std::int64_t year, int month, int day); // Fields will be normalized.
38  Date() : Date(1970, 1, 1) {}
39 
40  std::int64_t year() const { return year_; }
41  int month() const { return month_; }
42  int day() const { return day_; }
43 
44  private:
45  std::int64_t year_;
46  int month_;
47  int day_;
48 };
49 
50 std::ostream& operator<<(std::ostream& os, Date const& date);
51 
52 inline bool operator==(Date const& a, Date const& b) {
53  return std::make_tuple(a.year(), a.month(), a.day()) ==
54  std::make_tuple(b.year(), b.month(), b.day());
55 }
56 
57 inline bool operator!=(Date const& a, Date const& b) { return !(a == b); }
58 
59 inline bool operator<(Date const& a, Date const& b) {
60  return std::make_tuple(a.year(), a.month(), a.day()) <
61  std::make_tuple(b.year(), b.month(), b.day());
62 }
63 
64 inline bool operator<=(Date const& a, Date const& b) { return !(b < a); }
65 
66 inline bool operator>=(Date const& a, Date const& b) { return !(a < b); }
67 
68 inline bool operator>(Date const& a, Date const& b) { return b < a; }
69 
70 } // namespace SPANNER_CLIENT_NS
71 } // namespace spanner
72 } // namespace cloud
73 } // namespace google
74 
75 #endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_SPANNER_DATE_H
bool operator==(Date const &a, Date const &b)
Definition: date.h:52
std::int64_t year() const
Definition: date.h:40
bool operator<=(Date const &a, Date const &b)
Definition: date.h:64
bool operator!=(Date const &a, Date const &b)
Definition: date.h:57
Contains all the Cloud Spanner C++ client types and functions.
bool operator<(Date const &a, Date const &b)
Definition: date.h:59
Represents a date in the proleptic Gregorian calendar as a triple of year, month (1-12),...
Definition: date.h:35
bool operator>(Date const &a, Date const &b)
Definition: date.h:68
#define SPANNER_CLIENT_NS
Definition: version.h:22
bool operator>=(Date const &a, Date const &b)
Definition: date.h:66
std::ostream & operator<<(std::ostream &os, Backup const &bn)
Definition: backup.cc:35