@@ -36,8 +36,9 @@ def _default_datetime_formatter(dt):
3636 )
3737
3838
39- def _format_timezone (tzinfo , * , sep ):
40- offset = tzinfo .utcoffset (None ).total_seconds ()
39+ def _format_timezone (dt , * , sep ):
40+ tzinfo = dt .tzinfo or timezone .utc
41+ offset = tzinfo .utcoffset (dt ).total_seconds ()
4142 sign = "+" if offset >= 0 else "-"
4243 (h , m ), s = divmod (abs (offset // 60 ), 60 ), abs (offset ) % 60
4344 z = "%s%02d%s%02d" % (sign , h , sep , m )
@@ -103,8 +104,8 @@ def _compile_format(spec):
103104 "SSSSS" : ("%05d" , lambda t , dt : dt .microsecond // 10 ),
104105 "SSSSSS" : ("%06d" , lambda t , dt : dt .microsecond ),
105106 "A" : ("%s" , lambda t , dt : "AM" if t .tm_hour < 12 else "PM" ),
106- "Z" : ("%s" , lambda t , dt : _format_timezone (dt . tzinfo or timezone . utc , sep = ":" )),
107- "ZZ" : ("%s" , lambda t , dt : _format_timezone (dt . tzinfo or timezone . utc , sep = "" )),
107+ "Z" : ("%s" , lambda t , dt : _format_timezone (dt , sep = ":" )),
108+ "ZZ" : ("%s" , lambda t , dt : _format_timezone (dt , sep = "" )),
108109 "zz" : ("%s" , lambda t , dt : (dt .tzinfo or timezone .utc ).tzname (dt ) or "" ),
109110 "X" : ("%d" , lambda t , dt : dt .timestamp ()),
110111 "x" : ("%d" , lambda t , dt : int (dt .timestamp () * 1000000 + dt .microsecond )),
@@ -135,7 +136,6 @@ def _compile_format(spec):
135136
136137
137138class datetime (datetime_ ): # noqa: N801
138-
139139 def __format__ (self , fmt ):
140140 return _compile_format (fmt )(self )
141141
0 commit comments