File tree Expand file tree Collapse file tree 4 files changed +29
-0
lines changed
Expand file tree Collapse file tree 4 files changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -107,6 +107,18 @@ def parsedate_tz(data):
107107 tss = int (tss )
108108 except ValueError :
109109 return None
110+ # Check for a yy specified in two-digit format, then convert it to the
111+ # appropriate four-digit format, according to the POSIX standard. RFC 822
112+ # calls for a two-digit yy, but RFC 2822 (which obsoletes RFC 822)
113+ # mandates a 4-digit yy. For more information, see the documentation for
114+ # the time module.
115+ if yy < 100 :
116+ # The year is between 1969 and 1999 (inclusive).
117+ if yy > 68 :
118+ yy += 1900
119+ # The year is between 2000 and 2068 (inclusive).
120+ else :
121+ yy += 2000
110122 tzoffset = None
111123 tz = tz .upper ()
112124 if tz in _timezones :
Original file line number Diff line number Diff line change @@ -2234,6 +2234,19 @@ def test_parsedate_acceptable_to_time_functions(self):
22342234 eq (time .localtime (t )[:6 ], timetup [:6 ])
22352235 eq (int (time .strftime ('%Y' , timetup [:9 ])), 2003 )
22362236
2237+ def test_parsedate_y2k (self ):
2238+ """Test for parsing a date with a two-digit year.
2239+
2240+ Parsing a date with a two-digit year should return the correct
2241+ four-digit year. RFC822 allows two-digit years, but RFC2822 (which
2242+ obsoletes RFC822) requires four-digit years.
2243+
2244+ """
2245+ self .assertEqual (utils .parsedate_tz ('25 Feb 03 13:47:26 -0800' ),
2246+ utils .parsedate_tz ('25 Feb 2003 13:47:26 -0800' ))
2247+ self .assertEqual (utils .parsedate_tz ('25 Feb 71 13:47:26 -0800' ),
2248+ utils .parsedate_tz ('25 Feb 1971 13:47:26 -0800' ))
2249+
22372250 def test_parseaddr_empty (self ):
22382251 self .assertEqual (utils .parseaddr ('<>' ), ('' , '' ))
22392252 self .assertEqual (utils .formataddr (utils .parseaddr ('<>' )), '' )
Original file line number Diff line number Diff line change @@ -260,6 +260,7 @@ Niels Ferguson
260260Sebastian Fernandez
261261Vincent Fiack
262262Tomer Filiba
263+ Jeffrey Finkelstein
263264Russell Finn
264265Nils Fischbeck
265266Frederik Fix
Original file line number Diff line number Diff line change @@ -126,6 +126,9 @@ Extensions
126126Library
127127-------
128128
129+ - Issue #1194222: email.utils.parsedate now returns RFC2822 compliant four
130+ character years even if the message contains RFC822 two character years.
131+
129132- Issue #8750: Fixed MutableSet's methods to correctly handle reflexive
130133 operations on its self, namely x -= x and x ^= x.
131134
You can’t perform that action at this time.
0 commit comments