Skip to content

Fix timezone-aware datetime conversion#128

Merged
hownowstephen merged 3 commits into
mainfrom
fix/datetime-timezone-handling
May 22, 2026
Merged

Fix timezone-aware datetime conversion#128
hownowstephen merged 3 commits into
mainfrom
fix/datetime-timezone-handling

Conversation

@hownowstephen
Copy link
Copy Markdown
Contributor

@hownowstephen hownowstephen commented May 22, 2026

Summary

  • _datetime_to_timestamp() used dt.replace(tzinfo=timezone.utc) which silently discards existing timezone info instead of converting — a datetime at UTC-5 would be treated as UTC, producing the wrong timestamp
  • Now uses dt.astimezone(timezone.utc) for tz-aware datetimes, preserving dt.replace() only for naive datetimes (backward compatible)
  • 3 new tests covering naive, tz-aware UTC, and tz-aware non-UTC datetimes

Test plan

  • Naive datetime produces same result as before (backward compat)
  • Tz-aware UTC datetime produces correct timestamp
  • Tz-aware non-UTC datetime (UTC-5) correctly converts
  • All 51 tests pass

🤖 Generated with Claude Code


Note

Medium Risk
Changes how timestamps are generated for tz-aware datetime values, which can alter event/customer data sent to the API for non-UTC inputs. Scope is small and covered by added unit tests, but impacts payload correctness.

Overview
Fixes datetime sanitization so timezone-aware datetime values are converted to UTC before timestamping (using astimezone(timezone.utc)) instead of silently overriding their timezone via replace().

Keeps prior behavior for naive datetimes (assumed UTC) and adds tests for naive, UTC-aware, and non-UTC-aware datetime inputs to prevent regressions.

Reviewed by Cursor Bugbot for commit c7fd1cc. Bugbot is set up for automated code reviews on this repo. Configure here.

Previously, dt.replace(tzinfo=timezone.utc) silently discarded any
existing timezone info, treating e.g. a UTC-5 datetime as if it were
UTC. Now tz-aware datetimes use astimezone() for proper conversion,
while naive datetimes continue to be assumed UTC for backward compat.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 9721b45. Configure here.

Comment thread tests/test_customerio.py Outdated
@hownowstephen hownowstephen merged commit 147793a into main May 22, 2026
10 checks passed
@hownowstephen hownowstephen deleted the fix/datetime-timezone-handling branch May 22, 2026 13:59
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.

2 participants