44#define DRIZZLE_MAX_SECONDS 59
45#define DRIZZLE_MAX_SECONDS_WITH_LEAP 61
46#define DRIZZLE_MAX_MINUTES 59
47#define DRIZZLE_MAX_HOURS 23
48#define DRIZZLE_MAX_DAYS 31
49#define DRIZZLE_MAX_MONTHS 12
50#define DRIZZLE_MAX_YEARS_SQL 9999
51#define DRIZZLE_MAX_YEARS_EPOCH 2038
52#define DRIZZLE_MIN_SECONDS 0
53#define DRIZZLE_MIN_MINUTES 0
54#define DRIZZLE_MIN_HOURS 0
55#define DRIZZLE_MIN_DAYS 1
56#define DRIZZLE_MIN_MONTHS 1
57#define DRIZZLE_MIN_YEARS_SQL 1
58#define DRIZZLE_MIN_YEARS_EPOCH 1970
60#define DRIZZLE_SECONDS_IN_MINUTE 60
61#define DRIZZLE_SECONDS_IN_HOUR (60*60)
62#define DRIZZLE_SECONDS_IN_DAY (60*60*24)
63#define DRIZZLE_NANOSECONDS_IN_MICROSECOND 1000
65#define DRIZZLE_MAX_LENGTH_DATETIME_AS_STRING 40
67#define DRIZZLE_YY_PART_YEAR 70
70#include <drizzled/common_fwd.h>
89 time_t _epoch_seconds;
99 _years= _months= _days= _hours= _minutes=
100 _seconds= _epoch_seconds= _useconds= _nseconds= 0;
112 inline uint32_t
nseconds()
const {
return _nseconds;}
116 inline uint32_t
useconds()
const {
return _useconds;}
121 void set_epoch_seconds();
124 {_epoch_seconds= epoch_second;}
128 inline void set_seconds(
const uint32_t second) {_seconds= second;}
130 inline uint32_t
seconds()
const {
return _seconds;}
132 inline void set_minutes(
const uint32_t minute) {_minutes= minute;}
134 inline uint32_t
minutes()
const {
return _minutes;}
136 inline void set_hours(
const uint32_t hour) {_hours= hour;}
138 inline uint32_t
hours()
const {
return _hours;}
140 inline void set_days(
const uint32_t day) {_days= day;}
142 inline uint32_t
days()
const {
return _days;}
144 inline void set_months(
const uint32_t month) {_months= month;}
146 inline uint32_t
months()
const {
return _months;}
148 inline void set_years(
const uint32_t year) {_years= year;}
150 inline uint32_t
years()
const {
return _years;}
194 Date() :Temporal() {}
202 virtual bool operator!=(
const Date &rhs);
203 virtual bool operator>(
const Date &rhs);
204 virtual bool operator>=(
const Date &rhs);
205 virtual bool operator<(
const Date &rhs);
206 virtual bool operator<=(
const Date &rhs);
215 virtual bool operator!=(
const DateTime &rhs);
216 virtual bool operator>(
const DateTime &rhs);
217 virtual bool operator>=(
const DateTime &rhs);
218 virtual bool operator<(
const DateTime &rhs);
219 virtual bool operator<=(
const DateTime &rhs);
227 virtual bool operator==(
const Timestamp &rhs);
228 virtual bool operator!=(
const Timestamp &rhs);
229 virtual bool operator>(
const Timestamp &rhs);
230 virtual bool operator>=(
const Timestamp &rhs);
231 virtual bool operator<(
const Timestamp &rhs);
232 virtual bool operator<=(
const Timestamp &rhs);
244 Date& operator-=(
const Date &rhs);
254 Date& operator-=(
const Time &rhs);
268 Date& operator-=(
const DateTime &rhs);
285 return is_valid() && in_unix_epoch();
289 virtual bool is_valid()
const;
291 virtual bool in_unix_epoch()
const;
304 virtual int to_string(
char *to,
size_t to_len)
const;
322 virtual bool from_string(
const char *from,
size_t from_len);
386 virtual void to_tm(
struct tm *to)
const;
398 virtual bool from_tm(
const struct tm *from);
406 virtual void to_time_t(time_t &to)
const;
427 friend class TemporalInterval;
428 friend class Timestamp;
441 Time() :Temporal() {}
443 static const uint32_t MAX_CUMULATIVE_SECONDS= 86400L;
452 bool operator!=(
const Time &rhs);
453 bool operator>(
const Time &rhs);
454 bool operator>=(
const Time &rhs);
455 bool operator<(
const Time &rhs);
456 bool operator<=(
const Time &rhs);
474 bool is_valid()
const;
475 bool is_fuzzy_valid()
const;
488 int to_string(
char *to,
size_t to_len)
const;
507 bool from_string(
const char *from,
size_t from_len);
563 friend class DateTime;
573 DateTime() :Date() {}
575 friend class TemporalInterval;
602 virtual int to_string(
char *to,
size_t to_len)
const;
620 bool from_string(
const char *from,
size_t from_len);
641 bool from_timeval(
struct timeval &_timeval);
667 void to_tm(
struct tm *to)
const;
686 Timestamp() :DateTime() {}
695 bool operator!=(
const Date &rhs);
696 bool operator>(
const Date &rhs);
697 bool operator>=(
const Date &rhs);
698 bool operator<(
const Date &rhs);
699 bool operator<=(
const Date &rhs);
708 bool operator!=(
const DateTime &rhs);
709 bool operator>(
const DateTime &rhs);
710 bool operator>=(
const DateTime &rhs);
711 bool operator<(
const DateTime &rhs);
712 bool operator<=(
const DateTime &rhs);
721 bool operator!=(
const Timestamp &rhs);
722 bool operator>(
const Timestamp &rhs);
723 bool operator>=(
const Timestamp &rhs);
724 bool operator<(
const Timestamp &rhs);
725 bool operator<=(
const Timestamp &rhs);
729 virtual bool is_valid()
const;
737 void to_time_t(time_t &to)
const;
743std::ostream& operator<<(std::ostream& os,
const Timestamp& subject);
752 MicroTimestamp() :Timestamp() {}
767 int to_string(
char *to,
size_t to_len)
const;
795 NanoTimestamp() :Timestamp() {}
bool in_unix_epoch() const
bool from_string(const char *from, size_t from_len)
bool from_int64_t(const int64_t from, bool convert)
void to_int64_t(int64_t *to) const
virtual bool is_valid() const
bool from_int32_t(int32_t)
void to_int32_t(int32_t *) const
static const int MAX_STRING_LENGTH
bool from_time_t(const time_t from)
virtual bool from_time_t(const time_t from)
bool from_julian_day_number(const int64_t from)
virtual void to_decimal(type::Decimal *to) const
virtual bool is_valid_datetime() const
static const int MAX_STRING_LENGTH
virtual void to_time_t(time_t &to) const
virtual void to_int32_t(int32_t *to) const
virtual void to_int64_t(int64_t *to) const
const Date operator-(const Date &rhs)
virtual bool from_string(const char *from, size_t from_len)
void to_julian_day_number(int64_t *to) const
virtual bool is_valid_date() const
virtual bool from_int32_t(const int32_t from)
const Date operator+(const Date &rhs)
Date & operator+=(const Date &rhs)
virtual bool is_valid_time() const
virtual bool operator==(const Date &rhs)
virtual bool is_valid_timestamp() const
Date & operator=(const DateTime &rhs)
virtual void to_tm(struct tm *to) const
virtual bool from_tm(const struct tm *from)
virtual bool is_valid() const
static const int MAX_STRING_LENGTH
int to_string(char *to, size_t to_len) const
void to_timeval(struct timeval &to) const
void to_timespec(struct timespec *to) const
virtual bool is_valid_date() const =0
uint32_t useconds() const
friend class TemporalFormat
virtual bool is_valid() const =0
void set_useconds(const uint32_t usecond)
uint32_t nseconds() const
void set_seconds(const uint32_t second)
void set_nseconds(const uint32_t nsecond)
void set_hours(const uint32_t hour)
virtual bool is_valid_timestamp() const =0
void set_days(const uint32_t day)
time_t epoch_seconds() const
void set_minutes(const uint32_t minute)
enum calendar calendar() const
virtual bool is_valid_time() const =0
void set_months(const uint32_t month)
void set_epoch_seconds(const uint32_t epoch_second)
virtual bool is_valid_datetime() const =0
uint64_t _cumulative_seconds_in_time() const
void set_years(const uint32_t year)
bool from_time_t(const time_t from)
bool is_valid_timestamp() const
void to_uint64_t(uint64_t &to) const
bool is_valid_date() const
static const int MAX_STRING_LENGTH
bool operator==(const Time &rhs)
Time & operator+=(const Time &rhs)
bool is_valid_datetime() const
const Time operator-(const Time &rhs)
void to_int32_t(int32_t *to) const
bool is_valid_time() const
void to_decimal(type::Decimal *to) const
const Time operator+(const Time &rhs)
Time & operator-=(const Time &rhs)
bool from_int32_t(const int32_t from)
bool from_string(const char *from, size_t from_len)
bool is_valid_timestamp() const
bool operator==(const Date &rhs)
virtual bool is_valid() const
TODO: Rename this file - func.h is stupid.