Add a __add__
method to your FakeDate()
class:
class FakeDate(datetime.date):
@classmethod
def today(cls):
return cls(1999, 12, 31)
def __add__(self, other):
res = super(FakeDate, self).__add__(other)
return type(self)(res.year, res.month, res.day)
Demo:
>>> class FakeDate(datetime.date):
... @classmethod
... def today(cls):
... return cls(1999, 12, 31)
... def __add__(self, other):
... res = super(FakeDate, self).__add__(other)
... return type(self)(res.year, res.month, res.day)
...
>>> FakeDate.today() + datetime.timedelta(days=1)
FakeDate(2000, 1, 1)
Note that you can simply delegate the actual adding to the datetime.date
class here; all we need to do is convert the result back to a FakeDate()
instance.