From 74a872a30bf023cf37d9d3d30e28c25d84c69ffe Mon Sep 17 00:00:00 2001 From: bodqhrohro Date: Thu, 12 Dec 2019 00:48:35 +0200 Subject: Timezone support --- persistence/sessions.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'persistence') 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 +} -- cgit v1.2.3