@@ -3803,6 +3803,32 @@ def test_fromisoformat_utc(self):
38033803
38043804 self .assertIs (dt .tzinfo , timezone .utc )
38053805
3806+ def test_fromisoformat_utc_subsecond_offset (self ):
3807+ # A UTC offset whose whole-second part is zero but with a non-zero
3808+ # microsecond part must be preserved, not collapsed to UTC.
3809+ for us in (1 , - 1 , 999999 , - 999999 ):
3810+ with self .subTest (microseconds = us ):
3811+ tz = timezone (timedelta (microseconds = us ))
3812+ dt = self .theclass (2020 , 6 , 15 , 12 , 34 , 56 , tzinfo = tz )
3813+ rt = self .theclass .fromisoformat (dt .isoformat ())
3814+ self .assertEqual (rt .utcoffset (), timedelta (microseconds = us ))
3815+ self .assertEqual (rt , dt )
3816+ self .assertIsNot (rt .tzinfo , timezone .utc )
3817+
3818+ tz = timezone (timedelta (hours = 5 , minutes = 30 , seconds = 15 ,
3819+ microseconds = 123456 ))
3820+ dt = self .theclass (2020 , 6 , 15 , 12 , 34 , 56 , tzinfo = tz )
3821+ rt = self .theclass .fromisoformat (dt .isoformat ())
3822+ self .assertEqual (rt .utcoffset (), tz .utcoffset (None ))
3823+ self .assertEqual (rt , dt )
3824+
3825+ for tstr in ('2020-06-15T12:34:56+00:00' ,
3826+ '2020-06-15T12:34:56+00:00:00.000000' ,
3827+ '2020-06-15T12:34:56Z' ):
3828+ with self .subTest (tstr = tstr ):
3829+ self .assertIs (self .theclass .fromisoformat (tstr ).tzinfo ,
3830+ timezone .utc )
3831+
38063832 def test_fromisoformat_subclass (self ):
38073833 class DateTimeSubclass (self .theclass ):
38083834 pass
0 commit comments