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