Skip to content
This repository has been archived by the owner on Feb 24, 2024. It is now read-only.

Prepending time formats when using RegisterTimeFormats #1170

Merged
merged 2 commits into from
Jul 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion binding/binding.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ var timeFormats = []string{
// RegisterTimeFormats allows to add custom time layouts that
// the binder will be able to use for decoding.
func RegisterTimeFormats(layouts ...string) {
timeFormats = append(timeFormats, layouts...)
timeFormats = append(layouts, timeFormats...)
}

// RegisterCustomDecorder allows to define custom type decoders.
Expand Down
11 changes: 11 additions & 0 deletions binding/binding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,14 @@ func TestParseTime(t *testing.T) {
expected := time.Date(2017, time.January, 1, 0, 0, 0, 0, time.UTC)
r.Equal(expected, tt)
}

func TestParseTimeConflicting(t *testing.T) {
RegisterTimeFormats("2006-02-01")

r := require.New(t)
tt, err := parseTime([]string{"2017-01-10"})

r.NoError(err)
expected := time.Date(2017, time.October, 1, 0, 0, 0, 0, time.UTC)
r.Equal(expected, tt)
}