MCPcopy Create free account
hub / github.com/apache/impala / ParseDateTime

Method ParseDateTime

be/src/runtime/datetime-simple-date-format-parser.cc:431–536  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

429}
430
431bool SimpleDateFormatParser::ParseDateTime(const char* str, int str_len,
432 const DateTimeFormatContext& dt_ctx, DateTimeParseResult* dt_result) {
433 DCHECK(dt_ctx.fmt_len > 0);
434 DCHECK(dt_ctx.toks.size() > 0);
435 DCHECK(dt_result != NULL);
436 if (str_len <= 0 || str_len < dt_ctx.fmt_len || str == NULL) return false;
437 StringParser::ParseResult status;
438 // Keep track of the number of characters we need to shift token positions by.
439 // Variable-length tokens will result in values > 0;
440 int shift_len = 0;
441 for (const DateTimeFormatToken& tok: dt_ctx.toks) {
442 const char* tok_val = str + tok.pos + shift_len;
443 if (tok.type == SEPARATOR) {
444 if (UNLIKELY(*tok_val != *tok.val)) return false;
445 continue;
446 }
447 int tok_len = tok.len;
448 const char* str_end = str + str_len;
449 // In case of single-character tokens we scan ahead to the next separator.
450 if (UNLIKELY(tok_len == 1)) {
451 while ((tok_val + tok_len < str_end) && isdigit(*(tok_val + tok_len))) {
452 ++tok_len;
453 ++shift_len;
454 }
455 }
456 switch (tok.type) {
457 case YEAR: {
458 if (!ParseAndValidate(tok_val, tok_len, 0, 9999, &dt_result->year)) return false;
459 // Year in "Y" and "YY" format should be in the interval
460 // [current time - 80 years, current time + 20 years)
461 if (tok_len <= 2) dt_result->realign_year = true;
462 break;
463 }
464 case MONTH_IN_YEAR: {
465 if (!ParseAndValidate(tok_val, tok_len, 1, 12, &dt_result->month)) return false;
466 break;
467 }
468 case MONTH_NAME_SHORT: {
469 const char* tok_end = tok_val + tok_len;
470 if (!ParseMonthNameToken(tok, tok_val, &tok_end, dt_ctx.fx_modifier,
471 &dt_result->month)) {
472 return false;
473 }
474 break;
475 }
476 case DAY_IN_MONTH: {
477 if (!ParseAndValidate(tok_val, tok_len, 1, 31, &dt_result->day)) return false;
478 break;
479 }
480 case HOUR_IN_DAY: {
481 if (!ParseAndValidate(tok_val, tok_len, 0, 23, &dt_result->hour)) return false;
482 break;
483 }
484 case MINUTE_IN_HOUR: {
485 if (!ParseAndValidate(tok_val, tok_len, 0, 59, &dt_result->minute)) return false;
486 break;
487 }
488 case SECOND_IN_MINUTE: {

Callers

nothing calls this directly

Calls 5

ParseAndValidateFunction · 0.85
ParseMonthNameTokenFunction · 0.85
ParseFractionTokenFunction · 0.85
time_durationClass · 0.85
sizeMethod · 0.45

Tested by

no test coverage detected