第二代基于事件的高级计划排程引擎
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

37 lines
718 B

package grmi
import (
"encoding/json"
"fmt"
"leit.com/aps_engine/utils"
"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.ParseInLocation(URLDateFormat, jsonString, utils.TimezoneLocation)
if err != nil {
return err
}
*self = Date(result)
return nil
}
func (self *Date) Restore() time.Time {
return time.Time(*self)
}
func (self *Date) ToString() string {
date := self.Restore()
return date.Format(DateOutFormat)
}