}
// String returns the English name of the day ("Sunday", "Monday", ...).
-func (d Weekday) String() string { return days[d] }
+func (d Weekday) String() string {
+ if Sunday <= d && d <= Saturday {
+ return days[d]
+ }
+ buf := make([]byte, 20)
+ n := fmtInt(buf, uint64(d))
+ return "%!Weekday(" + string(buf[n:]) + ")"
+}
// Computations on time.
//
Date(0, 1, 2, 3, 4, 5, 6, UTC),
Date(7, 8, 9, 10, 11, 12, 13, FixedZone("", 0)),
Unix(81985467080890095, 0x76543210), // Time.sec: 0x0123456789ABCDEF
- {}, // nil location
+ {}, // nil location
Date(1, 2, 3, 4, 5, 6, 7, FixedZone("", 32767*60)),
Date(1, 2, 3, 4, 5, 6, 7, FixedZone("", -32768*60)),
}
}
}
+// Issue 24692: Out of range weekday panics
+func TestWeekdayString(t *testing.T) {
+ if got, want := Weekday(Tuesday).String(), "Tuesday"; got != want {
+ t.Errorf("Tuesday weekday = %q; want %q", got, want)
+ }
+ if got, want := Weekday(14).String(), "%!Weekday(14)"; got != want {
+ t.Errorf("14th weekday = %q; want %q", got, want)
+ }
+}
+
func TestReadFileLimit(t *testing.T) {
const zero = "/dev/zero"
if _, err := os.Stat(zero); err != nil {