cityuni-webserver/utils/yaml/date-type.go
Captain ALM e1e78655bd
All checks were successful
continuous-integration/drone/push Build is passing
Squash Edge branch with data and full pure html / css page support.
2022-07-28 01:56:00 +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
}