@@ -289,21 +289,6 @@ def parse_datetime_string(
289
289
dt, _ = dateutil_parse(date_string, default = _DEFAULT_DATETIME,
290
290
dayfirst = dayfirst, yearfirst = yearfirst,
291
291
ignoretz = False )
292
-
293
- if dt.tzinfo is not None :
294
- # dateutil can return a datetime with a tzoffset outside of (-24H, 24H)
295
- # bounds, which is invalid (can be constructed, but raises if we call
296
- # str(dt)). Check that and raise here if necessary.
297
- try :
298
- dt.utcoffset()
299
- except ValueError as err:
300
- # offset must be a timedelta strictly between -timedelta(hours=24)
301
- # and timedelta(hours=24)
302
- raise ValueError (
303
- f' Parsed string "{date_string}" gives an invalid tzoffset, '
304
- " which must be between -timedelta(hours=24) and timedelta(hours=24)"
305
- )
306
-
307
292
return dt
308
293
309
294
@@ -656,6 +641,20 @@ cdef dateutil_parse(
656
641
ret = ret.replace(tzinfo = _dateutil_tzutc())
657
642
elif res.tzoffset:
658
643
ret = ret.replace(tzinfo = tzoffset(res.tzname, res.tzoffset))
644
+
645
+ # dateutil can return a datetime with a tzoffset outside of (-24H, 24H)
646
+ # bounds, which is invalid (can be constructed, but raises if we call
647
+ # str(ret)). Check that and raise here if necessary.
648
+ try :
649
+ ret.utcoffset()
650
+ except ValueError as err:
651
+ # offset must be a timedelta strictly between -timedelta(hours=24)
652
+ # and timedelta(hours=24)
653
+ raise ValueError (
654
+ f' Parsed string "{timestr}" gives an invalid tzoffset, '
655
+ " which must be between -timedelta(hours=24) and timedelta(hours=24)"
656
+ )
657
+
659
658
return ret, reso
660
659
661
660
0 commit comments