|
|
- package grmi
-
- import (
- "fmt"
- json "github.com/json-iterator/go"
- "leit.com/LAPP_CHEERSSON_BACKEND/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
- }
- if jsonString == "0001-01-01" {
- *self = Date(time.Time{})
- return nil
- }
- 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)
- }
|