Files
zephyr/types/date.go

36 lines
542 B
Go
Raw Normal View History

2025-06-17 10:11:10 +02:00
package types
import (
"strings"
"time"
)
type ZephyrDate struct {
2025-06-18 08:44:52 +02:00
Date time.Time
2025-06-17 10:11:10 +02:00
}
func (date *ZephyrDate) UnmarshalJSON(b []byte) error {
s := strings.Trim(string(b), "\"")
if s == "" {
return nil
}
var err error
2025-06-18 08:44:52 +02:00
date.Date, err = time.Parse("Monday, 2006/01/02", s)
2025-06-17 10:11:10 +02:00
if err != nil {
return err
}
return nil
}
func (date *ZephyrDate) MarshalJSON() ([]byte, error) {
2025-06-18 08:44:52 +02:00
if date.Date.IsZero() {
2025-06-17 10:11:10 +02:00
return []byte("\"\""), nil
}
2025-06-18 08:44:52 +02:00
fmtDate := date.Date.Format("Monday, 2006/01/02")
2025-06-17 10:11:10 +02:00
return []byte("\"" + fmtDate + "\""), nil
}