31 lines
596 B
Go
31 lines
596 B
Go
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
|
|
}
|