108
108
if (day_of_year > 31+28)
111
if (day_of_year == 31+28)
112
leap_day=1; /* Handle leapyears leapday */
111
if (day_of_year == 31+28)
112
leap_day=1; /* Handle leapyears leapday */
116
116
for (month_pos= days_in_month ;
117
day_of_year > (uint32_t) *month_pos ;
118
day_of_year-= *(month_pos++), (*ret_month)++)
117
day_of_year > (uint32_t) *month_pos ;
118
day_of_year-= *(month_pos++), (*ret_month)++)
121
121
*ret_day=day_of_year+leap_day;
127
type::timestamp_t str_to_datetime_with_warn(Session *session,
127
enum enum_drizzle_timestamp_type
128
str_to_datetime_with_warn(const char *str,
130
DRIZZLE_TIME *l_time,
133
type::cut_t was_cut= type::VALID;
134
type::timestamp_t ts_type;
134
enum enum_drizzle_timestamp_type ts_type;
135
Session *session= current_session;
136
ts_type= l_time->store(str, length,
137
(flags | (session->variables.sql_mode &
138
(MODE_INVALID_DATES |
139
MODE_NO_ZERO_DATE))),
141
if (was_cut || ts_type <= type::DRIZZLE_TIMESTAMP_ERROR)
137
ts_type= str_to_datetime(str, length, l_time,
138
(flags | (session->variables.sql_mode &
139
(MODE_INVALID_DATES |
140
MODE_NO_ZERO_DATE))),
142
if (was_cut || ts_type <= DRIZZLE_TIMESTAMP_ERROR)
142
143
make_truncated_value_warning(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
143
144
str, length, ts_type, NULL);
150
str_to_time_with_warn(Session *session, const char *str, uint32_t length, type::Time *l_time)
150
str_to_time_with_warn(const char *str, uint32_t length, DRIZZLE_TIME *l_time)
153
bool ret_val= l_time->store(str, length, warning, type::DRIZZLE_TIMESTAMP_TIME);
153
bool ret_val= str_to_time(str, length, l_time, &warning);
154
154
if (ret_val || warning)
155
make_truncated_value_warning(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
156
str, length, type::DRIZZLE_TIMESTAMP_TIME, NULL);
155
make_truncated_value_warning(current_session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
156
str, length, DRIZZLE_TIMESTAMP_TIME, NULL);
161
void localtime_to_TIME(DRIZZLE_TIME *to, struct tm *from)
165
to->year= (int) ((from->tm_year+1900) % 10000);
166
to->month= (int) from->tm_mon+1;
167
to->day= (int) from->tm_mday;
168
to->hour= (int) from->tm_hour;
169
to->minute= (int) from->tm_min;
170
to->second= (int) from->tm_sec;
173
void make_time(const DRIZZLE_TIME *l_time, String *str)
175
str->alloc(MAX_DATE_STRING_REP_LENGTH);
176
uint32_t length= (uint32_t) my_time_to_str(l_time, str->c_ptr());
178
str->set_charset(&my_charset_bin);
181
void make_date(const DRIZZLE_TIME *l_time, String *str)
183
str->alloc(MAX_DATE_STRING_REP_LENGTH);
184
uint32_t length= (uint32_t) my_date_to_str(l_time, str->c_ptr());
186
str->set_charset(&my_charset_bin);
190
void make_datetime(const DRIZZLE_TIME *l_time, String *str)
192
str->alloc(MAX_DATE_STRING_REP_LENGTH);
193
uint32_t length= (uint32_t) my_datetime_to_str(l_time, str->c_ptr());
195
str->set_charset(&my_charset_bin);
161
199
void make_truncated_value_warning(Session *session,
162
200
DRIZZLE_ERROR::enum_warning_level level,
163
201
const char *str_val,
164
202
uint32_t str_length,
165
type::timestamp_t time_type,
203
enum enum_drizzle_timestamp_type time_type,
166
204
const char *field_name)
168
206
char warn_buff[DRIZZLE_ERRMSG_SIZE];
200
if (time_type > type::DRIZZLE_TIMESTAMP_ERROR)
235
if (time_type > DRIZZLE_TIMESTAMP_ERROR)
202
236
cs->cset->snprintf(cs, warn_buff, sizeof(warn_buff),
203
237
ER(ER_TRUNCATED_WRONG_VALUE),
204
238
type_str, str.c_ptr());
208
240
cs->cset->snprintf(cs, warn_buff, sizeof(warn_buff),
209
241
ER(ER_WRONG_VALUE), type_str, str.c_ptr());
212
243
push_warning(session, level,
213
244
ER_TRUNCATED_WRONG_VALUE, warn_buff);
227
258
the second argument should be TIMESTAMP_TIME also.
228
259
We should check it before calc_time_diff call.
230
if (l_time1->time_type == type::DRIZZLE_TIMESTAMP_TIME) // Time value
261
if (l_time1->time_type == DRIZZLE_TIMESTAMP_TIME) // Time value
231
262
days= (long)l_time1->day - l_sign * (long)l_time2->day;
234
265
days= calc_daynr((uint32_t) l_time1->year,
235
(uint32_t) l_time1->month,
236
(uint32_t) l_time1->day);
237
if (l_time2->time_type == type::DRIZZLE_TIMESTAMP_TIME)
266
(uint32_t) l_time1->month,
267
(uint32_t) l_time1->day);
268
if (l_time2->time_type == DRIZZLE_TIMESTAMP_TIME)
238
269
days-= l_sign * (long)l_time2->day;
240
271
days-= l_sign*calc_daynr((uint32_t) l_time2->year,
241
(uint32_t) l_time2->month,
242
(uint32_t) l_time2->day);
272
(uint32_t) l_time2->month,
273
(uint32_t) l_time2->day);
245
276
microseconds= ((int64_t)days*86400L +
246
277
(int64_t)(l_time1->hour*3600L +
247
l_time1->minute*60L +
278
l_time1->minute*60L +
249
280
l_sign*(int64_t)(l_time2->hour*3600L +
250
l_time2->minute*60L +
251
l_time2->second)) * 1000000L +
252
(int64_t)l_time1->second_part -
253
l_sign*(int64_t)l_time2->second_part;
281
l_time2->minute*60L +
282
l_time2->second)) * 1000000L +
283
(int64_t)l_time1->second_part -
284
l_sign*(int64_t)l_time2->second_part;
256
287
if (microseconds < 0)