A timezone that has a constant offset from UTC These timezones are rare, as most locations have changed their offset at some point in their history
| 74 | |
| 75 | |
| 76 | class StaticTzInfo(BaseTzInfo): |
| 77 | '''A timezone that has a constant offset from UTC |
| 78 | |
| 79 | These timezones are rare, as most locations have changed their |
| 80 | offset at some point in their history |
| 81 | ''' |
| 82 | def fromutc(self, dt): |
| 83 | '''See datetime.tzinfo.fromutc''' |
| 84 | if dt.tzinfo is not None and dt.tzinfo is not self: |
| 85 | raise ValueError('fromutc: dt.tzinfo is not self') |
| 86 | return (dt + self._utcoffset).replace(tzinfo=self) |
| 87 | |
| 88 | def utcoffset(self, dt, is_dst=None): |
| 89 | '''See datetime.tzinfo.utcoffset |
| 90 | |
| 91 | is_dst is ignored for StaticTzInfo, and exists only to |
| 92 | retain compatibility with DstTzInfo. |
| 93 | ''' |
| 94 | return self._utcoffset |
| 95 | |
| 96 | def dst(self, dt, is_dst=None): |
| 97 | '''See datetime.tzinfo.dst |
| 98 | |
| 99 | is_dst is ignored for StaticTzInfo, and exists only to |
| 100 | retain compatibility with DstTzInfo. |
| 101 | ''' |
| 102 | return _notime |
| 103 | |
| 104 | def tzname(self, dt, is_dst=None): |
| 105 | '''See datetime.tzinfo.tzname |
| 106 | |
| 107 | is_dst is ignored for StaticTzInfo, and exists only to |
| 108 | retain compatibility with DstTzInfo. |
| 109 | ''' |
| 110 | return self._tzname |
| 111 | |
| 112 | def localize(self, dt, is_dst=False): |
| 113 | '''Convert naive time to local time''' |
| 114 | if dt.tzinfo is not None: |
| 115 | raise ValueError('Not naive datetime (tzinfo is already set)') |
| 116 | return dt.replace(tzinfo=self) |
| 117 | |
| 118 | def normalize(self, dt, is_dst=False): |
| 119 | '''Correct the timezone information on the given datetime. |
| 120 | |
| 121 | This is normally a no-op, as StaticTzInfo timezones never have |
| 122 | ambiguous cases to correct: |
| 123 | |
| 124 | >>> from pytz import timezone |
| 125 | >>> gmt = timezone('GMT') |
| 126 | >>> isinstance(gmt, StaticTzInfo) |
| 127 | True |
| 128 | >>> dt = datetime(2011, 5, 8, 1, 2, 3, tzinfo=gmt) |
| 129 | >>> gmt.normalize(dt) is dt |
| 130 | True |
| 131 | |
| 132 | The supported method of converting between timezones is to use |
| 133 | datetime.astimezone(). Currently normalize() also works: |
nothing calls this directly
no outgoing calls
no test coverage detected