package gojay
import (
"time"
)
func (enc *Encoder ) EncodeTime (t *time .Time , format string ) error {
if enc .isPooled == 1 {
panic (InvalidUsagePooledEncoderError ("Invalid usage of pooled encoder" ))
}
_, _ = enc .encodeTime (t , format )
_ , err := enc .Write ()
if err != nil {
return err
}
return nil
}
func (enc *Encoder ) encodeTime (t *time .Time , format string ) ([]byte , error ) {
enc .writeByte ('"' )
enc .buf = t .AppendFormat (enc .buf , format )
enc .writeByte ('"' )
return enc .buf , nil
}
func (enc *Encoder ) AddTimeKey (key string , t *time .Time , format string ) {
enc .TimeKey (key , t , format )
}
func (enc *Encoder ) TimeKey (key string , t *time .Time , format string ) {
if enc .hasKeys {
if !enc .keyExists (key ) {
return
}
}
enc .grow (10 + len (key ))
r := enc .getPreviousRune ()
if r != '{' {
enc .writeTwoBytes (',' , '"' )
} else {
enc .writeByte ('"' )
}
enc .writeStringEscape (key )
enc .writeBytes (objKeyStr )
enc .buf = t .AppendFormat (enc .buf , format )
enc .writeByte ('"' )
}
func (enc *Encoder ) AddTime (t *time .Time , format string ) {
enc .Time (t , format )
}
func (enc *Encoder ) Time (t *time .Time , format string ) {
enc .grow (10 )
r := enc .getPreviousRune ()
if r != '[' {
enc .writeByte (',' )
}
enc .writeByte ('"' )
enc .buf = t .AppendFormat (enc .buf , format )
enc .writeByte ('"' )
}
The pages are generated with Golds v0.8.2 . (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu .
PR and bug reports are welcome and can be submitted to the issue list .
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds .