@@ -77,6 +77,30 @@ def test_parsedate_to_datetime_with_invalid_raises_valueerror(self):
7777 with self .subTest (dtstr = dtstr ):
7878 self .assertRaises (ValueError , utils .parsedate_to_datetime , dtstr )
7979
80+ def test_parsedate_to_datetime_year_edge_cases (self ):
81+ expectations = {
82+ # Various short-year formats that get expanded
83+ "Sat, 15 Aug 0001 23:12:09 +0500" : "2001" ,
84+ "Thu, 1 Sep 1 23:12:09 +0800" : "2001" ,
85+ "Thu, 7 Oct 123 23:12:09 +0500" : "2023" ,
86+ "Tue, 17 Nov 2026 12:12:09 +0500" : "2026" ,
87+ # RFC 5322 section 4.3 boundaries for 2-digit years
88+ "Mon, 1 Jan 0 00:00:00 +0000" : "2000" ,
89+ "Mon, 1 Jan 68 00:00:00 +0000" : "2068" ,
90+ "Mon, 1 Jan 69 00:00:00 +0000" : "1969" ,
91+ "Mon, 1 Jan 99 00:00:00 +0000" : "1999" ,
92+ # 3-digit year boundary
93+ "Mon, 1 Jan 999 00:00:00 +0000" : "2899" ,
94+ # Pre-1900 four-digit year: illegal per RFC but we accept it
95+ "Mon, 1 Jan 1000 00:00:00 +0000" : "1000" ,
96+ }
97+ for input_string , expected_year in expectations .items ():
98+ with self .subTest (input_string = input_string ):
99+ self .assertEqual (
100+ str (utils .parsedate_to_datetime (input_string ))[:4 ],
101+ expected_year ,
102+ )
103+
80104class LocaltimeTests (unittest .TestCase ):
81105
82106 def test_localtime_is_tz_aware_daylight_true (self ):
@@ -186,18 +210,5 @@ def test_formatdate_with_localtime(self):
186210 string = utils .formatdate (timeval , localtime = True )
187211 self .assertEqual (string , 'Thu, 01 Dec 2011 18:00:00 +0300' )
188212
189- # Issue #126845: Some edge cases seem to differ from RFC28222 spec
190- class ParsedateToDatetimeTest (unittest .TestCase ):
191- def test_year_parsing_edge_cases (self ):
192- expectations = {
193- "Sat, 15 Aug 0001 23:12:09 +0500" : "2001" ,
194- "Thu, 1 Sep 1 23:12:09 +0800" : "2001" ,
195- "Thu, 7 Oct 123 23:12:09 +0500" : "2023" ,
196- "Tue, 17 Nov 2026 12:12:09 +0500" : "2026" ,
197- }
198- for input_string , output_string in expectations .items ():
199- with self .subTest (input_string = input_string ):
200- self .assertEqual (str (utils .parsedate_to_datetime (input_string ))[:4 ], output_string )
201-
202213if __name__ == '__main__' :
203214 unittest .main ()
0 commit comments