diff options
author | xengineering <me@xengineering.eu> | 2024-09-07 20:43:15 +0200 |
---|---|---|
committer | xengineering <me@xengineering.eu> | 2024-09-08 17:21:32 +0200 |
commit | 36936455e7805f824cb07fe9b23500a882426f98 (patch) | |
tree | 5059f8b55ffcee5bcf6f4fa5d5ef91e6274524db /finance/flow.py | |
parent | 226f5afa968ead223baa5a1b0fafb481f9761f0f (diff) | |
download | finance-py-36936455e7805f824cb07fe9b23500a882426f98.tar finance-py-36936455e7805f824cb07fe9b23500a882426f98.tar.zst finance-py-36936455e7805f824cb07fe9b23500a882426f98.zip |
Implement Flow.since and Flow.until
That way a flow can be limited to a certain time frame.
Diffstat (limited to 'finance/flow.py')
-rw-r--r-- | finance/flow.py | 10 |
1 files changed, 10 insertions, 0 deletions
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 |