MCPcopy Create free account
hub / github.com/scottrogowski/code2flow / normalize

Method normalize

tests/test_code/py/pytz/tzinfo.py:118–145  ·  view source on GitHub ↗

Correct the timezone information on the given datetime. This is normally a no-op, as StaticTzInfo timezones never have ambiguous cases to correct: >>> from pytz import timezone >>> gmt = timezone('GMT') >>> isinstance(gmt, StaticTzInfo) True

(self, dt, is_dst=False)

Source from the content-addressed store, hash-verified

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:
134
135 >>> la = timezone('America/Los_Angeles')
136 >>> dt = la.localize(datetime(2011, 5, 7, 1, 2, 3))
137 >>> fmt = '%Y-%m-%d %H:%M:%S %Z (%z)'
138 >>> gmt.normalize(dt).strftime(fmt)
139 '2011-05-07 08:02:03 GMT (+0000)'
140 '''
141 if dt.tzinfo is self:
142 return dt
143 if dt.tzinfo is None:
144 raise ValueError('Naive time - no tzinfo set')
145 return dt.astimezone(self)
146
147 def __repr__(self):
148 return '<StaticTzInfo %r>' % (self.zone,)

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected