MCPcopy Create free account
hub / github.com/celery/celery / ffwd

Class ffwd

celery/utils/time.py:476–517  ·  view source on GitHub ↗

Version of ``dateutil.relativedelta`` that only supports addition.

Source from the content-addressed store, hash-verified

474
475
476class ffwd:
477 """Version of ``dateutil.relativedelta`` that only supports addition."""
478
479 def __init__(self, year=None, month=None, weeks=0, weekday=None, day=None,
480 hour=None, minute=None, second=None, microsecond=None,
481 **kwargs: Any):
482 # pylint: disable=redefined-outer-name
483 # weekday is also a function in outer scope.
484 self.year = year
485 self.month = month
486 self.weeks = weeks
487 self.weekday = weekday
488 self.day = day
489 self.hour = hour
490 self.minute = minute
491 self.second = second
492 self.microsecond = microsecond
493 self.days = weeks * 7
494 self._has_time = self.hour is not None or self.minute is not None
495
496 def __repr__(self) -> str:
497 return reprcall('ffwd', (), self._fields(weeks=self.weeks,
498 weekday=self.weekday))
499
500 def __radd__(self, other: Any) -> timedelta:
501 if not isinstance(other, date):
502 return NotImplemented
503 year = self.year or other.year
504 month = self.month or other.month
505 day = min(monthrange(year, month)[1], self.day or other.day)
506 ret = other.replace(**dict(dictfilter(self._fields()),
507 year=year, month=month, day=day))
508 if self.weekday is not None:
509 ret += timedelta(days=(7 - ret.weekday() + self.weekday) % 7)
510 return ret + timedelta(days=self.days)
511
512 def _fields(self, **extra: Any) -> dict[str, Any]:
513 return dictfilter({
514 'year': self.year, 'month': self.month, 'day': self.day,
515 'hour': self.hour, 'minute': self.minute,
516 'second': self.second, 'microsecond': self.microsecond,
517 }, **extra)
518
519
520def utcoffset(

Callers 5

test_remainingFunction · 0.90
test_reprMethod · 0.90
_delta_to_nextMethod · 0.85
remaining_deltaMethod · 0.85

Calls

no outgoing calls

Tested by 3

test_remainingFunction · 0.72
test_reprMethod · 0.72