Private
Public Access
1
0

Ensure all dates returned are ISO8601

This commit is contained in:
James Magahern
2024-01-05 16:26:19 -08:00
parent a8043e53b3
commit 831636216d
8 changed files with 53 additions and 24 deletions

30
model/date.go Normal file
View 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
}