Add support for timedelta operation on Timestamp.

This commit is contained in:
Sergio Martínez Portela 2021-02-07 23:59:35 +01:00
parent 88e709f7db
commit 608cefe02b

View File

@ -474,6 +474,23 @@ class Timestamp:
else: else:
return datetime(self.year, self.month, self.day, 0, 0) return datetime(self.year, self.month, self.day, 0, 0)
def __add__(self, delta: timedelta):
as_dt = self.to_datetime()
to_dt = as_dt + delta
return Timestamp(
self.active,
year=to_dt.year,
month=to_dt.month,
day=to_dt.day,
dow=None,
hour=to_dt.hour if self.hour is not None or to_dt.hour != 0 else None,
minute=to_dt.minute
if self.minute is not None or to_dt.minute != 0
else None,
repetition=self.repetition,
)
def __eq__(self, other): def __eq__(self, other):
if not isinstance(other, Timestamp): if not isinstance(other, Timestamp):
return False return False