@@ -290,22 +290,6 @@ def _calc_julian_from_U_or_W(year, week_of_year, day_of_week, week_starts_Mon):
290
290
return 1 + days_to_week + day_of_week
291
291
292
292
293
- def _calc_julian_from_V (iso_year , iso_week , iso_weekday ):
294
- """Calculate the Julian day based on the ISO 8601 year, week, and weekday.
295
- ISO weeks start on Mondays, with week 01 being the week containing 4 Jan.
296
- ISO week days range from 1 (Monday) to 7 (Sunday).
297
- """
298
- correction = datetime_date (iso_year , 1 , 4 ).isoweekday () + 3
299
- ordinal = (iso_week * 7 ) + iso_weekday - correction
300
- # ordinal may be negative or 0 now, which means the date is in the previous
301
- # calendar year
302
- if ordinal < 1 :
303
- ordinal += datetime_date (iso_year , 1 , 1 ).toordinal ()
304
- iso_year -= 1
305
- ordinal -= datetime_date (iso_year , 1 , 1 ).toordinal ()
306
- return iso_year , ordinal
307
-
308
-
309
293
def _strptime (data_string , format = "%a %b %d %H:%M:%S %Y" ):
310
294
"""Return a 2-tuple consisting of a time struct and an int containing
311
295
the number of microseconds based on the input string and the
@@ -483,7 +467,8 @@ def _strptime(data_string, format="%a %b %d %H:%M:%S %Y"):
483
467
else :
484
468
tz = value
485
469
break
486
- # Deal with the cases where ambiguities arize
470
+
471
+ # Deal with the cases where ambiguities arise
487
472
# don't assume default values for ISO week/year
488
473
if year is None and iso_year is not None :
489
474
if iso_week is None or weekday is None :
@@ -511,7 +496,6 @@ def _strptime(data_string, format="%a %b %d %H:%M:%S %Y"):
511
496
elif year is None :
512
497
year = 1900
513
498
514
-
515
499
# If we know the week of the year and what day of that week, we can figure
516
500
# out the Julian day of the year.
517
501
if julian is None and weekday is not None :
@@ -520,7 +504,10 @@ def _strptime(data_string, format="%a %b %d %H:%M:%S %Y"):
520
504
julian = _calc_julian_from_U_or_W (year , week_of_year , weekday ,
521
505
week_starts_Mon )
522
506
elif iso_year is not None and iso_week is not None :
523
- year , julian = _calc_julian_from_V (iso_year , iso_week , weekday + 1 )
507
+ datetime_result = datetime_date .fromisocalendar (iso_year , iso_week , weekday + 1 )
508
+ year = datetime_result .year
509
+ month = datetime_result .month
510
+ day = datetime_result .day
524
511
if julian is not None and julian <= 0 :
525
512
year -= 1
526
513
yday = 366 if calendar .isleap (year ) else 365
0 commit comments