81
/* Forward declaration needed */
82
class TemporalInterval;
83
class TemporalIntervalYear;
84
class TemporalIntervalDayOrLess;
85
class TemporalIntervalDayOrWeek;
86
class TemporalIntervalYearMonth;
82
89
* Base class for all temporal data classes.
94
101
time_t _epoch_seconds;
95
102
uint32_t _useconds;
96
103
uint32_t _nseconds;
104
/** Set on some operator overloads. Indicates that an overflow occurred. */
97
106
/** Returns number of seconds in time components (hour + minute + second) */
98
107
uint64_t _cumulative_seconds_in_time() const;
108
/** Resets all temporal components to zero */
109
inline void _reset() {_years= _months= _days= _hours= _minutes= _seconds= _epoch_seconds= _useconds= _nseconds= 0;}
101
112
virtual ~Temporal() {}
103
114
/** Returns the calendar component. */
104
115
inline enum calendar calendar() const {return _calendar;}
116
/** Sets the nseconds component. */
117
inline void set_nseconds(const uint32_t nsecond) {_nseconds= nsecond;}
105
118
/** Returns the nanoseconds component. */
106
119
inline uint32_t nseconds() const {return _nseconds;}
107
120
/** Sets the useconds component. */
108
121
inline void set_useconds(const uint32_t usecond) {_useconds= usecond;}
109
122
/** Returns the microsseconds component. */
110
123
inline uint32_t useconds() const {return _useconds;}
111
/** Sets the epoch_seconds component. */
125
* Sets the epoch_seconds component automatically,
126
* based on the temporal's components.
112
128
virtual void set_epoch_seconds();
129
/** Sets the epch_seconds component manually. */
130
inline void set_epoch_seconds(const uint32_t epoch_second) {_epoch_seconds= epoch_second;}
113
131
/** Returns the UNIX epoch seconds component. */
114
132
inline time_t epoch_seconds() const {return _epoch_seconds;}
115
133
/** Sets the seconds component. */
136
154
inline void set_years(const uint32_t year) {_years= year;}
137
155
/** Returns the years component. */
138
156
inline uint32_t years() const {return _years;}
157
/** Returns whether the overflow flag was set (which can occur during an overloaded operator's execution) */
158
inline bool overflow() const {return _overflow;}
140
160
/** Returns whether the temporal value is valid as a date. */
141
161
virtual bool is_valid_date() const= 0;
166
186
* This minimizes the repeated bounds-checking to
167
187
* just the conversion from_xxx routines.
170
189
friend class TemporalFormat;
192
/* Forward declaration needed */
174
196
* Class representing temporal components in a valid
175
197
* SQL date range, with no time component
184
206
* @param Date to compare against.
186
bool operator==(const Date &rhs);
187
bool operator!=(const Date &rhs);
188
bool operator>(const Date &rhs);
189
bool operator>=(const Date &rhs);
190
bool operator<(const Date &rhs);
191
bool operator<=(const Date &rhs);
208
virtual bool operator==(const Date &rhs);
209
virtual bool operator!=(const Date &rhs);
210
virtual bool operator>(const Date &rhs);
211
virtual bool operator>=(const Date &rhs);
212
virtual bool operator<(const Date &rhs);
213
virtual bool operator<=(const Date &rhs);
193
215
* Operator overload for adding/subtracting another Date
194
216
* (or subclass) to/from this temporal. When subtracting
201
223
Date& operator+=(const Date &rhs);
202
224
Date& operator-=(const Date &rhs);
227
* Operator overload for when a DateTime instance is
228
* assigned to a Date. We do a copy of the DateTime's
229
* date-related components.
231
* @param The DateTime to copy from
233
Date& operator=(const DateTime &rhs);
204
235
virtual bool is_valid_date() const {return is_valid();}
205
236
virtual bool is_valid_datetime() const {return is_valid();}
206
237
virtual bool is_valid_time() const {return false;}
262
293
virtual bool from_int32_t(const int32_t from);
296
* Fills a supplied int64_t with the Julian Day Number
297
* representation of this Date.
299
* @note Julian Day Number != julian day!
301
* Julian Day Number is the monotonically increasing number
302
* of days from the start of the Julian calendar (~4713 B.C.)
304
* julian day is the ordinal day number of a day in a year.
306
* @param int64_t to fill
308
void to_julian_day_number(int64_t *to) const;
265
311
* Attempts to populate the Date instance based
266
312
* on the contents of a supplied Julian Day Number
355
406
Time& operator-=(const Time &rhs);
356
407
Time& operator+=(const Time &rhs);
358
virtual bool is_valid_date() const {return false;}
359
virtual bool is_valid_datetime() const {return false;}
360
virtual bool is_valid_time() const {return is_valid();}
361
virtual bool is_valid_timestamp() const {return false;}
409
bool is_valid_date() const {return false;}
410
bool is_valid_datetime() const {return false;}
411
bool is_valid_time() const {return is_valid();}
412
bool is_valid_timestamp() const {return false;}
362
413
/** Returns whether the temporal value is valid date. */
363
virtual bool is_valid() const;
414
bool is_valid() const;
366
417
* Fills a supplied char string with a
370
421
* @param C-String to fill.
371
422
* @param Length of filled string (out param)
373
virtual void to_string(char *to, size_t *to_len) const;
424
void to_string(char *to, size_t *to_len) const;
376
427
* Attempts to populate the Time instance based
382
433
* @param String to convert from
383
434
* @param Length of supplied string
385
virtual bool from_string(const char *from, size_t from_len);
436
bool from_string(const char *from, size_t from_len);
388
439
* Fills a supplied 4-byte integer pointer with an
403
454
* @param Integer to convert from
405
virtual bool from_int32_t(const int32_t from);
456
bool from_int32_t(const int32_t from);
459
* Attempts to populate the Time instance based
460
* on the contents of a supplied time_t
462
* Returns whether the conversion was
467
* We can only convert *from* a time_t, not back
468
* to a time_t since it would be a lossy conversion.
470
* @param time_t to convert from
472
bool from_time_t(const time_t from);
408
475
* Fills a supplied my_decimal with a representation of
456
523
DateTime& operator+=(const DateTime &rhs);
457
524
DateTime& operator-=(const DateTime &rhs);
527
* Operator overload for adding/subtracting a TemporalInterval
528
* instance to this temporal.
530
* @param TemporalInterval instance to add/subtract to/from
532
DateTime& operator+=(const TemporalIntervalYear &rhs);
533
DateTime& operator+=(const TemporalIntervalDayOrLess &rhs);
534
DateTime& operator+=(const TemporalIntervalDayOrWeek &rhs);
535
DateTime& operator+=(const TemporalIntervalYearMonth &rhs);
536
DateTime& operator-=(const TemporalIntervalYear &rhs);
537
DateTime& operator-=(const TemporalIntervalDayOrLess &rhs);
538
DateTime& operator-=(const TemporalIntervalDayOrWeek &rhs);
539
DateTime& operator-=(const TemporalIntervalYearMonth &rhs);
541
friend class TemporalInterval;
459
543
/* Returns whether the DateTime (or subclass) instance is in the Unix Epoch. */
460
544
bool in_unix_epoch() const;
461
545
/** Returns whether the temporal value is valid datetime. */