|
@@ -5,7 +5,6 @@ import (
|
|
|
"encoding/binary"
|
|
|
"errors"
|
|
|
"fmt"
|
|
|
- "github.com/vmihailenco/msgpack"
|
|
|
"strings"
|
|
|
"time"
|
|
|
)
|
|
@@ -14,10 +13,6 @@ type Date time.Time
|
|
|
|
|
|
const NormalDateFormat = "2006-01-02"
|
|
|
|
|
|
-func init() {
|
|
|
- msgpack.RegisterExt(1, (*Date)(nil))
|
|
|
-}
|
|
|
-
|
|
|
func (t Date) MarshalJSON() ([]byte, error) {
|
|
|
if y := t.Year(); y < 0 || y >= 10000 {
|
|
|
return nil, errors.New("Time.MarshalJSON: year outside of range [0,9999]")
|
|
@@ -63,31 +58,6 @@ func (t *Date) UnmarshalMsgpack(b []byte) error {
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
-func DateRegisterExt() {
|
|
|
- t := Date(time.Unix(123456789, 123))
|
|
|
- b, err := msgpack.Marshal(&t)
|
|
|
- if err != nil {
|
|
|
- panic(err)
|
|
|
- }
|
|
|
-
|
|
|
- var v interface{}
|
|
|
- err = msgpack.Unmarshal(b, &v)
|
|
|
- if err != nil {
|
|
|
- panic(err)
|
|
|
- }
|
|
|
- fmt.Println(v.(*Date).UTC())
|
|
|
-
|
|
|
- tm := &Date{}
|
|
|
- err = msgpack.Unmarshal(b, tm)
|
|
|
- if err != nil {
|
|
|
- panic(err)
|
|
|
- }
|
|
|
- fmt.Println(tm.UTC())
|
|
|
-
|
|
|
- // Output: 1973-11-29 21:33:09.000000123 +0000 UTC
|
|
|
- // 1973-11-29 21:33:09.000000123 +0000 UTC
|
|
|
-}
|
|
|
-
|
|
|
func (t Date) MarshalText() ([]byte, error) {
|
|
|
if y := t.Year(); y < 0 || y >= 10000 {
|
|
|
return nil, errors.New("Time.MarshalText: year outside of range [0,9999]")
|