Version of ``dateutil.relativedelta`` that only supports addition.
| 387 | |
| 388 | |
| 389 | class ffwd: |
| 390 | """Version of ``dateutil.relativedelta`` that only supports addition.""" |
| 391 | |
| 392 | def __init__(self, year=None, month=None, weeks=0, weekday=None, day=None, |
| 393 | hour=None, minute=None, second=None, microsecond=None, |
| 394 | **kwargs: Any): |
| 395 | # pylint: disable=redefined-outer-name |
| 396 | # weekday is also a function in outer scope. |
| 397 | self.year = year |
| 398 | self.month = month |
| 399 | self.weeks = weeks |
| 400 | self.weekday = weekday |
| 401 | self.day = day |
| 402 | self.hour = hour |
| 403 | self.minute = minute |
| 404 | self.second = second |
| 405 | self.microsecond = microsecond |
| 406 | self.days = weeks * 7 |
| 407 | self._has_time = self.hour is not None or self.minute is not None |
| 408 | |
| 409 | def __repr__(self) -> str: |
| 410 | return reprcall('ffwd', (), self._fields(weeks=self.weeks, |
| 411 | weekday=self.weekday)) |
| 412 | |
| 413 | def __radd__(self, other: Any) -> timedelta: |
| 414 | if not isinstance(other, date): |
| 415 | return NotImplemented |
| 416 | year = self.year or other.year |
| 417 | month = self.month or other.month |
| 418 | day = min(monthrange(year, month)[1], self.day or other.day) |
| 419 | ret = other.replace(**dict(dictfilter(self._fields()), |
| 420 | year=year, month=month, day=day)) |
| 421 | if self.weekday is not None: |
| 422 | ret += timedelta(days=(7 - ret.weekday() + self.weekday) % 7) |
| 423 | return ret + timedelta(days=self.days) |
| 424 | |
| 425 | def _fields(self, **extra: Any) -> dict[str, Any]: |
| 426 | return dictfilter({ |
| 427 | 'year': self.year, 'month': self.month, 'day': self.day, |
| 428 | 'hour': self.hour, 'minute': self.minute, |
| 429 | 'second': self.second, 'microsecond': self.microsecond, |
| 430 | }, **extra) |
| 431 | |
| 432 | |
| 433 | def utcoffset( |
no outgoing calls