Skip to content

time: Parse of am/pm should be forgiving of spaces and case #51320

@spekary

Description

@spekary

What version of Go are you using (go version)?

1.17.5

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
Mac OS

What did you do?

import (
"testing"
"time"
)

func TestParse(t *testing.T) {
var tm time.Time
var err error

tm, err = time.Parse("3:04PM", "5:23 PM")
if err != nil {
	t.Error(err)
}
if tm.Hour() != 17 {
	t.Error("hour does not match")
}

tm, err = time.Parse("3:04pm", "5:23PM")
if err != nil {
	t.Error(err)
}
if tm.Hour() != 17 {
	t.Error("hour does not match")
}

}

What did you expect to see?

Tests pass

What did you see instead?

=== RUN TestParse
parse_test.go:14: parsing time "5:23 PM" as "3:04PM": cannot parse "M" as "PM"
parse_test.go:17: hour does not match
parse_test.go:22: parsing time "5:23PM" as "3:04pm": cannot parse "" as "pm"
parse_test.go:25: hour does not match
--- FAIL: TestParse (0.00s)

Metadata

Metadata

Assignees

No one assigned

    Labels

    NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions