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

Method _build_naive

src/dateutil/parser/_parser.py:1217–1240  ·  view source on GitHub ↗
(self, res, default)

Source from the content-addressed store, hash-verified

1215 return aware
1216
1217 def _build_naive(self, res, default):
1218 repl = {}
1219 for attr in ("year", "month", "day", "hour",
1220 "minute", "second", "microsecond"):
1221 value = getattr(res, attr)
1222 if value is not None:
1223 repl[attr] = value
1224
1225 if 'day' not in repl:
1226 # If the default day exceeds the last day of the month, fall back
1227 # to the end of the month.
1228 cyear = default.year if res.year is None else res.year
1229 cmonth = default.month if res.month is None else res.month
1230 cday = default.day if res.day is None else res.day
1231
1232 if cday > monthrange(cyear, cmonth)[1]:
1233 repl['day'] = monthrange(cyear, cmonth)[1]
1234
1235 naive = default.replace(**repl)
1236
1237 if res.weekday is not None and not res.day:
1238 naive = naive + relativedelta.relativedelta(weekday=res.weekday)
1239
1240 return naive
1241
1242 def _assign_tzname(self, dt, tzname):
1243 if dt.tzname() != tzname:

Callers 1

parseMethod · 0.95

Calls 1

replaceMethod · 0.45

Tested by

no test coverage detected