21
23
#include <drizzled/item.h>
26
* Stores time interval for date/time manipulation
28
class TemporalInterval
32
TemporalInterval(uint32_t in_year,
38
uint64_t in_second_part,
47
second_part(in_second_part),
64
* Sets whether or not this object specifies a negative interval
65
* @param[in] in_neg true if this is a negative interval, false if not
67
void setNegative(bool in_neg= true)
73
* reverse boolean value of the negative flag
81
* @retval true this is a negative temporal interval
82
* @retval false this is a positive temporal interval
84
bool getNegative() const
90
* Populate this TemporalInterval from a string value
92
* To make code easy, allow interval objects without separators.
94
* @param args argument Item structure
95
* @param int_type type of interval to create
96
* @param str_value String pointer to the input value
97
* @return true if the string would result in a null interval
100
bool initFromItem(Item *args, interval_type int_type, String *str_value);
103
* Adds this interval to a DRIZZLE_LTIME structure
105
* @param[in,out] ltime the interval will be added to ltime directly in the ltime structure
106
* @param[in] int_type the type of interval requested
107
* @retval true date was added and value stored properly
108
* @retval false result of addition is a null value
110
bool addDate(DRIZZLE_TIME *ltime, interval_type int_type);
115
* The maximum number of text elements to extract into a temporal interval
117
static const uint32_t MAX_STRING_ELEMENTS = 5;
120
* Each of these corresponds to an 'interval_type'
122
static const uint32_t NUM_YEAR_MONTH_STRING_ELEMENTS = 2;
123
static const uint32_t NUM_DAY_HOUR_STRING_ELEMENTS = 2;
124
static const uint32_t NUM_DAY_MICROSECOND_STRING_ELEMENTS = 5;
125
static const uint32_t NUM_DAY_MINUTE_STRING_ELEMENTS = 3;
126
static const uint32_t NUM_DAY_SECOND_STRING_ELEMENTS = 4;
127
static const uint32_t NUM_HOUR_MICROSECOND_STRING_ELEMENTS = 4;
128
static const uint32_t NUM_HOUR_MINUTE_STRING_ELEMENTS = 2;
129
static const uint32_t NUM_HOUR_SECOND_STRING_ELEMENTS = 3;
130
static const uint32_t NUM_MINUTE_MICROSECOND_STRING_ELEMENTS = 3;
131
static const uint32_t NUM_MINUTE_SECOND_STRING_ELEMENTS = 2;
132
static const uint32_t NUM_SECOND_MICROSECOND_STRING_ELEMENTS = 2;
136
* Get a array of positive numbers from a string object.
137
* Each number is separated by 1 non digit character
138
* Return error if there is too many numbers.
139
* If there is too few numbers, assume that the numbers are left out
140
* from the high end. This allows one to give:
141
* DAY_TO_SECOND as "D MM:HH:SS", "MM:HH:SS" "HH:SS" or as seconds.
143
* @param[in] length: length of str
144
* @param[in] cs: charset of str
145
* @param[out] values: array of results
146
* @param[out] count: count of elements in result array
147
* @param transform_msec: if value is true we suppose
148
* that the last part of string value is microseconds
149
* and we should transform value to six digit value.
150
* For example, '1.1' -> '1.100000'
152
bool getIntervalFromString(const char *str,uint32_t length, const CHARSET_INFO * const cs,
153
uint32_t count, uint64_t *values,
154
bool transform_msec);
162
uint64_t second_part;
30
* Stores time interval for date/time manipulation
32
class TemporalInterval
36
TemporalInterval(uint32_t in_year,
42
uint64_t in_second_part,
51
second_part(in_second_part),
68
* Sets whether or not this object specifies a negative interval
69
* @param[in] in_neg true if this is a negative interval, false if not
71
void setNegative(bool in_neg= true)
77
* reverse boolean value of the negative flag
85
* @retval true this is a negative temporal interval
86
* @retval false this is a positive temporal interval
88
bool getNegative() const
94
* Populate this TemporalInterval from a string value
96
* To make code easy, allow interval objects without separators.
98
* @param args argument Item structure
99
* @param int_type type of interval to create
100
* @param str_value String pointer to the input value
101
* @return true if the string would result in a null interval
104
bool initFromItem(Item *args, interval_type int_type, String *str_value);
107
* Adds this interval to a DRIZZLE_LTIME structure
109
* @param[in,out] ltime the interval will be added to ltime directly in the ltime structure
110
* @param[in] int_type the type of interval requested
111
* @retval true date was added and value stored properly
112
* @retval false result of addition is a null value
114
bool addDate(DRIZZLE_TIME *ltime, interval_type int_type);
119
* The maximum number of text elements to extract into a temporal interval
121
static const uint32_t MAX_STRING_ELEMENTS = 5;
124
* Each of these corresponds to an 'interval_type'
126
static const uint32_t NUM_YEAR_MONTH_STRING_ELEMENTS = 2;
127
static const uint32_t NUM_DAY_HOUR_STRING_ELEMENTS = 2;
128
static const uint32_t NUM_DAY_MICROSECOND_STRING_ELEMENTS = 5;
129
static const uint32_t NUM_DAY_MINUTE_STRING_ELEMENTS = 3;
130
static const uint32_t NUM_DAY_SECOND_STRING_ELEMENTS = 4;
131
static const uint32_t NUM_HOUR_MICROSECOND_STRING_ELEMENTS = 4;
132
static const uint32_t NUM_HOUR_MINUTE_STRING_ELEMENTS = 2;
133
static const uint32_t NUM_HOUR_SECOND_STRING_ELEMENTS = 3;
134
static const uint32_t NUM_MINUTE_MICROSECOND_STRING_ELEMENTS = 3;
135
static const uint32_t NUM_MINUTE_SECOND_STRING_ELEMENTS = 2;
136
static const uint32_t NUM_SECOND_MICROSECOND_STRING_ELEMENTS = 2;
140
* Get a array of positive numbers from a string object.
141
* Each number is separated by 1 non digit character
142
* Return error if there is too many numbers.
143
* If there is too few numbers, assume that the numbers are left out
144
* from the high end. This allows one to give:
145
* DAY_TO_SECOND as "D MM:HH:SS", "MM:HH:SS" "HH:SS" or as seconds.
147
* @param[in] length: length of str
148
* @param[in] cs: charset of str
149
* @param[out] values: array of results
150
* @param[out] count: count of elements in result array
151
* @param transform_msec: if value is true we suppose
152
* that the last part of string value is microseconds
153
* and we should transform value to six digit value.
154
* For example, '1.1' -> '1.100000'
156
bool getIntervalFromString(const char *str,
158
const CHARSET_INFO * const cs,
161
bool transform_msec);
169
uint64_t second_part;
174
} /* end namespace drizzled */