1212
1313import _strptime
1414
15+ from Lib .test .test_zipfile ._path ._test_params import parameterize
16+
17+
1518class getlang_Tests (unittest .TestCase ):
1619 """Test _getlang"""
1720 def test_basic (self ):
@@ -354,7 +357,7 @@ def test_julian(self):
354357 # Test julian directives
355358 self .helper ('j' , 7 )
356359
357- def test_offset (self ):
360+ def test_z_directive_offset (self ):
358361 one_hour = 60 * 60
359362 half_hour = 30 * 60
360363 half_minute = 30
@@ -370,22 +373,39 @@ def test_offset(self):
370373 (* _ , offset ), _ , offset_fraction = _strptime ._strptime ("-013030.000001" , "%z" )
371374 self .assertEqual (offset , - (one_hour + half_hour + half_minute ))
372375 self .assertEqual (offset_fraction , - 1 )
373- (* _ , offset ), _ , offset_fraction = _strptime ._strptime ("+01:00" , "%z" )
376+
377+ @parameterize (
378+ ["directive" ],
379+ [
380+ ("%z" ,),
381+ ("%:z" ,),
382+ ]
383+ )
384+ def test_iso_offset (self , directive : str ):
385+ """
386+ Tests offset for the '%:z' directive from ISO 8601.
387+ Since '%z' directive also accepts '%:z'-formatted strings for backwards compatibility,
388+ we're testing that here too.
389+ """
390+ one_hour = 60 * 60
391+ half_hour = 30 * 60
392+ half_minute = 30
393+ (* _ , offset ), _ , offset_fraction = _strptime ._strptime ("+01:00" , directive )
374394 self .assertEqual (offset , one_hour )
375395 self .assertEqual (offset_fraction , 0 )
376- (* _ , offset ), _ , offset_fraction = _strptime ._strptime ("-01:30" , "%z" )
396+ (* _ , offset ), _ , offset_fraction = _strptime ._strptime ("-01:30" , directive )
377397 self .assertEqual (offset , - (one_hour + half_hour ))
378398 self .assertEqual (offset_fraction , 0 )
379- (* _ , offset ), _ , offset_fraction = _strptime ._strptime ("-01:30:30" , "%z" )
399+ (* _ , offset ), _ , offset_fraction = _strptime ._strptime ("-01:30:30" , directive )
380400 self .assertEqual (offset , - (one_hour + half_hour + half_minute ))
381401 self .assertEqual (offset_fraction , 0 )
382- (* _ , offset ), _ , offset_fraction = _strptime ._strptime ("-01:30:30.000001" , "%z" )
402+ (* _ , offset ), _ , offset_fraction = _strptime ._strptime ("-01:30:30.000001" , directive )
383403 self .assertEqual (offset , - (one_hour + half_hour + half_minute ))
384404 self .assertEqual (offset_fraction , - 1 )
385- (* _ , offset ), _ , offset_fraction = _strptime ._strptime ("+01:30:30.001" , "%z" )
405+ (* _ , offset ), _ , offset_fraction = _strptime ._strptime ("+01:30:30.001" , directive )
386406 self .assertEqual (offset , one_hour + half_hour + half_minute )
387407 self .assertEqual (offset_fraction , 1000 )
388- (* _ , offset ), _ , offset_fraction = _strptime ._strptime ("Z" , "%z" )
408+ (* _ , offset ), _ , offset_fraction = _strptime ._strptime ("Z" , directive )
389409 self .assertEqual (offset , 0 )
390410 self .assertEqual (offset_fraction , 0 )
391411
0 commit comments