6 #ifndef ACE_TIME_DATE_TUPLE_H
7 #define ACE_TIME_DATE_TUPLE_H
10 #include "common/logging.h"
11 #include "local_date_mutation.h"
13 #ifndef ACE_TIME_EXTENDED_ZONE_PROCESSOR_DEBUG
14 #define ACE_TIME_EXTENDED_ZONE_PROCESSOR_DEBUG 0
24 enum class CompareStatus : uint8_t {
39 DateTuple(int16_t y, uint8_t mon, uint8_t d, int16_t min, uint8_t mod):
40 year(y), month(mon), day(d), suffix(mod), minutes(min) {}
50 if (ACE_TIME_EXTENDED_ZONE_PROCESSOR_DEBUG) {
51 int hour = minutes / 60;
52 int minute = minutes - hour * 60;
53 char c =
"wsu"[(suffix>>4)];
54 logging::printf(
"%04d-%02u-%02uT%02d:%02d%c",
55 year, month, day, hour, minute, c);
61 inline bool operator<(
const DateTuple& a,
const DateTuple& b) {
62 if (a.year < b.year)
return true;
63 if (a.year > b.year)
return false;
64 if (a.month < b.month)
return true;
65 if (a.month > b.month)
return false;
66 if (a.day < b.day)
return true;
67 if (a.day > b.day)
return false;
68 if (a.minutes < b.minutes)
return true;
69 if (a.minutes > b.minutes)
return false;
73 inline bool operator>=(
const DateTuple& a,
const DateTuple& b) {
77 inline bool operator<=(
const DateTuple& a,
const DateTuple& b) {
81 inline bool operator>(
const DateTuple& a,
const DateTuple& b) {
86 inline bool operator==(
const DateTuple& a,
const DateTuple& b) {
87 return a.year == b.year
90 && a.minutes == b.minutes
91 && a.suffix == b.suffix;
95 inline void normalizeDateTuple(DateTuple* dt) {
96 const int16_t kOneDayAsMinutes = 60 * 24;
97 if (dt->minutes <= -kOneDayAsMinutes) {
99 local_date_mutation::decrementOneDay(ld);
100 dt->year = ld.year();
101 dt->month = ld.month();
103 dt->minutes += kOneDayAsMinutes;
104 }
else if (kOneDayAsMinutes <= dt->minutes) {
106 local_date_mutation::incrementOneDay(ld);
107 dt->year = ld.year();
108 dt->month = ld.month();
110 dt->minutes -= kOneDayAsMinutes;
122 inline acetime_t subtractDateTuple(
const DateTuple& a,
const DateTuple& b) {
132 return (epochDaysA - epochDaysB) * 86400 + (a.minutes - b.minutes) * 60;
147 inline CompareStatus compareDateTupleFuzzy(
149 const DateTuple& start,
150 const DateTuple& until) {
153 int32_t tMonths = t.year * (int32_t) 12 + t.month;
154 int32_t startMonths = start.year * (int32_t) 12 + start.month;
155 if (tMonths < startMonths - 1)
return CompareStatus::kPrior;
156 int32_t untilMonths = until.year * 12 + until.month;
157 if (untilMonths + 1 < tMonths)
return CompareStatus::kFarFuture;
158 return CompareStatus::kWithinMatch;
static LocalDate forComponents(int16_t year, uint8_t month, uint8_t day)
Factory method using separated year, month and day fields.
int32_t toEpochDays() const
Return number of days since the current epoch year sCurrentEpochYear.
int32_t acetime_t
Type for the number of seconds from epoch.
A tuple that represents a date and time.
void log() const
Used only for debugging.