(self, tz=None)
| 1966 | return timezone(timedelta(seconds=gmtoff), zone) |
| 1967 | |
| 1968 | def astimezone(self, tz=None): |
| 1969 | if tz is None: |
| 1970 | tz = self._local_timezone() |
| 1971 | elif not isinstance(tz, tzinfo): |
| 1972 | raise TypeError("tz argument must be an instance of tzinfo") |
| 1973 | |
| 1974 | mytz = self.tzinfo |
| 1975 | if mytz is None: |
| 1976 | mytz = self._local_timezone() |
| 1977 | myoffset = mytz.utcoffset(self) |
| 1978 | else: |
| 1979 | myoffset = mytz.utcoffset(self) |
| 1980 | if myoffset is None: |
| 1981 | mytz = self.replace(tzinfo=None)._local_timezone() |
| 1982 | myoffset = mytz.utcoffset(self) |
| 1983 | |
| 1984 | if tz is mytz: |
| 1985 | return self |
| 1986 | |
| 1987 | # Convert self to UTC, and attach the new time zone object. |
| 1988 | utc = (self - myoffset).replace(tzinfo=tz) |
| 1989 | |
| 1990 | # Convert from UTC to tz's local time. |
| 1991 | return tz.fromutc(utc) |
| 1992 | |
| 1993 | # Ways to produce a string. |
| 1994 |
no test coverage detected