50
50
// Otherwise we must convert to a string and extract the multiple parts
52
if (!(res=args->val_str(str_value)))
52
if (!(res= args->val_str(str_value)))
55
55
// record negative intervalls in interval->neg
57
const char *end=str+res->length();
57
const char *end= str+res->length();
58
58
// Skip the whitespace
59
59
while (str != end && my_isspace(cs,*str))
61
61
if (str != end && *str == '-')
67
67
length= (size_t) (end-str); // Set up pointers to new str
74
case INTERVAL_QUARTER:
75
month= (ulong)(value*3);
81
day= (ulong)(value*7);
89
case INTERVAL_MICROSECOND:
98
case INTERVAL_YEAR_MONTH: // Allow YEAR-MONTH YYYYYMM
99
if (getIntervalInfo(str,length,cs,2,array,0))
101
year= (ulong) array[0];
102
month= (ulong) array[1];
104
case INTERVAL_DAY_HOUR:
105
if (getIntervalInfo(str,length,cs,2,array,0))
107
day= (ulong) array[0];
108
hour= (ulong) array[1];
110
case INTERVAL_DAY_MICROSECOND:
111
if (getIntervalInfo(str,length,cs,5,array,1))
113
day= (ulong) array[0];
114
hour= (ulong) array[1];
117
second_part= array[4];
119
case INTERVAL_DAY_MINUTE:
120
if (getIntervalInfo(str,length,cs,3,array,0))
122
day= (ulong) array[0];
123
hour= (ulong) array[1];
126
case INTERVAL_DAY_SECOND:
127
if (getIntervalInfo(str,length,cs,4,array,0))
129
day= (ulong) array[0];
130
hour= (ulong) array[1];
134
case INTERVAL_HOUR_MICROSECOND:
135
if (getIntervalInfo(str,length,cs,4,array,1))
137
hour= (ulong) array[0];
140
second_part= array[3];
142
case INTERVAL_HOUR_MINUTE:
143
if (getIntervalInfo(str,length,cs,2,array,0))
145
hour= (ulong) array[0];
148
case INTERVAL_HOUR_SECOND:
149
if (getIntervalInfo(str,length,cs,3,array,0))
151
hour= (ulong) array[0];
155
case INTERVAL_MINUTE_MICROSECOND:
156
if (getIntervalInfo(str,length,cs,3,array,1))
160
second_part= array[2];
162
case INTERVAL_MINUTE_SECOND:
163
if (getIntervalInfo(str,length,cs,2,array,0))
168
case INTERVAL_SECOND_MICROSECOND:
169
if (getIntervalInfo(str,length,cs,2,array,1))
172
second_part= array[1];
174
case INTERVAL_LAST: // purecov: begin deadcode
176
break; // purecov: end
75
case INTERVAL_QUARTER:
76
month= (ulong)(value*3);
82
day= (ulong)(value*7);
90
case INTERVAL_MICROSECOND:
99
case INTERVAL_YEAR_MONTH: // Allow YEAR-MONTH YYYYYMM
100
if (getIntervalInfo(str,length,cs,2,array,0))
102
year= (ulong) array[0];
103
month= (ulong) array[1];
105
case INTERVAL_DAY_HOUR:
106
if (getIntervalInfo(str,length,cs,2,array,0))
108
day= (ulong) array[0];
109
hour= (ulong) array[1];
111
case INTERVAL_DAY_MICROSECOND:
112
if (getIntervalInfo(str,length,cs,5,array,1))
114
day= (ulong) array[0];
115
hour= (ulong) array[1];
118
second_part= array[4];
120
case INTERVAL_DAY_MINUTE:
121
if (getIntervalInfo(str,length,cs,3,array,0))
123
day= (ulong) array[0];
124
hour= (ulong) array[1];
127
case INTERVAL_DAY_SECOND:
128
if (getIntervalInfo(str,length,cs,4,array,0))
130
day= (ulong) array[0];
131
hour= (ulong) array[1];
135
case INTERVAL_HOUR_MICROSECOND:
136
if (getIntervalInfo(str,length,cs,4,array,1))
138
hour= (ulong) array[0];
141
second_part= array[3];
143
case INTERVAL_HOUR_MINUTE:
144
if (getIntervalInfo(str,length,cs,2,array,0))
146
hour= (ulong) array[0];
149
case INTERVAL_HOUR_SECOND:
150
if (getIntervalInfo(str,length,cs,3,array,0))
152
hour= (ulong) array[0];
156
case INTERVAL_MINUTE_MICROSECOND:
157
if (getIntervalInfo(str,length,cs,3,array,1))
161
second_part= array[2];
163
case INTERVAL_MINUTE_SECOND:
164
if (getIntervalInfo(str,length,cs,2,array,0))
169
case INTERVAL_SECOND_MICROSECOND:
170
if (getIntervalInfo(str,length,cs,2,array,1))
173
second_part= array[1];
175
case INTERVAL_LAST: // purecov: begin deadcode
177
break; // purecov: end
187
188
sign= (neg ? -1 : 1);
190
case INTERVAL_SECOND:
191
case INTERVAL_SECOND_MICROSECOND:
192
case INTERVAL_MICROSECOND:
193
case INTERVAL_MINUTE:
195
case INTERVAL_MINUTE_MICROSECOND:
196
case INTERVAL_MINUTE_SECOND:
197
case INTERVAL_HOUR_MICROSECOND:
198
case INTERVAL_HOUR_SECOND:
199
case INTERVAL_HOUR_MINUTE:
200
case INTERVAL_DAY_MICROSECOND:
201
case INTERVAL_DAY_SECOND:
202
case INTERVAL_DAY_MINUTE:
203
case INTERVAL_DAY_HOUR:
205
int64_t sec, days, daynr, microseconds, extra_sec;
206
ltime->time_type= DRIZZLE_TIMESTAMP_DATETIME; // Return full date
207
microseconds= ltime->second_part + sign*second_part;
208
extra_sec= microseconds/1000000L;
209
microseconds= microseconds%1000000L;
192
case INTERVAL_SECOND:
193
case INTERVAL_SECOND_MICROSECOND:
194
case INTERVAL_MICROSECOND:
195
case INTERVAL_MINUTE:
197
case INTERVAL_MINUTE_MICROSECOND:
198
case INTERVAL_MINUTE_SECOND:
199
case INTERVAL_HOUR_MICROSECOND:
200
case INTERVAL_HOUR_SECOND:
201
case INTERVAL_HOUR_MINUTE:
202
case INTERVAL_DAY_MICROSECOND:
203
case INTERVAL_DAY_SECOND:
204
case INTERVAL_DAY_MINUTE:
205
case INTERVAL_DAY_HOUR:
206
int64_t sec, days, daynr, microseconds, extra_sec;
207
ltime->time_type= DRIZZLE_TIMESTAMP_DATETIME; // Return full date
208
microseconds= ltime->second_part + sign*second_part;
209
extra_sec= microseconds/1000000L;
210
microseconds= microseconds%1000000L;
211
sec=((ltime->day-1)*3600*24L+ltime->hour*3600+ltime->minute*60+
213
sign* (int64_t) (day*3600*24L +
214
hour*3600L+minute*60L+
216
if (microseconds < 0)
218
microseconds+= 1000000L;
221
days= sec/(3600*24L);
228
ltime->second_part= (uint32_t) microseconds;
229
ltime->second= (uint32_t) (sec % 60);
230
ltime->minute= (uint32_t) (sec/60 % 60);
231
ltime->hour= (uint32_t) (sec/3600);
232
daynr= calc_daynr(ltime->year,ltime->month,1) + days;
233
/* Day number from year 0 to 9999-12-31 */
234
if ((uint64_t) daynr > MAX_DAY_NUMBER)
236
get_date_from_daynr((long) daynr, <ime->year, <ime->month,
242
period= (calc_daynr(ltime->year,ltime->month,ltime->day) +
244
/* Daynumber from year 0 to 9999-12-31 */
245
if (period > MAX_DAY_NUMBER)
247
get_date_from_daynr((long) period,<ime->year,<ime->month,<ime->day);
250
ltime->year+= sign * (long) year;
251
if (ltime->year >= 10000L)
253
if (ltime->month == 2 && ltime->day == 29 &&
254
calc_days_in_year(ltime->year) != 366)
255
ltime->day=28; // Was leap-year
257
case INTERVAL_YEAR_MONTH:
258
case INTERVAL_QUARTER:
260
period= (ltime->year*12 + sign * (long) year*12 +
261
ltime->month-1 + sign * (long) month);
262
if (period >= 120000L)
264
ltime->year= (uint32_t) (period / 12);
265
ltime->month= (uint32_t) (period % 12L)+1;
266
/* Adjust day if the new month doesn't have enough days */
267
if (ltime->day > days_in_month[ltime->month-1])
269
ltime->day = days_in_month[ltime->month-1];
270
if (ltime->month == 2 && calc_days_in_year(ltime->year) == 366)
271
ltime->day++; // Leap-year
212
sec= ((ltime->day-1)*3600*24L+ltime->hour*3600+ltime->minute*60+
214
sign* (int64_t) (day*3600*24L +
215
hour*3600L+minute*60L+
217
if (microseconds < 0)
219
microseconds+= 1000000L;
222
days= sec/(3600*24L);
229
ltime->second_part= (uint32_t) microseconds;
230
ltime->second= (uint32_t) (sec % 60);
231
ltime->minute= (uint32_t) (sec/60 % 60);
232
ltime->hour= (uint32_t) (sec/3600);
233
daynr= calc_daynr(ltime->year,ltime->month,1) + days;
234
/* Day number from year 0 to 9999-12-31 */
235
if ((uint64_t) daynr > MAX_DAY_NUMBER)
237
get_date_from_daynr((long) daynr, <ime->year, <ime->month,
242
period= (calc_daynr(ltime->year,ltime->month,ltime->day) +
244
/* Daynumber from year 0 to 9999-12-31 */
245
if (period > MAX_DAY_NUMBER)
247
get_date_from_daynr((long) period,<ime->year,<ime->month,<ime->day);
250
ltime->year+= sign * (long) year;
251
if (ltime->year >= 10000L)
253
if (ltime->month == 2 && ltime->day == 29 &&
254
calc_days_in_year(ltime->year) != 366)
255
ltime->day= 28; // Was leap-year
257
case INTERVAL_YEAR_MONTH:
258
case INTERVAL_QUARTER:
260
period= (ltime->year*12 + sign * (long) year*12 +
261
ltime->month-1 + sign * (long) month);
262
if (period >= 120000L)
264
ltime->year= (uint32_t) (period / 12);
265
ltime->month= (uint32_t) (period % 12L)+1;
266
/* Adjust day if the new month doesn't have enough days */
267
if (ltime->day > days_in_month[ltime->month-1])
269
ltime->day= days_in_month[ltime->month-1];
270
if (ltime->month == 2 && calc_days_in_year(ltime->year) == 366)
271
ltime->day++; // Leap-year