From 270594eb1f298e8c024f1fc49cb5fc8de09e52a5 Mon Sep 17 00:00:00 2001 From: RandomChars <random@chars.jp> Date: Thu, 13 Jan 2022 13:55:33 +0900 Subject: [PATCH] timezone in configuration --- config.go | 18 ++++++++++++++---- tournament.go | 2 +- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/config.go b/config.go index 821cb23..09e0b3e 100644 --- a/config.go +++ b/config.go @@ -6,11 +6,13 @@ import ( "log" "os" "strconv" + "time" ) var ( administrators map[string]bool guildID string + timezone *time.Location ) type conf struct { @@ -30,8 +32,9 @@ type serverConf struct { } type systemConf struct { - Verbose bool `toml:"verbose"` - Store string `toml:"store"` + Verbose bool `toml:"verbose"` + Store string `toml:"store"` + Timezone string `toml:"timezone"` } type discordConf struct { @@ -77,6 +80,12 @@ func confLoad() { } } + if location, err := time.LoadLocation(config.System.Timezone); err != nil { + log.Fatalf("error parsing location: %s", err) + } else { + timezone = location + } + if len(config.Discord.Administrators) != 0 && config.Discord.Administrators[0] != -1 { administrators = make(map[string]bool) @@ -92,8 +101,9 @@ func confLoad() { var defConf = conf{ System: systemConf{ - Verbose: false, - Store: "db", + Verbose: false, + Store: "db", + Timezone: "UTC", }, Server: serverConf{ Host: "127.0.0.1", diff --git a/tournament.go b/tournament.go index c3bb0c4..1350a1c 100644 --- a/tournament.go +++ b/tournament.go @@ -69,7 +69,7 @@ func parseDate(date string) time.Time { d[i] = n } } - return time.Date(d[0], time.Month(d[1]), d[2], 0, 0, 0, 0, time.Local) + return time.Date(d[0], time.Month(d[1]), d[2], 0, 0, 0, 0, timezone) } var tournamentLock = sync.RWMutex{} -- GitLab