nominaldelta

nominal difference of date/datetime
git clone https://git.ce9e.org/nominaldelta.git

commit
3c7d7fabcb01d82cc361d8415663db573ed51124
parent
125a4fbda06d0b6f3ca17f5a427cf98af43a9a3c
Author
Tobias Bengfort <tobias.bengfort@posteo.de>
Date
2024-08-31 14:26
typing: use Date TypeVar

Diffstat

M nominaldelta.py 7 ++++---

1 files changed, 4 insertions, 3 deletions


diff --git a/nominaldelta.py b/nominaldelta.py

@@ -3,6 +3,7 @@ from datetime import datetime
    3     3 from typing import TypeVar
    4     4 
    5     5 Self = TypeVar('Self', bound='NominalDelta')
   -1     6 Date = TypeVar('Date', bound=date)
    6     7 
    7     8 
    8     9 def date_to_timestamp(d):
@@ -146,18 +147,18 @@ class NominalDelta:
  146   147     def __rmul__(self: Self, factor: int) -> Self:
  147   148         return self * factor
  148   149 
  149    -1     def __radd__(self: Self, other: date) -> date:
   -1   150     def __radd__(self: Self, other: Date) -> Date:
  150   151         if isinstance(other, datetime):
  151   152             return dt_add(other, self)
  152   153         elif isinstance(other, date):
  153   154             return date_add(other, self)
  154   155         return NotImplemented
  155   156 
  156    -1     def __rsub__(self: Self, other: date) -> date:
   -1   157     def __rsub__(self: Self, other: Date) -> Date:
  157   158         return (-self).__radd__(other)
  158   159 
  159   160     @classmethod
  160    -1     def diff(cls: type[Self], a: date, b: date, *, allow_months: bool = True) -> Self:
   -1   161     def diff(cls: type[Self], a: Date, b: Date, *, allow_months: bool = True) -> Self:
  161   162         if isinstance(a, datetime) and isinstance(b, datetime):
  162   163             return dt_diff(a, b, allow_months=allow_months)
  163   164         elif isinstance(a, date) and isinstance(b, date):