第二代基于事件的高级计划排程引擎
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.

44 lines
912 B

3 years ago
  1. package grmi
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "leit.com/aps_engine/utils"
  6. "time"
  7. )
  8. type DateTime time.Time
  9. const (
  10. URLDateTimeFormat = "20060102150405"
  11. URLDateFormat = "20060102"
  12. DateOutFormat = "2006-01-02"
  13. DatetimeOutFormat = "2006-01-02 15:04:05"
  14. )
  15. func (self DateTime) MarshalJSON() ([]byte, error) {
  16. return []byte(fmt.Sprintf("\"%s\"", time.Time(self).Format(URLDateTimeFormat))), nil
  17. }
  18. func (self *DateTime) UnmarshalJSON(data []byte) error {
  19. var jsonString string
  20. err := json.Unmarshal(data, &jsonString)
  21. if err != nil {
  22. return err
  23. }
  24. result, err := time.ParseInLocation(URLDateTimeFormat, jsonString, utils.TimezoneLocation)
  25. if err != nil {
  26. return err
  27. }
  28. *self = DateTime(result)
  29. return nil
  30. }
  31. func (self *DateTime) Restore() time.Time {
  32. return time.Time(*self)
  33. }
  34. func (self *DateTime) ToString() string {
  35. date := self.Restore()
  36. return date.Format(DatetimeOutFormat)
  37. }