aboutsummaryrefslogtreecommitdiff
path: root/persistence
diff options
context:
space:
mode:
authorbodqhrohro <bodqhrohro@gmail.com>2019-12-12 01:48:35 +0300
committerbodqhrohro <bodqhrohro@gmail.com>2019-12-12 01:48:35 +0300
commit74a872a30bf023cf37d9d3d30e28c25d84c69ffe (patch)
tree1ae2497e083b21971fb027c53056301012213113 /persistence
parent9e785a56d29f617a29afb941476c73f43bcdb3cc (diff)
Timezone support
Diffstat (limited to 'persistence')
-rw-r--r--persistence/sessions.go21
1 files changed, 21 insertions, 0 deletions
diff --git a/persistence/sessions.go b/persistence/sessions.go
index 85c84be..efb32d3 100644
--- a/persistence/sessions.go
+++ b/persistence/sessions.go
@@ -3,6 +3,7 @@ package persistence
import (
"github.com/pkg/errors"
"io/ioutil"
+ "time"
"dev.narayana.im/narayana/telegabber/yamldb"
@@ -10,6 +11,16 @@ import (
"gopkg.in/yaml.v2"
)
+var zeroLocation *time.Location
+
+func init() {
+ var err error
+ zeroLocation, err = time.LoadLocation("")
+ if err != nil {
+ log.Fatal("Wrong hardcoded timezone")
+ }
+}
+
// SessionsYamlDB wraps YamlDB with Session
type SessionsYamlDB struct {
yamldb.YamlDB
@@ -108,3 +119,13 @@ func (s *Session) Set(key string, value string) (string, error) {
return "", errors.New("Unknown session property")
}
+
+func (s *Session) TimezoneToLocation() *time.Location {
+ time, err := time.Parse("-07:00", s.Timezone)
+ if err == nil {
+ return time.Location()
+ }
+
+ // default
+ return zeroLocation
+}