github.com/LazyboyChen7/engine@v17.12.1-ce-rc2+incompatible/daemon/logger/jsonfilelog/jsonlog/time_marshalling.go (about)

     1  package jsonlog
     2  
     3  import (
     4  	"time"
     5  
     6  	"github.com/pkg/errors"
     7  )
     8  
     9  const jsonFormat = `"` + time.RFC3339Nano + `"`
    10  
    11  // fastTimeMarshalJSON avoids one of the extra allocations that
    12  // time.MarshalJSON is making.
    13  func fastTimeMarshalJSON(t time.Time) (string, error) {
    14  	if y := t.Year(); y < 0 || y >= 10000 {
    15  		// RFC 3339 is clear that years are 4 digits exactly.
    16  		// See golang.org/issue/4556#c15 for more discussion.
    17  		return "", errors.New("time.MarshalJSON: year outside of range [0,9999]")
    18  	}
    19  	return t.Format(jsonFormat), nil
    20  }