Commit f4b4d2f4 authored by Edward Muller's avatar Edward Muller Committed by Rob Pike

time: _2006 is a literal _, followed by 2006

Otherwise _2006 is treated as _2 and then an error.

Fixes #11334

Change-Id: I40a385b45e279e9f4538bf419baab72781cdb215
Reviewed-on: https://go-review.googlesource.com/16311Reviewed-by: default avatarRob Pike <r@golang.org>
parent 2619dccf
......@@ -162,8 +162,12 @@ func nextStdChunk(layout string) (prefix string, std int, suffix string) {
}
return layout[0:i], stdDay, layout[i+1:]
case '_': // _2
case '_': // _2, _2006
if len(layout) >= i+2 && layout[i+1] == '2' {
//_2006 is really a literal _, followed by stdLongYear
if len(layout) >= i+5 && layout[i+1:i+5] == "2006" {
return layout[0 : i+1], stdLongYear, layout[i+5:]
}
return layout[0:i], stdUnderDay, layout[i+2:]
}
......
......@@ -529,3 +529,22 @@ func TestFormatSecondsInTimeZone(t *testing.T) {
}
}
}
// Issue 11334.
func TestUnderscoreTwoThousand(t *testing.T) {
format := "15:04_20060102"
input := "14:38_20150618"
time, err := Parse(format, input)
if err != nil {
t.Error(err)
}
if y, m, d := time.Date(); y != 2015 || m != 6 || d != 18 {
t.Errorf("Incorrect y/m/d, got %d/%d/%d", y, m, d)
}
if h := time.Hour(); h != 14 {
t.Errorf("Incorrect hour, got %d", h)
}
if m := time.Minute(); m != 38 {
t.Errorf("Incorrect minute, got %d", m)
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment