Skip to content

fix(rules/en): parse 12 am as midnight - #55

Merged
olebedev merged 1 commit into
olebedev:masterfrom
Shaisolaris:fix-12am
Oct 14, 2026
Merged

olebedev merged 1 commit into
olebedev:masterfrom
Shaisolaris:fix-12am

Conversation

@Shaisolaris

Copy link
Copy Markdown
Contributor

The English Hour and HourMinute rules treat 12 am as noon:

w := when.New(nil)
w.Add(en.All...)
r, _ := w.Parse("at 12:30am", time.Date(2026, 1, 31, 10, 30, 0, 0, time.UTC))
// r.Time is 2026-01-31 12:30, expected 00:30

The same happens for 12am, 12 A.M. and 12:00 am tomorrow. The pm branch already leaves 12 as is and adds 12 to the other hours; the am branch used the hour as written, so 12 stayed 12. This maps 12 am to hour 0 in both rules.

Testing:

  • New fixtures in hour_test.go (at 12 am, 12A.M.) and hour_minute_test.go (12:30am, at 12:00 am, plus 12:30pm to pin the pm side) fail before the change and pass after.
  • go test ./... and go vet ./... pass.

The br and ru hour rules have the same am branch; I left them out because I can't confirm how 12 is written with those markers in those languages.

@Shaisolaris
Shaisolaris requested a review from olebedev as a code owner October 13, 2026 03:31

@olebedev olebedev left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Reviewed the midnight conversion in both English time rules. Tests and go vet pass on the PR combined with current master (Go 1.26.7).

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