1
0
mirror of https://github.com/golang/go synced 2024-11-20 00:24:43 -07:00

time: simplify stringification of Month

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>
This commit is contained in:
Martin Möhrmann 2016-11-12 20:08:02 +01:00 committed by Brad Fitzpatrick
parent 4bee9012b3
commit 524cd4855e

View 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, ...).