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

Function parse_date_time_format

sql/sql_time.cc:686–898  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

684*/
685
686bool parse_date_time_format(timestamp_type format_type,
687 const char *format, uint format_length,
688 DATE_TIME_FORMAT *date_time_format)
689{
690 uint offset= 0, separators= 0;
691 const char *ptr= format, *format_str;
692 const char *end= ptr+format_length;
693 uchar *dt_pos= date_time_format->positions;
694 /* need_p is set if we are using AM/PM format */
695 bool need_p= 0, allow_separator= 0;
696 ulong part_map= 0, separator_map= 0;
697 const char *parts[16];
698
699 date_time_format->time_separator= 0;
700 date_time_format->flag= 0; // For future
701
702 /*
703 Fill position with 'dummy' arguments to found out if a format tag is
704 used twice (This limit's the format to 255 characters, but this is ok)
705 */
706 dt_pos[0]= dt_pos[1]= dt_pos[2]= dt_pos[3]=
707 dt_pos[4]= dt_pos[5]= dt_pos[6]= dt_pos[7]= 255;
708
709 for (; ptr != end; ptr++)
710 {
711 if (*ptr == '%' && ptr+1 != end)
712 {
713 uint position;
714 LINT_INIT(position);
715 switch (*++ptr) {
716 case 'y': // Year
717 case 'Y':
718 position= 0;
719 break;
720 case 'c': // Month
721 case 'm':
722 position= 1;
723 break;
724 case 'd':
725 case 'e':
726 position= 2;
727 break;
728 case 'h':
729 case 'I':
730 case 'l':
731 need_p= 1; // Need AM/PM
732 /* Fall through */
733 case 'k':
734 case 'H':
735 position= 3;
736 break;
737 case 'i':
738 position= 4;
739 break;
740 case 's':
741 case 'S':
742 position= 5;
743 break;

Callers 1

date_time_format_makeFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected