Skip to content

fix(parser): stop the .msg date test depending on the host timezone - #19182

Merged
JinHai-CN merged 1 commit into
infiniflow:mainfrom
devYRPauli:fix/msg-date-test-timezone
Sep 3, 2026
Merged

JinHai-CN merged 1 commit into
infiniflow:mainfrom
devYRPauli:fix/msg-date-test-timezone

Conversation

@devYRPauli

Copy link
Copy Markdown
Contributor

Summary

TestEmailParser_MsgSupported asserts the literal string 2018-03-24 00:06:29+0800. The test only passes on a host at +0800.

formatMsgDate renders msg.Date with the -0700 layout. gomsg builds that time in filetimeToTime with time.Unix, which returns a time.Time in the local location. The rendered offset follows TZ, so the correct expected string does too.

Measured on 4168b3f9d, one run per zone:

TZ result
Asia/Shanghai ok
America/New_York FAIL, got "2018-03-23 12:06:29-0400"
UTC FAIL, got "2018-03-23 16:06:29+0000"
Europe/Berlin FAIL, got "2018-03-23 17:06:29+0100"

All four strings are the same instant. docker/.env line 291 sets TZ=Asia/Shanghai, so CI stays green. A contributor in another zone gets a red package on a clean checkout.

The parser is correct, so this PR does not touch it. The test now parses the value with the same layout and compares the instant.

if v, ok := item["date"].(string); !ok {
	t.Errorf("date: got %T, want string", item["date"])
} else if got, err := time.Parse("2006-01-02 15:04:05-0700", v); err != nil {
	t.Errorf("date %q: %v", v, err)
} else if want := time.Date(2018, 3, 23, 16, 6, 29, 0, time.UTC); !got.Equal(want) {
	t.Errorf("date: got %q = %v, want %v", v, got.UTC(), want)
}

The new assertion passes under Asia/Shanghai, America/New_York, UTC, Europe/Berlin, Australia/Sydney, Asia/Kolkata and Pacific/Kiritimati.

It still catches a broken formatMsgDate. I applied each mutation to the parser and ran the test under America/New_York:

mutation failure
layout -07:00 instead of -0700 cannot parse "-04:00" as "-0700"
t.Add(time.Hour) before the format got "2018-03-23 13:06:29-0400" = 2018-03-23 17:06:29 +0000 UTC, want 2018-03-23 16:06:29 +0000 UTC
zone dropped from the layout cannot parse "" as "-0700"

TestEmailParser_MsgSupported asserted the literal string
"2018-03-24 00:06:29+0800". That value only holds on a host at +0800.

formatMsgDate renders msg.Date with the "-0700" layout. gomsg builds that
time in filetimeToTime with time.Unix, which returns a Time in the local
location. The rendered offset therefore follows TZ.

Measured on 4168b3f, with TZ set for one run each:

  Asia/Shanghai     ok
  America/New_York  got "2018-03-23 12:06:29-0400"
  UTC               got "2018-03-23 16:06:29+0000"
  Europe/Berlin     got "2018-03-23 17:06:29+0100"

Parse the value with the same layout and compare the instant. That keeps
both properties the old assertion checked, the layout and the time, and
drops the host dependency. The parser is unchanged.

Signed-off-by: Yash Raj Pandey <[email protected]>
@coderabbitai

coderabbitai Bot commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Team

Run ID: 8ff1fbf0-83b0-450d-8bd4-0baa5de4b3d2

📥 Commits

Reviewing files that changed from the base of the PR and between 4168b3f and 4b8bbda.

📒 Files selected for processing (1)
  • internal/parser/parser/email_parser_test.go

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

The MSG date test now parses the rendered date and compares the result with the expected UTC instant. This removes dependence on the host timezone.

Changes

Timezone-independent test validation

Layer / File(s) Summary
Parse MSG date before comparison
internal/parser/parser/email_parser_test.go
The test parses the date with a fixed layout and compares it with 2018-03-23 16:06:29 UTC.

Estimated code review effort: 1 (Trivial) | ~2 minutes

Merge Risk: ⚪ Minimal · up to 4b8bb

This change makes the existing date test independent of the host timezone without altering production behavior. No actionable merge-blocking risk remains after normal checks and review.

Suggested reviewers: xugangqiang, euvre

Poem

A rabbit reads each line,
The patch grows clear beneath the moon,
Small changes hop in place,
Tests guard the garden path,
Reviews bloom before the dawn.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: removing host-timezone dependence from the .msg date test.
Description check ✅ Passed The description includes the required Summary section and provides clear background, failure examples, implementation details, and validation results.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 1 files.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@JinHai-CN JinHai-CN added the ci Continue Integration label Sep 3, 2026
@JinHai-CN JinHai-CN self-assigned this Sep 3, 2026
@JinHai-CN
JinHai-CN merged commit 7d9bcba into infiniflow:main Sep 3, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continue Integration

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants