diff options
author | Kevin Chabowski <kevin@kch42.de> | 2013-08-29 22:37:05 +0200 |
---|---|---|
committer | Kevin Chabowski <kevin@kch42.de> | 2013-08-29 22:37:05 +0200 |
commit | 61f137d2cc8ae0199c99493701023b4d862a34ad (patch) | |
tree | 5a77a1beb16cfd508486fabf6419f37fc348fc34 /timelocs.go | |
parent | 8ecfe7a2fc61caf890e319e7a2f298b71dc90826 (diff) | |
download | mailremind-61f137d2cc8ae0199c99493701023b4d862a34ad.tar.gz mailremind-61f137d2cc8ae0199c99493701023b4d862a34ad.tar.bz2 mailremind-61f137d2cc8ae0199c99493701023b4d862a34ad.zip |
Registering accounts is working
Diffstat (limited to 'timelocs.go')
-rw-r--r-- | timelocs.go | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/timelocs.go b/timelocs.go new file mode 100644 index 0000000..bb04070 --- /dev/null +++ b/timelocs.go @@ -0,0 +1,42 @@ +package main + +import ( + "archive/zip" + "log" + "path" + "runtime" + "sort" + "sync" +) + +var timeLocs []string +var tlOnce sync.Once + +func listTimeLocations() ([]string, error) { + zoneinfoZip := path.Join(runtime.GOROOT(), "lib", "time", "zoneinfo.zip") + z, err := zip.OpenReader(zoneinfoZip) + if err != nil { + return nil, err + } + defer z.Close() + + locs := []string{} + for _, f := range z.File { + if f.Name[len(f.Name)-1] == '/' { + continue + } + locs = append(locs, f.Name) + } + + sort.Strings(locs) + return locs, nil +} + +func loadTimeLocs() { + tlOnce.Do(func() { + var err error + if timeLocs, err = listTimeLocations(); err != nil { + log.Fatalf("Could not load time locations: %s", err) + } + }) +} |