diff -r 234021dcad93 Lib/datetime.py --- a/Lib/datetime.py Wed May 25 02:35:58 2011 +0200 +++ b/Lib/datetime.py Tue May 24 20:49:47 2011 -0500 @@ -633,7 +633,8 @@ class date: fromtimestamp() today() fromordinal() - + fromisocalendar() + Operators: __repr__, __str__ @@ -690,7 +691,7 @@ class date: @classmethod def fromordinal(cls, n): - """Contruct a date from a proleptic Gregorian ordinal. + """Construct a date from a proleptic Gregorian ordinal. January 1 of year 1 is day 1. Only the year, month and day are non-zero in the result. @@ -698,6 +699,28 @@ class date: y, m, d = _ord2ymd(n) return cls(y, m, d) + @classmethod + def fromisocalendar(cls, s): + """Construct a date from ISO 8601 year, week, and day number + + Accepts a string in the form YYYYWWD, where + YYYY is the four-digit year, + WW is the week number, and + D is the day number (1-7). + """ + year = s[0:4] + isoweek = s[4:6] + isoday = s[6:7] + + # convert to an ordinal date for the year + week1monday = _isoweek1monday(year) + n = (isoweek * 7) + isoday - (week1monday + 3) + # add the days before the year + n += _days_before_year(year) + + y, m, d = _ord2ymd(n) + return cls(y, m, d) + # Conversions to string def __repr__(self):