diff options
Diffstat (limited to 'page/time.go')
| -rw-r--r-- | page/time.go | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/page/time.go b/page/time.go index 0374490..cd419c8 100644 --- a/page/time.go +++ b/page/time.go @@ -1,10 +1,14 @@ package page import ( - "gopkg.in/yaml.v3" + "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 } @@ -13,16 +17,22 @@ type PageTime struct { // 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 err + 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 } |
