]> Cypherpunks repositories - gostls13.git/commitdiff
time: do not crash in String on nil Time
authorRuss Cox <rsc@golang.org>
Thu, 2 Sep 2010 18:21:40 +0000 (14:21 -0400)
committerRuss Cox <rsc@golang.org>
Thu, 2 Sep 2010 18:21:40 +0000 (14:21 -0400)
R=r
CC=golang-dev
https://golang.org/cl/2052041

src/pkg/time/format.go

index 8166d2e77acc231a8509e5f3995c585ed14cb3af..355721e1839d2725e5a8d59ee91306f7eb4115f2 100644 (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