MCPcopy Create free account
hub / github.com/Meituan-Dianping/SQLAdvisor / str_to_time

Function str_to_time

sql-common/my_time.c:635–834  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

633*/
634
635my_bool str_to_time(const char *str, uint length, MYSQL_TIME *l_time,
636 MYSQL_TIME_STATUS *status)
637{
638 ulong date[5];
639 ulonglong value;
640 const char *end=str+length, *end_of_days;
641 my_bool found_days,found_hours;
642 uint state;
643
644 my_time_status_init(status);
645 l_time->neg=0;
646 for (; str != end && my_isspace(&my_charset_latin1,*str) ; str++)
647 length--;
648 if (str != end && *str == '-')
649 {
650 l_time->neg=1;
651 str++;
652 length--;
653 }
654 if (str == end)
655 return 1;
656
657 /* Check first if this is a full TIMESTAMP */
658 if (length >= 12)
659 { /* Probably full timestamp */
660 (void) str_to_datetime(str, length, l_time,
661 (TIME_FUZZY_DATE | TIME_DATETIME_ONLY), status);
662 if (l_time->time_type >= MYSQL_TIMESTAMP_ERROR)
663 return l_time->time_type == MYSQL_TIMESTAMP_ERROR;
664 my_time_status_init(status);
665 }
666
667 /* Not a timestamp. Try to get this as a DAYS_TO_SECOND string */
668 for (value=0; str != end && my_isdigit(&my_charset_latin1,*str) ; str++)
669 value=value*10L + (long) (*str - '0');
670
671 if (value > UINT_MAX)
672 return 1;
673
674 /* Skip all space after 'days' */
675 end_of_days= str;
676 for (; str != end && my_isspace(&my_charset_latin1, str[0]) ; str++)
677 ;
678
679 LINT_INIT(state);
680 found_days=found_hours=0;
681 if ((uint) (end-str) > 1 && str != end_of_days &&
682 my_isdigit(&my_charset_latin1, *str))
683 { /* Found days part */
684 date[0]= (ulong) value;
685 state= 1; /* Assume next is hours */
686 found_days= 1;
687 }
688 else if ((end-str) > 1 && *str == time_separator &&
689 my_isdigit(&my_charset_latin1, str[1]))
690 {
691 date[0]= 0; /* Assume we found hours */
692 date[1]= (ulong) value;

Callers

nothing calls this directly

Calls 5

my_time_status_initFunction · 0.85
bmove_uppFunction · 0.85
check_time_mmssff_rangeFunction · 0.85
adjust_time_rangeFunction · 0.85
str_to_datetimeFunction · 0.70

Tested by

no test coverage detected