- commit
- 32c42a05751a83b9cbb12054297c0a32aca03b18
- parent
- 7ee0200344cc546271b84cad9e71c20578b0d795
- Author
- Tobias Bengfort <tobias.bengfort@posteo.de>
- Date
- 2024-08-31 08:28
keep class on inheritance
Diffstat
| M | nominaldelta.py | 14 | +++++++------- |
1 files changed, 7 insertions, 7 deletions
diff --git a/nominaldelta.py b/nominaldelta.py
@@ -18,18 +18,18 @@ def date_add(dt, delta): 18 18 day = dt.day 19 19 while day > 0: 20 20 try:21 -1 tmp = date(year, month, day)-1 21 tmp = dt.__class__(year, month, day) 22 22 break 23 23 except ValueError: 24 24 day -= 1 25 2526 -1 return date.fromordinal(tmp.toordinal() + delta.days)-1 26 return dt.__class__.fromordinal(tmp.toordinal() + delta.days) 27 27 28 28 29 29 def dt_add(dt, delta): 30 30 d = date_add(dt.date(), delta) 31 31 offset = dt.timestamp() - date_to_timestamp(dt.date())32 -1 return datetime.fromtimestamp(-1 32 return dt.__class__.fromtimestamp( 33 33 date_to_timestamp(d) + offset + delta.seconds, tz=dt.tzinfo 34 34 ) 35 35 @@ -104,7 +104,7 @@ class NominalDelta: 104 104 105 105 def __add__(self: Self, other: Self) -> Self: 106 106 if isinstance(other, NominalDelta):107 -1 return NominalDelta(-1 107 return self.__class__( 108 108 months=self.months + other.months, 109 109 days=self.days + other.days, 110 110 seconds=self.seconds + other.seconds, @@ -113,7 +113,7 @@ class NominalDelta: 113 113 114 114 def __sub__(self: Self, other: Self) -> Self: 115 115 if isinstance(other, NominalDelta):116 -1 return NominalDelta(-1 116 return self.__class__( 117 117 months=self.months - other.months, 118 118 days=self.days - other.days, 119 119 seconds=self.seconds - other.seconds, @@ -121,11 +121,11 @@ class NominalDelta: 121 121 return NotImplemented 122 122 123 123 def __neg__(self: Self) -> Self:124 -1 return NominalDelta() - self-1 124 return self.__class__() - self 125 125 126 126 def __mul__(self: Self, factor: int) -> Self: 127 127 if isinstance(factor, int):128 -1 return NominalDelta(-1 128 return self.__class__( 129 129 months=self.months * factor, 130 130 days=self.days * factor, 131 131 seconds=self.seconds * factor,