pkger/pkging/mod_time.go

25 lines
386 B
Go
Raw Permalink Normal View History

2019-09-02 01:02:45 +03:00
package pkging
2019-09-02 00:50:21 +03:00
import (
"encoding/json"
"time"
)
const timeFmt = time.RFC3339Nano
type ModTime time.Time
func (m ModTime) MarshalJSON() ([]byte, error) {
t := time.Time(m)
return json.Marshal(t.Format(timeFmt))
}
func (m *ModTime) UnmarshalJSON(b []byte) error {
t := time.Time{}
if err := json.Unmarshal(b, &t); err != nil {
return err
}
(*m) = ModTime(t)
return nil
}