Skip to content

fix: preserve time and offset in ISO datetime strings - #355

Open
ryanduguid wants to merge 2 commits into
arrobalytics:developfrom
ryanduguid:fix/preserve-iso-datetime-timestamps
Open

ryanduguid wants to merge 2 commits into
arrobalytics:developfrom
ryanduguid:fix/preserve-iso-datetime-timestamps

Conversation

@ryanduguid

@ryanduguid ryanduguid commented Sep 20, 2026 •

Copy link
Copy Markdown

validate_io_timestamp() parses ISO datetime strings, then combines the result with midnight. This discards the supplied time, fractional seconds and UTC offset. For example, with TIME_ZONE='America/New_York', committing 2024-07-01T00:35:27.123456+10:00 saves 2024-07-01T04:00:00Z instead of 2024-06-30T14:35:27.123456Z.

Return parsed datetimes before the date-only conversion. Naive datetime strings use the current timezone when USE_TZ=True and remain naive otherwise. Date-only strings retain their existing midnight behaviour. Regression coverage checks UTC and positive/negative offsets, fractional seconds, timezone settings, date-only inputs and the timestamp saved by commit_txs().

Validation on Windows with Python 3.12.10 and Django 6.0.1, using uv sync --locked --python 3.12:

  • The new regression cases fail on the original implementation and pass with this fix.
  • python manage.py test django_ledger.tests.test_io --noinput: 13 tests pass.
  • python manage.py test --noinput: 60 tests, 14 failing or erroring. Untouched upstream 5b4787b runs 55 tests with the same 14 failing test names (OFX helpers, transaction forms, UI messages and query counts). test_bill_detail depends on generated data: on both revisions it fails either its query count or a later account-detail URL reverse, so the failure/error split varies between runs.
  • Scoped Pylint with the repository's error-only options reports the same 10 existing mixin no-member errors in the changed module and upstream source. The test file has no errors.
  • git diff --check passes.

The complete Linux/Python 3.9 CI and full lint workflow were not reproduced locally. The manifest requires Python 3.11 or newer, and the lint workflow references an absent brickbox/ directory. This change affects newly parsed timestamps; it does not repair previously saved entries.

Django cannot save aware datetimes with USE_TZ disabled, so convert parsed
offset timestamps to the default time zone and drop the offset.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant