@@ -62,6 +62,9 @@ DEF delimiters = b' /-\\'
62
62
DEF MAX_DAYS_IN_MONTH = 31
63
63
DEF MAX_MONTH = 12
64
64
65
+ cdef bint _is_not_delimiter(const char ch):
66
+ return strchr(delimiters, ch) == NULL
67
+
65
68
cdef inline int _parse_2digit(const char * s):
66
69
cdef int result = 0
67
70
result += getdigit_ascii(s[0 ], - 10 ) * 10
@@ -84,13 +87,21 @@ cdef object parse_slashed_date(object date_string, bint dayfirst,
84
87
int day, month, year
85
88
86
89
buf = get_c_string_buf_and_size(date_string, & length)
87
- if length != 10 or strchr(delimiters, buf[2 ]) == NULL \
88
- or strchr(delimiters, buf[5 ]) == NULL :
90
+ if length == 10 :
91
+ if _is_not_delimiter(buf[2 ]) or _is_not_delimiter(buf[5 ]):
92
+ return None
93
+ month = _parse_2digit(buf)
94
+ day = _parse_2digit(buf + 3 )
95
+ year = _parse_4digit(buf + 6 )
96
+ elif length == 7 :
97
+ if _is_not_delimiter(buf[2 ]):
98
+ return None
99
+ month = _parse_2digit(buf)
100
+ day = 1
101
+ year = _parse_4digit(buf + 3 )
102
+ else :
89
103
return None
90
104
91
- month = _parse_2digit(buf)
92
- day = _parse_2digit(buf + 3 )
93
- year = _parse_4digit(buf + 6 )
94
105
if month < 0 or day < 0 or year < 0 :
95
106
# some part is not an integer, so it's not a mm/dd/yyyy date
96
107
return None
0 commit comments