Skip to content

refactor[#281]: whenever migration - replace stdlib datetime with whenever across fenn - #289

Merged
ApusBerliozi merged 4 commits into
pyfenn:mainfrom
AaronProbha18:feat/migrate-to-whenever
Jul 28, 2026
Merged

refactor[#281]: whenever migration - replace stdlib datetime with whenever across fenn#289
ApusBerliozi merged 4 commits into
pyfenn:mainfrom
AaronProbha18:feat/migrate-to-whenever

Conversation

@AaronProbha18

Copy link
Copy Markdown
Contributor

Fixes: #281

Changes

  • Migrated all datetime usage in fenn/logging.py, fenn/reproducibility.py, fenn/cli/pull.py, fenn/dashboard/app.py and fenn/dashboard/scanner.py to the whenever library.
  • Added whenever>=0.10.3 to the project dependencies in pyproject.toml.
  • Replaced datetime.now() and datetime.now().replace(microsecond=0) with whenever equivalents using Instant/PlainDateTime (Instant.now().to_system_tz().to_plain()).
  • Replaced datetime.fromtimestamp(ts, tz=timezone.utc) with Instant.from_timestamp(ts) for UTC log-entry timestamps.
  • Replaced datetime.strptime(...) parsing (used for the session started field and the /api/sessions started_after/started_before query parameters) with PlainDateTime.parse(..., format=...).
  • Replaced the duration calculation ((ended_at - started_at).total_seconds()) with PlainDateTime.difference(..., naive_arithmetic_ok=True).total("seconds").
  • Replaced datetime.now(timezone.utc).isoformat() in fenn/cli/pull.py's template registry with a small _isoformat_utc_now() helper in cli/utils.py.

Notes

  • All formatting and parsing calls now use explicit whenever pattern strings (such as "YYYY-MM-DD hh:mm:ss" and "YYYYMMDD_hhmm") instead of relying on the library’s default string or ISO formatting. This is important because the default output includes a T separator and nanosecond precision with a Z UTC suffix, which would change the existing on-disk formats. By using explicit patterns, we ensure that all stored strings in .fn XML files, .log files, the template registry, and session IDs remain exactly byte-for-byte identical to what was produced by the previous standard library implementation.
  • The PERMANENT_SESSION_LIFETIME setting was intentionally left using the standard library timedelta because it is a Flask/Werkzeug configuration value. Flask internally expects a standard datetime.timedelta when calculating session expiration. Specifically, SessionInterface.get_expiration_time adds datetime.now(timezone.utc) to this value, and mixing it with whenever.TimeDelta would cause a type error since the two types are incompatible. For this reason, it must remain a standard library timedelta and is excluded from the migration.
  • The test_reproducibility.py test for timestamp behavior was also updated because it previously mocked fenn.reproducibility.datetime, which no longer exists after switching to whenever. Timestamps are now generated using Instant, which is an immutable Rust-backed type and cannot be monkeypatched directly. As a result, the test was adjusted to mock the module-level Instant reference instead.

@ApusBerliozi ApusBerliozi added enhancement New feature or request code quality refactor Code is refactored labels Jul 28, 2026
@ApusBerliozi
ApusBerliozi self-requested a review July 28, 2026 06:45
@github-project-automation github-project-automation Bot moved this to Todo in Roadmap Jul 28, 2026
Comment thread fenn/cli/utils.py Outdated
Comment thread fenn/dashboard/app.py
@ApusBerliozi
ApusBerliozi merged commit 2ae1d03 into pyfenn:main Jul 28, 2026
7 checks passed
@github-project-automation github-project-automation Bot moved this from Todo to Done in Roadmap Jul 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

code quality enhancement New feature or request refactor Code is refactored

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Replace datetime with whenever

2 participants