mc-webserver/utils/yaml/date-type.go
2023-08-13 20:19:47 +01:00

32 lines
506 B
Go

package yaml
import (
"gopkg.in/yaml.v3"
"strings"
"time"
)
const dateFormat = "02/01/2006"
type DateType struct {
time.Time
}
func (dt *DateType) MarshalYAML() (interface{}, error) {
return dt.Time.Format(dateFormat), nil
}
func (dt *DateType) UnmarshalYAML(value *yaml.Node) error {
var stringIn string
err := value.Decode(&stringIn)
if err != nil {
return nil
}
pt, err := time.Parse(dateFormat, strings.TrimSpace(stringIn))
if err != nil {
return err
}
dt.Time = pt
return nil
}