27220ecc |
package jsonlog |
9ae3134d |
import (
"time"
|
27cfa68a |
"github.com/pkg/errors" |
9ae3134d |
)
|
27cfa68a |
const jsonFormat = `"` + time.RFC3339Nano + `"`
|
7de92de6 |
// fastTimeMarshalJSON avoids one of the extra allocations that |
d1a85078 |
// time.MarshalJSON is making. |
7de92de6 |
func fastTimeMarshalJSON(t time.Time) (string, error) { |
9ae3134d |
if y := t.Year(); y < 0 || y >= 10000 {
// RFC 3339 is clear that years are 4 digits exactly.
// See golang.org/issue/4556#c15 for more discussion. |
d1a85078 |
return "", errors.New("time.MarshalJSON: year outside of range [0,9999]") |
9ae3134d |
} |
27cfa68a |
return t.Format(jsonFormat), nil |
9ae3134d |
} |