MCPcopy
hub / github.com/myusuf3/delorean / __init__

Method __init__

delorean/dates.py:184–225  ·  view source on GitHub ↗
(self, datetime=None, timezone=None)

Source from the content-addressed store, hash-verified

182 'thursday', 'friday', 'saturday', 'sunday')
183
184 def __init__(self, datetime=None, timezone=None):
185 # maybe set timezone on the way in here. if here set it if not
186 # use UTC
187 is_datetime_instance(datetime)
188
189 if datetime:
190 if is_datetime_naive(datetime):
191 if timezone:
192 if isinstance(timezone, tzoffset):
193 utcoffset = timezone.utcoffset(None)
194 total_seconds = (
195 (utcoffset.microseconds + (
196 utcoffset.seconds + utcoffset.days * 24 * 3600) * 10 ** 6) / 10 ** 6)
197 self._tzinfo = pytz.FixedOffset(total_seconds / 60)
198 elif isinstance(timezone, tzinfo):
199 self._tzinfo = timezone
200 else:
201 self._tzinfo = pytz.timezone(timezone)
202 self._dt = localize(datetime, self._tzinfo)
203 self._tzinfo = self._dt.tzinfo
204 else:
205 # TODO(mlew, 2015-08-09):
206 # Should we really throw an error here, or should this
207 # default to UTC?)
208 raise DeloreanInvalidTimezone('Provide a valid timezone')
209 else:
210 self._tzinfo = datetime.tzinfo
211 self._dt = datetime
212 else:
213 if timezone:
214 if isinstance(timezone, tzoffset):
215 self._tzinfo = pytz.FixedOffset(timezone.utcoffset(None).total_seconds() / 60)
216 elif isinstance(timezone, tzinfo):
217 self._tzinfo = timezone
218 else:
219 self._tzinfo = pytz.timezone(timezone)
220
221 self._dt = datetime_timezone(self._tzinfo)
222 self._tzinfo = self._dt.tzinfo
223 else:
224 self._tzinfo = pytz.utc
225 self._dt = datetime_timezone('UTC')
226
227 def __repr__(self):
228 dt = self.datetime.replace(tzinfo=None)

Callers

nothing calls this directly

Calls 7

is_datetime_instanceFunction · 0.85
is_datetime_naiveFunction · 0.85
localizeFunction · 0.85
datetime_timezoneFunction · 0.85
utcoffsetMethod · 0.80
timezoneMethod · 0.80

Tested by

no test coverage detected