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

time: do not crash in String on nil Time

R=r
CC=golang-dev
https://golang.org/cl/2052041
This commit is contained in:
Russ Cox 2010-09-02 14:21:40 -04:00
parent 8d7ae528bf
commit f699811c14

View File

@ -335,7 +335,12 @@ func (t *Time) Format(layout string) string {
}
// String returns a Unix-style representation of the time value.
func (t *Time) String() string { return t.Format(UnixDate) }
func (t *Time) String() string {
if t == nil {
return "<nil>"
}
return t.Format(UnixDate)
}
var errBad = os.ErrorString("bad") // just a marker; not returned to user