aboutsummaryrefslogtreecommitdiff
path: root/page/time.go
blob: 0374490f00a46ecff07cf2ea59c1e8ea997e6351 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package page

import (
	"gopkg.in/yaml.v3"
	"time"
)

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"

func (pt *PageTime) UnmarshalYAML(n *yaml.Node) error {
	t, err := time.Parse(TimeFormat, n.Value)
	if err != nil {
		return err
	}
	pt.Time = t
	return nil
}

func (pt PageTime) MarshalYAML() (interface{}, error) {
	s := pt.Time.Format(TimeFormat)
	return s, nil
}