From 36936455e7805f824cb07fe9b23500a882426f98 Mon Sep 17 00:00:00 2001 From: xengineering Date: Sat, 7 Sep 2024 20:43:15 +0200 Subject: Implement Flow.since and Flow.until That way a flow can be limited to a certain time frame. --- finance/flow.py | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'finance/flow.py') diff --git a/finance/flow.py b/finance/flow.py index a5817af..9ea72c8 100644 --- a/finance/flow.py +++ b/finance/flow.py @@ -9,12 +9,22 @@ class Flow: """Time-discrete flow of money paid on the first day of a month""" amount: Decimal + since: None | datetime + until: None | datetime def integrate(self, start: datetime, end: datetime) -> Decimal: """Integrate the flow between two dates to an amount of money""" payments: int = 0 + if self.since is not None: + if start < self.since: + start = self.since + + if self.until is not None: + if end > self.until: + end = self.until + for candidate in monthly_candidates(start): if start <= candidate <= end: payments += 1 -- cgit v1.2.3-70-g09d2