diff options
Diffstat (limited to 'persistence')
-rw-r--r-- | persistence/sessions.go | 21 |
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 +} |