Commit c12e38aa authored by Marvin Stenger's avatar Marvin Stenger Committed by Rob Pike

time: fixed handling of "5" in Format's layout string

Fixes #12440

Change-Id: Iead77fe34d986cfd5c16bac671fe13c8d012a754
Reviewed-on: https://go-review.googlesource.com/14178Reviewed-by: default avatarRob Pike <r@golang.org>
parent 1fbff651
...@@ -518,7 +518,7 @@ func (t Time) AppendFormat(b []byte, layout string) []byte { ...@@ -518,7 +518,7 @@ func (t Time) AppendFormat(b []byte, layout string) []byte {
case stdZeroMinute: case stdZeroMinute:
b = appendInt(b, min, 2) b = appendInt(b, min, 2)
case stdSecond: case stdSecond:
b = appendInt(b, sec, 2) b = appendInt(b, sec, 0)
case stdZeroSecond: case stdZeroSecond:
b = appendInt(b, sec, 2) b = appendInt(b, sec, 2)
case stdPM: case stdPM:
......
...@@ -74,6 +74,16 @@ func TestFormat(t *testing.T) { ...@@ -74,6 +74,16 @@ func TestFormat(t *testing.T) {
} }
} }
// issue 12440.
func TestFormatSingleDigits(t *testing.T) {
time := Date(2001, 2, 3, 4, 5, 6, 700000000, UTC)
test := FormatTest{"single digit format", "3:4:5", "4:5:6"}
result := time.Format(test.format)
if result != test.result {
t.Errorf("%s expected %q got %q", test.name, test.result, result)
}
}
func TestFormatShortYear(t *testing.T) { func TestFormatShortYear(t *testing.T) {
years := []int{ years := []int{
-100001, -100000, -99999, -100001, -100000, -99999,
......
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