MCPcopy Create free account
hub / github.com/dateutil/dateutil / _build_tzaware

Method _build_tzaware

src/dateutil/parser/_parser.py:1177–1215  ·  view source on GitHub ↗
(self, naive, res, tzinfos)

Source from the content-addressed store, hash-verified

1175 return tzinfo
1176
1177 def _build_tzaware(self, naive, res, tzinfos):
1178 if (callable(tzinfos) or (tzinfos and res.tzname in tzinfos)):
1179 tzinfo = self._build_tzinfo(tzinfos, res.tzname, res.tzoffset)
1180 aware = naive.replace(tzinfo=tzinfo)
1181 aware = self._assign_tzname(aware, res.tzname)
1182
1183 elif res.tzname and res.tzname in time.tzname:
1184 aware = naive.replace(tzinfo=tz.tzlocal())
1185
1186 # Handle ambiguous local datetime
1187 aware = self._assign_tzname(aware, res.tzname)
1188
1189 # This is mostly relevant for winter GMT zones parsed in the UK
1190 if (aware.tzname() != res.tzname and
1191 res.tzname in self.info.UTCZONE):
1192 aware = aware.replace(tzinfo=tz.UTC)
1193
1194 elif res.tzoffset == 0:
1195 aware = naive.replace(tzinfo=tz.UTC)
1196
1197 elif res.tzoffset:
1198 aware = naive.replace(tzinfo=tz.tzoffset(res.tzname, res.tzoffset))
1199
1200 elif not res.tzname and not res.tzoffset:
1201 # i.e. no timezone information was found.
1202 aware = naive
1203
1204 elif res.tzname:
1205 # tz-like string was parsed but we don't know what to do
1206 # with it
1207 warnings.warn("tzname {tzname} identified but not understood. "
1208 "Pass `tzinfos` argument in order to correctly "
1209 "return a timezone-aware datetime. In a future "
1210 "version, this will raise an "
1211 "exception.".format(tzname=res.tzname),
1212 category=UnknownTimezoneWarning)
1213 aware = naive
1214
1215 return aware
1216
1217 def _build_naive(self, res, default):
1218 repl = {}

Callers 1

parseMethod · 0.95

Calls 5

_build_tzinfoMethod · 0.95
_assign_tznameMethod · 0.95
tzoffsetMethod · 0.80
replaceMethod · 0.45
tznameMethod · 0.45

Tested by

no test coverage detected