fix(cron): handle naive legacy timestamps in due-job checks#929
Closed
fix(cron): handle naive legacy timestamps in due-job checks#929
Conversation
Cherry-picked from PR #807 by 0xNyk, rebased onto current main. When HERMES_TIMEZONE differs from system local timezone, naive (legacy) timestamps were misinterpreted by _ensure_aware() — it stamped them with the Hermes timezone via replace(tzinfo=...), but they were created using datetime.now() (system local time). This could shift the absolute time and cause overdue jobs to appear not-due. Fix: interpret naive datetimes as system-local wall time first, then convert to Hermes timezone. Already-aware datetimes are normalized to Hermes timezone for consistent comparisons. Added 3 tests: - _ensure_aware preserves absolute time for naive datetimes - _ensure_aware normalizes aware datetimes to Hermes tz - get_due_jobs detects naive past timestamps as due even when Hermes tz is far behind system local tz (the scenario from #806) Fixes #806 Co-authored-by: Nyk <0xnykcd@googlemail.com>
1 task
Contributor
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Cherry-picked from PR #807 by @0xNyk, rebased onto current main with added tests.
The Bug (#806)
_ensure_aware()useddt.replace(tzinfo=hermes_tz)for naive datetimes, but those timestamps were created withdatetime.now()(system local time). WhenHERMES_TIMEZONEdiffers from the system timezone, this reinterprets the wall-clock time in the wrong timezone, shifting the absolute moment in time.Example: System in IST (UTC+5:30), HERMES_TIMEZONE=US/Eastern (UTC-5):
_hermes_now()= 07:00 EST — job appears NOT due ❌The Fix
astimezone()for consistent comparisonsTests Added (3 new)
test_ensure_aware_naive_preserves_absolute_time— verifies correct local→Hermes conversiontest_ensure_aware_normalizes_aware_to_hermes_tz— verifies aware datetime normalizationtest_get_due_jobs_naive_cross_timezone— integration test with Pacific/Midway (UTC-11) to catch the false not-due scenarioTest Results
64 passed, 3 skipped (timezone + cron suites)
Fixes #806
Closes #807