]> Cypherpunks repositories - gostls13.git/commitdiff
time: simplify stringification of Month
authorMartin Möhrmann <moehrmann@google.com>
Sat, 12 Nov 2016 19:08:02 +0000 (20:08 +0100)
committerBrad Fitzpatrick <bradfitz@golang.org>
Sat, 12 Nov 2016 21:24:06 +0000 (21:24 +0000)
Simplifies https://golang.org/cl/33145
which fixed #17720.

Change-Id: Ib922d493cdc5920832dc95b55094796baca7243e
Reviewed-on: https://go-review.googlesource.com/33194
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/time/time.go

index 00fafb64ddf91f7953007b339ace5d52df014796..10b32461e1cd3b974c3988a9011c3ca7aa654e00 100644 (file)
@@ -118,13 +118,9 @@ func (m Month) String() string {
        if January <= m && m <= December {
                return months[m-1]
        }
-       const prefix = "%!Month("
-       buf := make([]byte, 20+len(prefix)+1)
-       buf[len(buf)-1] = ')'
-       n := fmtInt(buf[:len(buf)-1], uint64(m))
-       n -= len(prefix)
-       copy(buf[n:], prefix)
-       return string(buf[n:])
+       buf := make([]byte, 20)
+       n := fmtInt(buf, uint64(m))
+       return "%!Month(" + string(buf[n:]) + ")"
 }
 
 // A Weekday specifies a day of the week (Sunday = 0, ...).