--- _strptime.py.orig 2011-05-26 14:25:58.000000000 +0200
+++ _strptime.py 2011-05-26 14:36:51.000000000 +0200
@@ -199,6 +199,8 @@
'S': r"(?P~~6[0-1]|[0-5]\d|\d)",
'U': r"(?P~~__5[0-3]|[0-4]\d|\d)",
'w': r"(?P[0-6])",
+ 'u': r"(?P____[1-7])",
+ 'V': r"(?P5[0-3]|0[1-9]|[1-4]\d|\d)",
# W is set below by using 'U'
'y': r"(?P\d\d)",
#XXX: Does 'Y' need to worry about having less or more than
@@ -291,6 +293,21 @@
days_to_week = week_0_length + (7 * (week_of_year - 1))
return 1 + days_to_week + day_of_week
+def _calc_julian_from_V(year, iso_week, iso_weekday):
+ """Calculate the Julian day based on the ISO 8601 year, week, and weekday.
+ ISO weeks start on Mondays, with week 01 being the week containing 4 Jan.
+ ISO week days range from 1 (Monday) to 7 (Sunday).
+
+ """
+ correction = datetime_date(year,1,4).isoweekday() + 3
+ ordinal = (iso_week * 7) + iso_weekday - correction
+ # ordinal may be negative or 0 now, which means the date is in the previous
+ # calendar year
+ if ordinal < 1:
+ ordinal += datetime_date(year,1,1).toordinal() - datetime_date(year-1,1,1).toordinal()
+ return year - 1, ordinal
+ else:
+ return year, ordinal
def _strptime(data_string, format="%a %b %d %H:%M:%S %Y"):
"""Return a time struct based on the input string and the format string."""
@@ -334,6 +351,8 @@
# though
week_of_year = -1
week_of_year_start = -1
+ iso_week = -1
+ iso_weekday = -1
# weekday and julian defaulted to -1 so as to signal need to calculate
# values
weekday = julian = -1
@@ -400,6 +419,14 @@
weekday = 6
else:
weekday -= 1
+ iso_weekday = weekday + 1
+ elif group_key == 'u':
+ iso_weekday = int(found_dict['u'])
+ weekday = iso_weekday % 7
+ if weekday == 0:
+ weekday = 6
+ else:
+ weekday -=1
elif group_key == 'j':
julian = int(found_dict['j'])
elif group_key in ('U', 'W'):
@@ -410,6 +437,8 @@
else:
# W starts week on Monday.
week_of_year_start = 0
+ elif group_key == 'V':
+ iso_week = int(found_dict['V'])
elif group_key == 'Z':
# Since -1 is default value only need to worry about setting tz if
# it can be something other than -1.
@@ -431,6 +460,8 @@
week_starts_Mon = True if week_of_year_start == 0 else False
julian = _calc_julian_from_U_or_W(year, week_of_year, weekday,
week_starts_Mon)
+ elif julian == -1 and iso_week != -1 and iso_weekday != -1:
+ year, julian = _calc_julian_from_V(year, iso_week, iso_weekday)
# Cannot pre-calculate datetime_date() since can change in Julian
# calculation and thus could have different value for the day of the week
# calculation.
__