@@ -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
@@ -168,14 +169,28 @@ cdef inline object _parse_delimited_date(str date_string, bint dayfirst):
168
169
# date_string can't be converted to date, above format
169
170
return None , None
170
171
172
+ swapped_day_and_month = False
171
173
if 1 <= month <= MAX_DAYS_IN_MONTH and 1 <= day <= MAX_DAYS_IN_MONTH \
172
174
and (month <= MAX_MONTH or day <= MAX_MONTH):
173
175
if (month > MAX_MONTH or (day <= MAX_MONTH and dayfirst)) and can_swap:
174
176
day, month = month, day
177
+ swapped_day_and_month = True
175
178
if PY_VERSION_HEX >= 0x03060100 :
176
179
# In Python <= 3.6.0 there is no range checking for invalid dates
177
180
# in C api, thus we call faster C version for 3.6.1 or newer
181
+
182
+ if dayfirst and not swapped_day_and_month:
183
+ warnings.warn(f" Parsing {date_string} MM/DD format." )
184
+ elif not dayfirst and swapped_day_and_month:
185
+ warnings.warn(f" Parsing {date_string} DD/MM format." )
186
+
178
187
return datetime_new(year, month, day, 0 , 0 , 0 , 0 , None ), reso
188
+
189
+ if dayfirst and not swapped_day_and_month:
190
+ warnings.warn(f" Parsing {date_string} MM/DD format." )
191
+ elif not dayfirst and swapped_day_and_month:
192
+ warnings.warn(f" Parsing {date_string} DD/MM format." )
193
+
179
194
return datetime(year, month, day, 0 , 0 , 0 , 0 , None ), reso
180
195
181
196
raise DateParseError(f" Invalid date specified ({month}/{day})" )
0 commit comments