diff options
Diffstat (limited to 'libgo/go/time/time.go')
-rw-r--r-- | libgo/go/time/time.go | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/libgo/go/time/time.go b/libgo/go/time/time.go index 294cc77f417..ef4ba5842de 100644 --- a/libgo/go/time/time.go +++ b/libgo/go/time/time.go @@ -180,7 +180,7 @@ func (d Weekday) String() string { return days[d] } // everywhere. // // The calendar runs on an exact 400 year cycle: a 400-year calendar -// printed for 1970-2469 will apply as well to 2470-2869. Even the days +// printed for 1970-2469 will apply as well to 2370-2769. Even the days // of the week match up. It simplifies the computations to choose the // cycle boundaries so that the exceptional years are always delayed as // long as possible. That means choosing a year equal to 1 mod 400, so @@ -935,7 +935,12 @@ func (t Time) MarshalJSON() ([]byte, error) { // See golang.org/issue/4556#c15 for more discussion. return nil, errors.New("Time.MarshalJSON: year outside of range [0,9999]") } - return []byte(t.Format(`"` + RFC3339Nano + `"`)), nil + + b := make([]byte, 0, len(RFC3339Nano)+2) + b = append(b, '"') + b = t.AppendFormat(b, RFC3339Nano) + b = append(b, '"') + return b, nil } // UnmarshalJSON implements the json.Unmarshaler interface. @@ -952,7 +957,9 @@ func (t Time) MarshalText() ([]byte, error) { if y := t.Year(); y < 0 || y >= 10000 { return nil, errors.New("Time.MarshalText: year outside of range [0,9999]") } - return []byte(t.Format(RFC3339Nano)), nil + + b := make([]byte, 0, len(RFC3339Nano)) + return t.AppendFormat(b, RFC3339Nano), nil } // UnmarshalText implements the encoding.TextUnmarshaler interface. |