}
// String returns the English name of the month ("January", "February", ...).
-func (m Month) String() string { return months[m-1] }
+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:])
+}
// A Weekday specifies a day of the week (Sunday = 0, ...).
type Weekday int
{"Truncate", func(t1, t2 Time) bool { return t1.Truncate(Hour).Equal(t2.Truncate(Hour)) }},
{"Round", func(t1, t2 Time) bool { return t1.Round(Hour).Equal(t2.Round(Hour)) }},
-
- {"== Time{}", func(t1, t2 Time) bool { return (t1==Time{}) == (t2==Time{}) }},
+
+ {"== Time{}", func(t1, t2 Time) bool { return (t1 == Time{}) == (t2 == Time{}) }},
}
func TestDefaultLoc(t *testing.T) {
t.Errorf("t0=%#v\nt1=%#v\nwant identical structures", t0, t1)
}
}
+
+// Issue 17720: Zero value of time.Month fails to print
+func TestZeroMonthString(t *testing.T) {
+ if got, want := Month(0).String(), "%!Month(0)"; got != want {
+ t.Errorf("zero month = %q; want %q", got, want)
+ }
+}