@@ -3626,6 +3626,32 @@ def test_fromisoformat_utc(self):
36263626
36273627 self .assertIs (dt .tzinfo , timezone .utc )
36283628
3629+ def test_fromisoformat_utc_subsecond_offset (self ):
3630+ # A UTC offset whose whole-second part is zero but with a non-zero
3631+ # microsecond part must be preserved, not collapsed to UTC.
3632+ for us in (1 , - 1 , 999999 , - 999999 ):
3633+ with self .subTest (microseconds = us ):
3634+ tz = timezone (timedelta (microseconds = us ))
3635+ dt = self .theclass (2020 , 6 , 15 , 12 , 34 , 56 , tzinfo = tz )
3636+ rt = self .theclass .fromisoformat (dt .isoformat ())
3637+ self .assertEqual (rt .utcoffset (), timedelta (microseconds = us ))
3638+ self .assertEqual (rt , dt )
3639+ self .assertIsNot (rt .tzinfo , timezone .utc )
3640+
3641+ tz = timezone (timedelta (hours = 5 , minutes = 30 , seconds = 15 ,
3642+ microseconds = 123456 ))
3643+ dt = self .theclass (2020 , 6 , 15 , 12 , 34 , 56 , tzinfo = tz )
3644+ rt = self .theclass .fromisoformat (dt .isoformat ())
3645+ self .assertEqual (rt .utcoffset (), tz .utcoffset (None ))
3646+ self .assertEqual (rt , dt )
3647+
3648+ for tstr in ('2020-06-15T12:34:56+00:00' ,
3649+ '2020-06-15T12:34:56+00:00:00.000000' ,
3650+ '2020-06-15T12:34:56Z' ):
3651+ with self .subTest (tstr = tstr ):
3652+ self .assertIs (self .theclass .fromisoformat (tstr ).tzinfo ,
3653+ timezone .utc )
3654+
36293655 def test_fromisoformat_subclass (self ):
36303656 class DateTimeSubclass (self .theclass ):
36313657 pass
0 commit comments