Skip to content

Commit

Permalink
fix: timestamp issue in balance assertions
Browse files Browse the repository at this point in the history
this was causing unit tests to pass or fail on different test servers,
because of an off-by-one error on the balance assertion date, depending
on the timezone of the host the test was run on.
  • Loading branch information
redstreet committed Feb 11, 2024
1 parent c79f92c commit 92b5184
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,12 @@ If you want something else, simply override this method in individual importer

`smart` dates: Banks and credit cards typically have pending transactions that are not
included in downloads. When we download the next statement, new transactions may appear
prior to the balance assertion date that we generate for this statement. To attempt to
avoid this, we set the balance assertion date to either two days (fudge factor to
prior to the balance assertion date that we generate for this statement, which renders
this balance assertion invalid. This problem manifests occasionally as an existing
balance statement breaking when a new statement is downloaded and is an annoyance as it
needs manual fixing.

To minimize this, we set the balance assertion date to either two days (fudge factor to
account for pending transactions) before the statement's end date or the last
transaction's date, whichever is later. To choose a different fudge factor, simply set
`balance_assertion_date_fudge` in your config.
Expand Down
5 changes: 1 addition & 4 deletions beancount_reds_importers/libreader/ofxreader.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,8 @@ def get_available_cash(self, settlement_fund_balance=0):
def get_ofx_end_date(self, field='end_date'):
end_date = getattr(self.ofx_account.statement, field, None)

# Convert end_date from utc to local timezone if needed and return
# This is needed only if there is an actual timestamp other than time(0, 0)
if end_date:
if end_date.time() != datetime.time(0, 0):
end_date = end_date.replace(tzinfo=datetime.timezone.utc).astimezone()
# We don't care about timestamps, remove them so they don't affect date calculations
return end_date.date()

return None
Expand Down

0 comments on commit 92b5184

Please sign in to comment.