Skip to content

Commit 2207fc6

Browse files
committed
Preliminary interval range add/subtract [doesn't work for all cases]
1 parent 9af31c0 commit 2207fc6

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/undate/converters/calendars/gregorian.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def max_day(self, year: int, month: int) -> int:
4040
_, max_day = monthrange(year, month)
4141
else:
4242
# if year and month are unknown, return maximum possible
43-
# TODO: should this return a ufloat?
43+
# TODO: should this return an IntervalRange?
4444
max_day = 31
4545

4646
return max_day

src/undate/date.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,24 @@ def __init__(self, lower: int, upper: int):
4949
raise ValueError(f"Lower value ({lower}) must be less than upper ({upper})")
5050
super().__init__(portion.closed(lower, upper))
5151

52+
def __sub__(self, other):
53+
# portion default subtraction is to remove from the set, but
54+
# we want to decrease the values
55+
if isinstance(other, int):
56+
return IntegerRange(self.lower - other, self.upper - other)
57+
elif isinstance(other, IntegerRange):
58+
# subtract the range respective endpoints
59+
return IntegerRange(self.lower - other.lower, self.upper - other.upper)
60+
61+
def __add__(self, other):
62+
# portion default subtraction is to remove from the set, but
63+
# we want to decrease the values
64+
if isinstance(other, int):
65+
return IntegerRange(self.lower + other, self.upper + other)
66+
elif isinstance(other, IntegerRange):
67+
# the new range is the smallest possible value to the highest
68+
return IntegerRange(self.lower + other.lower, self.upper - other.upper)
69+
5270

5371
@dataclass
5472
class Udelta:

0 commit comments

Comments
 (0)