]> Cypherpunks repositories - gostls13.git/commitdiff
time: fixed handling of "5" in Format's layout string
authorMarvin Stenger <marvin.stenger94@gmail.com>
Wed, 2 Sep 2015 22:39:53 +0000 (00:39 +0200)
committerRob Pike <r@golang.org>
Wed, 9 Sep 2015 18:41:34 +0000 (18:41 +0000)
Fixes #12440

Change-Id: Iead77fe34d986cfd5c16bac671fe13c8d012a754
Reviewed-on: https://go-review.googlesource.com/14178
Reviewed-by: Rob Pike <r@golang.org>
src/time/format.go
src/time/format_test.go

index 873d3ffde91d95a4282731ae7d87b9ccd4e0c0d7..6cf7946711470ed9bd316e979dc35e2626fb85f6 100644 (file)
@@ -518,7 +518,7 @@ func (t Time) AppendFormat(b []byte, layout string) []byte {
                case stdZeroMinute:
                        b = appendInt(b, min, 2)
                case stdSecond:
-                       b = appendInt(b, sec, 2)
+                       b = appendInt(b, sec, 0)
                case stdZeroSecond:
                        b = appendInt(b, sec, 2)
                case stdPM:
index ecc5c8f28a1d3ea6ed61398e1276bc7ff895dc40..d44347aed56a08a1f60212ed330eb9b747139a0c 100644 (file)
@@ -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) {
        years := []int{
                -100001, -100000, -99999,