@@ -3416,6 +3416,32 @@ def test_fromisoformat_utc(self):
34163416
34173417 self .assertIs (dt .tzinfo , timezone .utc )
34183418
3419+ def test_fromisoformat_utc_subsecond_offset (self ):
3420+ # A UTC offset whose whole-second part is zero but with a non-zero
3421+ # microsecond part must be preserved, not collapsed to UTC.
3422+ for us in (1 , - 1 , 999999 , - 999999 ):
3423+ with self .subTest (microseconds = us ):
3424+ tz = timezone (timedelta (microseconds = us ))
3425+ dt = self .theclass (2020 , 6 , 15 , 12 , 34 , 56 , tzinfo = tz )
3426+ rt = self .theclass .fromisoformat (dt .isoformat ())
3427+ self .assertEqual (rt .utcoffset (), timedelta (microseconds = us ))
3428+ self .assertEqual (rt , dt )
3429+ self .assertIsNot (rt .tzinfo , timezone .utc )
3430+
3431+ tz = timezone (timedelta (hours = 5 , minutes = 30 , seconds = 15 ,
3432+ microseconds = 123456 ))
3433+ dt = self .theclass (2020 , 6 , 15 , 12 , 34 , 56 , tzinfo = tz )
3434+ rt = self .theclass .fromisoformat (dt .isoformat ())
3435+ self .assertEqual (rt .utcoffset (), tz .utcoffset (None ))
3436+ self .assertEqual (rt , dt )
3437+
3438+ for tstr in ('2020-06-15T12:34:56+00:00' ,
3439+ '2020-06-15T12:34:56+00:00:00.000000' ,
3440+ '2020-06-15T12:34:56Z' ):
3441+ with self .subTest (tstr = tstr ):
3442+ self .assertIs (self .theclass .fromisoformat (tstr ).tzinfo ,
3443+ timezone .utc )
3444+
34193445 def test_fromisoformat_subclass (self ):
34203446 class DateTimeSubclass (self .theclass ):
34213447 pass
0 commit comments