00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #pragma once
00025
00026
00027 #include <drizzled/item.h>
00028 #include <drizzled/type/time.h>
00029
00030 namespace drizzled
00031 {
00032
00037 class TemporalInterval
00038 {
00039 public:
00040
00041 TemporalInterval(uint32_t in_year,
00042 uint32_t in_month,
00043 uint32_t in_day,
00044 uint32_t in_hour,
00045 uint64_t in_minute,
00046 uint64_t in_second,
00047 uint64_t in_second_part,
00048 bool in_neg) :
00049 year(in_year),
00050 month(in_month),
00051 day(in_day),
00052 hour(in_hour),
00053 minute(in_minute),
00054 second(in_second),
00055 second_part(in_second_part),
00056 neg(in_neg)
00057 {}
00058
00059 TemporalInterval() :
00060 year(0),
00061 month(0),
00062 day(0),
00063 hour(0),
00064 minute(0),
00065 second(0),
00066 second_part(0),
00067 neg(false)
00068 {}
00069
00074 inline void setNegative(bool in_neg= true)
00075 {
00076 neg= in_neg;
00077 }
00078
00082 inline void toggleNegative()
00083 {
00084 neg= !neg;
00085 }
00086
00091 inline bool getNegative() const
00092 {
00093 return neg;
00094 }
00095
00096 inline uint32_t get_year() { return year; }
00097 inline void set_year(uint32_t new_year) { year = new_year; }
00098
00099 inline uint32_t get_month(){ return month; }
00100 inline void set_month(uint32_t new_month) { month = new_month; }
00101
00102 inline uint32_t get_day(){ return day; }
00103 inline void set_day(uint32_t new_day) { day = new_day; }
00104
00105 inline uint32_t get_hour(){ return hour; }
00106 inline void set_hour(uint32_t new_hour) { hour = new_hour; }
00107
00108 inline uint64_t get_minute(){ return minute; }
00109 inline void set_minute(uint32_t new_minute) { minute = new_minute; }
00110
00111 inline uint64_t get_second(){ return second; }
00112 inline void set_second(uint32_t new_second) { second = new_second; }
00113
00114 inline uint64_t get_second_part(){ return second_part; }
00115 inline void set_second_part(uint32_t new_second_part) { second_part = new_second_part; }
00116
00128 bool initFromItem(Item *args, interval_type int_type, String *str_value);
00129
00138 bool addDate(type::Time *ltime, interval_type int_type);
00139
00140 private:
00141
00145 static const uint32_t MAX_STRING_ELEMENTS = 5;
00146
00150 static const uint32_t NUM_YEAR_MONTH_STRING_ELEMENTS = 2;
00151 static const uint32_t NUM_DAY_HOUR_STRING_ELEMENTS = 2;
00152 static const uint32_t NUM_DAY_MICROSECOND_STRING_ELEMENTS = 5;
00153 static const uint32_t NUM_DAY_MINUTE_STRING_ELEMENTS = 3;
00154 static const uint32_t NUM_DAY_SECOND_STRING_ELEMENTS = 4;
00155 static const uint32_t NUM_HOUR_MICROSECOND_STRING_ELEMENTS = 4;
00156 static const uint32_t NUM_HOUR_MINUTE_STRING_ELEMENTS = 2;
00157 static const uint32_t NUM_HOUR_SECOND_STRING_ELEMENTS = 3;
00158 static const uint32_t NUM_MINUTE_MICROSECOND_STRING_ELEMENTS = 3;
00159 static const uint32_t NUM_MINUTE_SECOND_STRING_ELEMENTS = 2;
00160 static const uint32_t NUM_SECOND_MICROSECOND_STRING_ELEMENTS = 2;
00161
00180 bool getIntervalFromString(const char *str,
00181 uint32_t length,
00182 const CHARSET_INFO * const cs,
00183 uint32_t count,
00184 uint64_t *values,
00185 bool transform_msec);
00186
00187 uint32_t year;
00188 uint32_t month;
00189 uint32_t day;
00190 uint32_t hour;
00191 uint64_t minute;
00192 uint64_t second;
00193 uint64_t second_part;
00194 bool neg;
00195
00196 };
00197
00198 }
00199