@@ -3,6 +3,7 @@ Parsing functions for datetime and datetime-like strings.
3
3
"""
4
4
import re
5
5
import time
6
+ import warnings
6
7
7
8
from libc.string cimport strchr
8
9
@@ -149,14 +150,28 @@ cdef inline object _parse_delimited_date(str date_string, bint dayfirst):
149
150
# date_string can't be converted to date, above format
150
151
return None , None
151
152
153
+ swapped_day_and_month = False
152
154
if 1 <= month <= MAX_DAYS_IN_MONTH and 1 <= day <= MAX_DAYS_IN_MONTH \
153
155
and (month <= MAX_MONTH or day <= MAX_MONTH):
154
156
if (month > MAX_MONTH or (day <= MAX_MONTH and dayfirst)) and can_swap:
155
157
day, month = month, day
158
+ swapped_day_and_month = True
156
159
if PY_VERSION_HEX >= 0x03060100 :
157
160
# In Python <= 3.6.0 there is no range checking for invalid dates
158
161
# in C api, thus we call faster C version for 3.6.1 or newer
162
+
163
+ if dayfirst and not swapped_day_and_month:
164
+ warnings.warn(f" Parsing {date_string} MM/DD format." )
165
+ elif not dayfirst and swapped_day_and_month:
166
+ warnings.warn(f" Parsing {date_string} DD/MM format." )
167
+
159
168
return datetime_new(year, month, day, 0 , 0 , 0 , 0 , None ), reso
169
+
170
+ if dayfirst and not swapped_day_and_month:
171
+ warnings.warn(f" Parsing {date_string} MM/DD format." )
172
+ elif not dayfirst and swapped_day_and_month:
173
+ warnings.warn(f" Parsing {date_string} DD/MM format." )
174
+
160
175
return datetime(year, month, day, 0 , 0 , 0 , 0 , None ), reso
161
176
162
177
raise DateParseError(f" Invalid date specified ({month}/{day})" )
0 commit comments