func encodeTime(t time.Time) []byte {
	tsecs, tnsecs := t.Unix(), t.Nanosecond()
	var (
		bd   byte
		btmp [8]byte
		bs   [16]byte
		i    int = 1
	)
	l := t.Location()
	if l == time.UTC {
		l = nil
	}
	if tsecs != 0 {
		bd = bd | 0x80
		bigen.PutUint64(btmp[:], uint64(tsecs))
		f := pruneSignExt(btmp[:], tsecs >= 0)
		bd = bd | (byte(7-f) << 2)
		copy(bs[i:], btmp[f:])
		i = i + (8 - f)
	}
	if tnsecs != 0 {
		bd = bd | 0x40
		bigen.PutUint32(btmp[:4], uint32(tnsecs))
		f := pruneSignExt(btmp[:4], true)
		bd = bd | byte(3-f)
		copy(bs[i:], btmp[f:4])
		i = i + (4 - f)
	}
	if l != nil {
		bd = bd | 0x20
		_, zoneOffset := t.Zone()
		zoneOffset /= 60
		z := uint16(zoneOffset)
		bigen.PutUint16(btmp[:2], z)
		bs[i] = btmp[0] & 0x3f
		bs[i+1] = btmp[1]
		i = i + 2
	}
	bs[0] = bd
	return bs[0:i]
}
EncodeTime encodes a time.Time as a []byte, including
information on the instant in time and UTC offset.

Format Description

A timestamp is composed of 3 components:

- secs: signed integer representing seconds since unix epoch
- nsces: unsigned integer representing fractional seconds as a
nanosecond offset within secs, in the range 0 <= nsecs < 1e9
- tz: signed integer representing timezone offset in minutes east of UTC,
and a dst (daylight savings time) flag

When encoding a timestamp, the first byte is the descriptor, which
defines which components are encoded and how many bytes are used to
encode secs and nsecs components. *If secs/nsecs is 0 or tz is UTC, it
is not encoded in the byte array explicitly*.

Descriptor 8 bits are of the form `A B C DDD EE`:
A:   Is secs component encoded? 1 = true
B:   Is nsecs component encoded? 1 = true
C:   Is tz component encoded? 1 = true
DDD: Number of extra bytes for secs (range 0-7).
If A = 1, secs encoded in DDD+1 bytes.
If A = 0, secs is not encoded, and is assumed to be 0.
If A = 1, then we need at least 1 byte to encode secs.
DDD says the number of extra bytes beyond that 1.
E.g. if DDD=0, then secs is represented in 1 byte.
if DDD=2, then secs is represented in 3 bytes.
EE:  Number of extra bytes for nsecs (range 0-3).
If B = 1, nsecs encoded in EE+1 bytes (similar to secs/DDD above)

Following the descriptor bytes, subsequent bytes are:

secs component encoded in `DDD + 1` bytes (if A == 1)
nsecs component encoded in `EE + 1` bytes (if B == 1)
tz component encoded in 2 bytes (if C == 1)

secs and nsecs components are integers encoded in a BigEndian
2-complement encoding format.

tz component is encoded as 2 bytes (16 bits). Most significant bit 15 to
Least significant bit 0 are described below:

Timezone offset has a range of -12:00 to +14:00 (ie -720 to +840 minutes).
Bit 15 = have\_dst: set to 1 if we set the dst flag.
Bit 14 = dst\_on: set to 1 if dst is in effect at the time, or 0 if not.
Bits 13..0 = timezone offset in minutes. It is a signed integer in Big Endian format.
package codec
import (
	"fmt"
	"reflect"
	"time"
)
var (
	timeDigits   = [...]byte{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'}
	timeExtEncFn = func(rv reflect.Value) (bs []byte, err error) {
		defer panicToErr(&err)
		bs = timeExt{}.WriteExt(rv.Interface())
		return
	}
	timeExtDecFn = func(rv reflect.Value, bs []byte) (err error) {
		defer panicToErr(&err)
		timeExt{}.ReadExt(rv.Interface(), bs)
		return
	}
)
type timeExt struct{}
func (x timeExt) WriteExt(v interface{}) (bs []byte) {
	switch v2 := v.(type) {
	case time.Time:
		bs = encodeTime(v2)
	case *time.Time:
		bs = encodeTime(*v2)
	default:
		panic(fmt.Errorf("unsupported format for time conversion: expecting time.Time; got %T", v2))
	}
	return
}
func (x timeExt) ReadExt(v interface{}, bs []byte) {
	tt, err := decodeTime(bs)
	if err != nil {
		panic(err)
	}
	*(v.(*time.Time)) = tt
}
func (x timeExt) ConvertExt(v interface{}) interface{} {
	return x.WriteExt(v)
}
func (x timeExt) UpdateExt(v interface{}, src interface{}) {
	x.ReadExt(v, src.([]byte))
}