16 #include "google/cloud/spanner/internal/date.h" 26 bool IsLeapYear(std::int64_t y) {
27 return y % 4 == 0 && (y % 100 != 0 || y % 400 == 0);
30 int DaysPerMonth(std::int64_t y,
int m) {
31 static std::array<int, 1 + 12>
const kKDaysPerMonth = {{
32 -1, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
34 return kKDaysPerMonth[m] + (m == 2 && IsLeapYear(y) ? 1 : 0);
39 Date::Date(std::int64_t year,
int month,
int day)
40 : year_(year), month_(month), day_(day) {
47 year_ += (day_ / 146097) * 400;
53 for (
int n = DaysPerMonth(year_, month_); day_ > n;
54 n = DaysPerMonth(year_, month_)) {
64 return os << internal::DateToString(date);
Contains all the Cloud Spanner C++ client types and functions.
Represents a date in the proleptic Gregorian calendar as a triple of year, month (1-12),...
#define SPANNER_CLIENT_NS
std::ostream & operator<<(std::ostream &os, Backup const &bn)