| 266 | #define MAX_DATE_PARTS 8 |
| 267 | |
| 268 | my_bool |
| 269 | str_to_datetime(const char *str, uint length, MYSQL_TIME *l_time, |
| 270 | ulonglong flags, MYSQL_TIME_STATUS *status) |
| 271 | { |
| 272 | uint field_length, UNINIT_VAR(year_length), digits, i, number_of_fields; |
| 273 | uint date[MAX_DATE_PARTS], date_len[MAX_DATE_PARTS]; |
| 274 | uint add_hours= 0, start_loop; |
| 275 | ulong not_zero_date, allow_space; |
| 276 | my_bool is_internal_format; |
| 277 | const char *pos, *UNINIT_VAR(last_field_pos); |
| 278 | const char *end=str+length; |
| 279 | const uchar *format_position; |
| 280 | my_bool found_delimitier= 0, found_space= 0; |
| 281 | uint frac_pos, frac_len; |
| 282 | DBUG_ENTER("str_to_datetime"); |
| 283 | DBUG_PRINT("ENTER",("str: %.*s",length,str)); |
| 284 | |
| 285 | LINT_INIT(field_length); |
| 286 | |
| 287 | my_time_status_init(status); |
| 288 | |
| 289 | /* Skip space at start */ |
| 290 | for (; str != end && my_isspace(&my_charset_latin1, *str) ; str++) |
| 291 | ; |
| 292 | if (str == end || ! my_isdigit(&my_charset_latin1, *str)) |
| 293 | { |
| 294 | status->warnings= MYSQL_TIME_WARN_TRUNCATED; |
| 295 | l_time->time_type= MYSQL_TIMESTAMP_NONE; |
| 296 | DBUG_RETURN(1); |
| 297 | } |
| 298 | |
| 299 | is_internal_format= 0; |
| 300 | /* This has to be changed if want to activate different timestamp formats */ |
| 301 | format_position= internal_format_positions; |
| 302 | |
| 303 | /* |
| 304 | Calculate number of digits in first part. |
| 305 | If length= 8 or >= 14 then year is of format YYYY. |
| 306 | (YYYY-MM-DD, YYYYMMDD, YYYYYMMDDHHMMSS) |
| 307 | */ |
| 308 | for (pos=str; |
| 309 | pos != end && (my_isdigit(&my_charset_latin1,*pos) || *pos == 'T'); |
| 310 | pos++) |
| 311 | ; |
| 312 | |
| 313 | digits= (uint) (pos-str); |
| 314 | start_loop= 0; /* Start of scan loop */ |
| 315 | date_len[format_position[0]]= 0; /* Length of year field */ |
| 316 | if (pos == end || *pos == '.') |
| 317 | { |
| 318 | /* Found date in internal format (only numbers like YYYYMMDD) */ |
| 319 | year_length= (digits == 4 || digits == 8 || digits >= 14) ? 4 : 2; |
| 320 | field_length= year_length; |
| 321 | is_internal_format= 1; |
| 322 | format_position= internal_format_positions; |
| 323 | } |
| 324 | else |
| 325 | { |
no test coverage detected