summaryrefslogtreecommitdiffstats
path: root/langs
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2021-07-27 13:45:05 +0200
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2021-07-27 19:02:48 +0200
commitefa5760db5ef39ae084bfccb5b8f756c7b117a2a (patch)
tree7c70d6665f34ca25a443f5a51ce956a3fa729282 /langs
parenta57dda854b5efd3429af5f0b1564fc9d9d5439b9 (diff)
Add timezone support for front matter dates without one
Fixes #8810
Diffstat (limited to 'langs')
-rw-r--r--langs/language.go22
1 files changed, 21 insertions, 1 deletions
diff --git a/langs/language.go b/langs/language.go
index 5f5e8ddef..6f39848cf 100644
--- a/langs/language.go
+++ b/langs/language.go
@@ -17,6 +17,7 @@ import (
"sort"
"strings"
"sync"
+ "time"
translators "github.com/bep/gotranslators"
"github.com/go-playground/locales"
@@ -71,10 +72,13 @@ type Language struct {
paramsMu sync.Mutex
paramsSet bool
- // Used for date formatting etc. We don't want this exported to the
+ // Used for date formatting etc. We don't want these exported to the
// templates.
// TODO(bep) do the same for some of the others.
translator locales.Translator
+
+ locationInit sync.Once
+ location *time.Location
}
func (l *Language) String() string {
@@ -244,9 +248,25 @@ func (l *Language) IsSet(key string) bool {
return l.Cfg.IsSet(key)
}
+func (l *Language) getLocation() *time.Location {
+ l.locationInit.Do(func() {
+ location, err := time.LoadLocation(l.GetString("timeZone"))
+ if err != nil {
+ location = time.UTC
+ }
+ l.location = location
+ })
+
+ return l.location
+}
+
// Internal access to unexported Language fields.
// This construct is to prevent them from leaking to the templates.
func GetTranslator(l *Language) locales.Translator {
return l.translator
}
+
+func GetLocation(l *Language) *time.Location {
+ return l.getLocation()
+}