Added custom date type

This commit is contained in:
2025-06-17 10:11:10 +02:00
parent bac8c69382
commit 4844e946d3
3 changed files with 41 additions and 9 deletions

35
types/date.go Normal file
View File

@@ -0,0 +1,35 @@
package types
import (
"strings"
"time"
)
type ZephyrDate struct {
time.Time
}
func (date *ZephyrDate) UnmarshalJSON(b []byte) error {
s := strings.Trim(string(b), "\"")
if s == "" {
return nil
}
var err error
date.Time, err = time.Parse("Monday, 2006/01/02", s)
if err != nil {
return err
}
return nil
}
func (date *ZephyrDate) MarshalJSON() ([]byte, error) {
if date.Time.IsZero() {
return []byte("\"\""), nil
}
fmtDate := date.Time.Format("Monday, 2006/01/02")
return []byte("\"" + fmtDate + "\""), nil
}