aboutsummaryrefslogtreecommitdiff
path: root/page/time.go
diff options
context:
space:
mode:
authorMitchell Riedstra <mitch@riedstra.dev>2021-10-24 12:52:38 -0400
committerMitchell Riedstra <mitch@riedstra.dev>2021-10-24 12:52:38 -0400
commit268fcf7e6b671d4959a12111d5abf553bf0a201b (patch)
tree6f5c46c9a765478eaae78d66f4b9aefc953bbd1a /page/time.go
parentd36b6a55c8fa4400cd39de717443e110e990a8a3 (diff)
downloadgo-website-268fcf7e6b671d4959a12111d5abf553bf0a201b.tar.gz
go-website-268fcf7e6b671d4959a12111d5abf553bf0a201b.tar.xz
Redis caching. Linter config and cleanup.
Diffstat (limited to 'page/time.go')
-rw-r--r--page/time.go14
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
}