Skip to content

fix: correct timezone handling in datetime-based integration tests - #334

Merged
d-rk merged 1 commit into
mainfrom
fix/timezone-datetime-tests
Jul 30, 2026
Merged

d-rk merged 1 commit into
mainfrom
fix/timezone-datetime-tests

Conversation

@d-rk

@d-rk d-rk commented Jul 30, 2026

Copy link
Copy Markdown
Collaborator

Description

TestConsumeFromTimestampIntegration and TestResetCGOToDatetimeIntegration fail when run on any machine whose local timezone isn't UTC (e.g. make integration_test on a dev laptop set to Europe/Berlin), while passing fine in CI (which runs in UTC).

Root cause: both tests build a filter timestamp via time.Time.Format("2006-01-02T15:04:05.000Z"). The trailing Z in that layout is not a timezone-conversion directive (only Z07:00/Z0700 are) — it's just a literal character. Formatting a Local time.Time with it therefore produces the local wall-clock string with a misleading Z suffix that looks like UTC but isn't.

On the parsing side, internal/util.ParseTimestamp tries time.RFC3339 first via time.ParseInLocation(time.RFC3339, s, Local). Since the input string's Z matches RFC3339's Z07:00 zone verb, Go treats it as an explicit UTC marker and ignores the Local location argument (this is documented ParseInLocation behavior: an explicit zone in the input always wins over the passed-in location). The result: the parsed cutoff is off by exactly the host's UTC offset, shifting the query window away from the actual message timestamps and making both tests get empty results.

Fix: call .UTC() before formatting, so the literal Z is accurate.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Testing

  • Verified locally (Europe/Berlin, UTC+2 in July) that both tests fail before this change and pass after, without needing to force TZ=UTC.
  • Ran full go test -short ./... and the full cmd/consume/cmd/reset integration suites against a local docker-compose Kafka cluster — all pass.
  • golangci-lint run clean.

Test-only change, no user-facing behavior affected, so no CHANGELOG entry.

🤖 Generated with Claude Code

Format("...Z") only appends a literal Z, it doesn't convert to UTC. When
formatting a Local time.Time this way, the RFC3339 parser on the other
side reads the string as UTC, shifting the parsed instant by the host's
UTC offset. This made TestConsumeFromTimestampIntegration and
TestResetCGOToDatetimeIntegration fail on any non-UTC machine (e.g. CI
runs in UTC so it never surfaced there). Calling .UTC() before
formatting makes the literal Z accurate.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@d-rk
d-rk merged commit 5b661de into main Jul 30, 2026
5 checks passed
@d-rk
d-rk deleted the fix/timezone-datetime-tests branch July 30, 2026 09:52
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