Browse Source

增加了日期类型

pull/20/head
allanwei 4 years ago
parent
commit
324536d1c0
2 changed files with 33 additions and 0 deletions
  1. +31
    -0
      grmi/Date.go
  2. +2
    -0
      grmi/grmi.go

+ 31
- 0
grmi/Date.go View File

@ -0,0 +1,31 @@
package grmi
import (
"encoding/json"
"fmt"
"time"
)
type Date time.Time
func (self Date) MarshalJSON() ([]byte, error) {
return []byte(fmt.Sprintf("\"%s\"", time.Time(self).Format(URLDateFormat))), nil
}
func (self *Date) UnmarshalJSON(data []byte) error {
var jsonString string
err := json.Unmarshal(data, &jsonString)
if err != nil {
return err
}
result, err := time.Parse(URLDateFormat, jsonString)
if err != nil {
return err
}
*self = Date(result)
return nil
}
func (self *Date) Restore() time.Time {
return time.Time(*self)
}

+ 2
- 0
grmi/grmi.go View File

@ -15,6 +15,7 @@ type GoType int
const (
URLDateTimeFormat = "20060102150405"
URLDateFormat = "20060102"
)
const (
@ -30,6 +31,7 @@ const (
TypeUint64
TypeFloat32
TypeFloat64
TypeDate
TypeDateTime
TypeBool
TypeString


Loading…
Cancel
Save