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