mirror of
https://github.com/golang/go.git
synced 2025-05-22 16:09:37 +00:00
time: don't panic when stringifying Weekday
Fixes #24692 Change-Id: I14058cd3968d08fbcfc275f1b13b6dba9e3c5068 Reviewed-on: https://go-review.googlesource.com/106535 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
parent
2dfb423e6e
commit
94ef1dafbd
@ -323,7 +323,14 @@ var days = [...]string{
|
|||||||
}
|
}
|
||||||
|
|
||||||
// String returns the English name of the day ("Sunday", "Monday", ...).
|
// 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.
|
// Computations on time.
|
||||||
//
|
//
|
||||||
|
@ -1319,6 +1319,16 @@ func TestZeroMonthString(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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) {
|
func TestReadFileLimit(t *testing.T) {
|
||||||
const zero = "/dev/zero"
|
const zero = "/dev/zero"
|
||||||
if _, err := os.Stat(zero); err != nil {
|
if _, err := os.Stat(zero); err != nil {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user