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

Method _build_tzaware

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

Source from the content-addressed store, hash-verified

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

Callers 1

parseMethod · 0.95

Calls 5

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

Tested by

no test coverage detected