28
28
* Defines the API for dealing with temporal data inside the server.
30
30
* The Temporal class is the base class for all data of any temporal
31
* type. A number of derived classes define specialized classes
31
* type. A number of derived classes define specialized classes
32
32
* representng various date, date-time, time, or timestamp types.
34
34
* All Temporal derived classes are ValueObjects. That is to say that
106
106
/** Returns number of seconds in time components (hour + minute + second) */
107
107
uint64_t _cumulative_seconds_in_time() const;
108
108
/** Resets all temporal components to zero */
109
inline void _reset() {_years= _months= _days= _hours= _minutes= _seconds= _epoch_seconds= _useconds= _nseconds= 0;}
111
_years= _months= _days= _hours= _minutes=
112
_seconds= _epoch_seconds= _useconds= _nseconds= 0;
112
117
virtual ~Temporal() {}
121
126
inline void set_useconds(const uint32_t usecond) {_useconds= usecond;}
122
127
/** Returns the microsseconds component. */
123
128
inline uint32_t useconds() const {return _useconds;}
125
* Sets the epoch_seconds component automatically,
126
* based on the temporal's components.
130
* Sets the epoch_seconds component automatically,
131
* based on the temporal's components.
128
133
void set_epoch_seconds();
129
134
/** Sets the epch_seconds component manually. */
130
inline void set_epoch_seconds(const uint32_t epoch_second) {_epoch_seconds= epoch_second;}
135
inline void set_epoch_seconds(const uint32_t epoch_second)
136
{_epoch_seconds= epoch_second;}
131
137
/** Returns the UNIX epoch seconds component. */
132
138
inline time_t epoch_seconds() const {return _epoch_seconds;}
133
139
/** Sets the seconds component. */
154
160
inline void set_years(const uint32_t year) {_years= year;}
155
161
/** Returns the years component. */
156
162
inline uint32_t years() const {return _years;}
157
/** Returns whether the overflow flag was set (which can occur during an overloaded operator's execution) */
163
/** Returns whether the overflow flag was set
164
* (which can occur during an overloaded operator's execution) */
158
165
inline bool overflow() const {return _overflow;}
160
167
/** Returns whether the temporal value is valid as a date. */
177
184
* All Temporal derived classes must implement
178
185
* conversion routines for converting to and from
179
* a string. Subclasses implement other conversion
186
* a string. Subclasses implement other conversion
180
187
* routines, but should always follow these notes:
182
189
* 1) Ensure that ALL from_xxx methods call is_valid()
212
221
bool operator>=(const Date &rhs);
213
222
bool operator<(const Date &rhs);
214
223
bool operator<=(const Date &rhs);
226
* Comparison operator overloads to compare a Date against
229
* @param DateTime to compare against.
231
bool operator==(const DateTime &rhs);
232
bool operator!=(const DateTime &rhs);
233
bool operator>(const DateTime &rhs);
234
bool operator>=(const DateTime &rhs);
235
bool operator<(const DateTime &rhs);
236
bool operator<=(const DateTime &rhs);
239
* Comparison operator overloads to compare a Date against
242
* @param Timestamp to compare against.
244
bool operator==(const Timestamp &rhs);
245
bool operator!=(const Timestamp &rhs);
246
bool operator>(const Timestamp &rhs);
247
bool operator>=(const Timestamp &rhs);
248
bool operator<(const Timestamp &rhs);
249
bool operator<=(const Timestamp &rhs);
216
252
* Operator overload for adding/subtracting another Date
217
* (or subclass) to/from this temporal. When subtracting
253
* (or subclass) to/from this temporal. When subtracting
218
254
* or adding two Dates, we return a new Date instance.
220
* @param Temporal instance to add/subtract to/from
256
* @param Date instance to add/subtract to/from
222
258
const Date operator-(const Date &rhs);
223
259
const Date operator+(const Date &rhs);
225
261
Date& operator-=(const Date &rhs);
264
* Operator to add/subtract a Time from a Time.
265
* We can return a Time new temporal instance.
267
* @param Temporal instance to add/subtract to/from
269
const Date operator-(const Time &rhs);
270
const Date operator+(const Time &rhs);
271
Date& operator-=(const Time &rhs);
272
Date& operator+=(const Time &rhs);
276
* Operator overload for adding/subtracting a DateTime
277
* (or subclass) to/from this temporal. When subtracting
278
* or adding two Dates, we return a new Date instance.
280
* @param DateTime instance to add/subtract to/from
282
const Date operator-(const DateTime &rhs);
283
const Date operator+(const DateTime &rhs);
284
Date& operator+=(const DateTime &rhs);
285
Date& operator-=(const DateTime &rhs);
289
* Operator overload for adding/subtracting a TemporalInterval
290
* instance to this temporal.
292
* @param TemporalInterval instance to add/subtract to/from
294
Date& operator+=(const TemporalIntervalYear &rhs);
295
Date& operator+=(const TemporalIntervalDayOrLess &rhs);
296
Date& operator+=(const TemporalIntervalDayOrWeek &rhs);
297
Date& operator+=(const TemporalIntervalYearMonth &rhs);
298
Date& operator-=(const TemporalIntervalYear &rhs);
299
Date& operator-=(const TemporalIntervalDayOrLess &rhs);
300
Date& operator-=(const TemporalIntervalDayOrWeek &rhs);
301
Date& operator-=(const TemporalIntervalYearMonth &rhs);
228
305
* Operator overload for when a DateTime instance is
229
306
* assigned to a Date. We do a copy of the DateTime's
230
307
* date-related components.
236
313
virtual bool is_valid_date() const {return is_valid();}
237
314
virtual bool is_valid_datetime() const {return is_valid();}
238
315
virtual bool is_valid_time() const {return false;}
239
virtual bool is_valid_timestamp() const {return is_valid() && in_unix_epoch();}
316
virtual bool is_valid_timestamp() const
318
return is_valid() && in_unix_epoch();
240
321
/** Returns whether the temporal value is valid date. */
241
322
virtual bool is_valid() const;
242
323
/* Returns whether the Date (or subclass) instance is in the Unix Epoch. */
460
541
* Attempts to populate the Time instance based
461
542
* on the contents of a supplied time_t
463
* Returns whether the conversion was
544
* Returns whether the conversion was
468
* We can only convert *from* a time_t, not back
549
* We can only convert *from* a time_t, not back
469
550
* to a time_t since it would be a lossy conversion.
471
552
* @param time_t to convert from
493
575
DateTime() :Date() {}
495
* Comparison operator overloads to compare a DateTime against
496
* another DateTime value.
498
* @param DateTime to compare against.
500
bool operator==(const DateTime &rhs);
501
bool operator!=(const DateTime &rhs);
502
bool operator>(const DateTime &rhs);
503
bool operator>=(const DateTime &rhs);
504
bool operator<(const DateTime &rhs);
505
bool operator<=(const DateTime &rhs);
507
* Operator to add/subtract a Time from a Time.
508
* We can return a Time new temporal instance.
510
* @param Temporal instance to add/subtract to/from
512
const DateTime operator-(const Time &rhs);
513
const DateTime operator+(const Time &rhs);
514
DateTime& operator-=(const Time &rhs);
515
DateTime& operator+=(const Time &rhs);
517
* Operator overload for adding/subtracting another DateTime
518
* (or subclass) to/from this temporal. When subtracting
519
* or adding two DateTimes, we return a new DateTime instance.
521
* @param Temporal instance to add/subtract to/from
523
const DateTime operator-(const DateTime &rhs);
524
const DateTime operator+(const DateTime &rhs);
525
DateTime& operator+=(const DateTime &rhs);
526
DateTime& operator-=(const DateTime &rhs);
529
* Operator overload for adding/subtracting a TemporalInterval
530
* instance to this temporal.
532
* @param TemporalInterval instance to add/subtract to/from
534
DateTime& operator+=(const TemporalIntervalYear &rhs);
535
DateTime& operator+=(const TemporalIntervalDayOrLess &rhs);
536
DateTime& operator+=(const TemporalIntervalDayOrWeek &rhs);
537
DateTime& operator+=(const TemporalIntervalYearMonth &rhs);
538
DateTime& operator-=(const TemporalIntervalYear &rhs);
539
DateTime& operator-=(const TemporalIntervalDayOrLess &rhs);
540
DateTime& operator-=(const TemporalIntervalDayOrWeek &rhs);
541
DateTime& operator-=(const TemporalIntervalYearMonth &rhs);
543
577
friend class TemporalInterval;
545
/* Returns whether the DateTime (or subclass) instance is in the Unix Epoch. */
579
/** Returns whether the DateTime (or subclass) instance
580
* is in the Unix Epoch.
546
582
bool in_unix_epoch() const;
547
583
/** Returns whether the temporal value is valid datetime. */
548
584
virtual bool is_valid() const;
551
* It's not possible to convert to and from a DateTime and
587
* It's not possible to convert to and from a DateTime and
552
588
* a 4-byte integer, so let us know if we try and do it!
554
590
void to_int32_t(int32_t *) const {assert(0);}
629
665
* Class representing temporal components in the UNIX epoch
631
class Timestamp: public DateTime
667
class Timestamp: public DateTime
634
670
Timestamp() :DateTime() {}
636
* Comparison operator overloads to compare a Timestamp against
637
* another Timestamp value.
639
* @param Timestamp to compare against.
641
bool operator==(const Timestamp &rhs);
642
bool operator!=(const Timestamp &rhs);
643
bool operator>(const Timestamp &rhs);
644
bool operator>=(const Timestamp &rhs);
645
bool operator<(const Timestamp &rhs);
646
bool operator<=(const Timestamp &rhs);
648
672
bool is_valid_timestamp() const {return is_valid();}
649
673
/** Returns whether the temporal value is valid timestamp. */