package page import ( "fmt" "time" "gopkg.in/yaml.v3" ) // PageTime allows us to slip in a different time format for loading/unloading // the yaml from disk than the default. type PageTime struct { time.Time } // TimeFormat is the format string used when unmarshaling the time // from the yaml information. var TimeFormat = "01.02.2006 15:04:05 MST" // UnmarshalYAML override the default and parse our time with the global time // format. func (pt *PageTime) UnmarshalYAML(n *yaml.Node) error { t, err := time.Parse(TimeFormat, n.Value) if err != nil { return fmt.Errorf("pagetime: %w", err) } pt.Time = t return nil } // MarshalYAML override the default with our own time format. func (pt PageTime) MarshalYAML() (interface{}, error) { s := pt.Time.Format(TimeFormat) return s, nil }