MCPcopy Index your code
hub / github.com/RustPython/RustPython / astimezone

Method astimezone

Lib/_pydatetime.py:2087–2110  ·  view source on GitHub ↗
(self, tz=None)

Source from the content-addressed store, hash-verified

2085 return timezone(timedelta(seconds=gmtoff), zone)
2086
2087 def astimezone(self, tz=None):
2088 if tz is None:
2089 tz = self._local_timezone()
2090 elif not isinstance(tz, tzinfo):
2091 raise TypeError("tz argument must be an instance of tzinfo")
2092
2093 mytz = self.tzinfo
2094 if mytz is None:
2095 mytz = self._local_timezone()
2096 myoffset = mytz.utcoffset(self)
2097 else:
2098 myoffset = mytz.utcoffset(self)
2099 if myoffset is None:
2100 mytz = self.replace(tzinfo=None)._local_timezone()
2101 myoffset = mytz.utcoffset(self)
2102
2103 if tz is mytz:
2104 return self
2105
2106 # Convert self to UTC, and attach the new time zone object.
2107 utc = (self - myoffset).replace(tzinfo=tz)
2108
2109 # Convert from UTC to tz's local time.
2110 return tz.fromutc(utc)
2111
2112 # Ways to produce a string.
2113

Callers 15

Time2InternaldateFunction · 0.80
_date_to_stringFunction · 0.80
_write_objectMethod · 0.80
formatdateFunction · 0.80
localtimeFunction · 0.80
test_astimezoneMethod · 0.80
test_tzinfo_nowMethod · 0.80
test_utctimetupleMethod · 0.80
test_more_astimezoneMethod · 0.80

Calls 6

_local_timezoneMethod · 0.95
replaceMethod · 0.95
isinstanceFunction · 0.85
utcoffsetMethod · 0.45
replaceMethod · 0.45
fromutcMethod · 0.45