Ensure all dates returned are ISO8601
This commit is contained in:
30
model/date.go
Normal file
30
model/date.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Date time.Time
|
||||
|
||||
func (d Date) Equal(other Date) bool {
|
||||
return time.Time(d).Equal(time.Time(other))
|
||||
}
|
||||
|
||||
func (d Date) After(other Date) bool {
|
||||
return time.Time(d).After(time.Time(other))
|
||||
}
|
||||
|
||||
func (d Date) Before(other Date) bool {
|
||||
return time.Time(d).Before(time.Time(other))
|
||||
}
|
||||
|
||||
func (d Date) Format(layout string) string {
|
||||
return time.Time(d).Format(layout)
|
||||
}
|
||||
|
||||
func (t Date) MarshalJSON() ([]byte, error) {
|
||||
// Must use ISO8601
|
||||
formatted := fmt.Sprintf("\"%s\"", time.Time(t).Format("2006-01-02T15:04:05+00:00"))
|
||||
return []byte(formatted), nil
|
||||
}
|
||||
Reference in New Issue
Block a user