Use time.LoadLocation instead
Anirudh Oppiliappan x@icyphox.sh
Sun, 21 Nov 2021 17:02:52 +0530
1 files changed,
3 insertions(+),
18 deletions(-)
jump to
M
plugins/time/time.go
→
plugins/time/time.go
@@ -1,10 +1,7 @@
package time import ( - "encoding/json" "fmt" - "net/http" - "path" "time" "github.com/zsefvlol/timezonemapper"@@ -16,21 +13,9 @@ return tz
} func GetTime(lonlat [2]float64, label string) (string, error) { - url := path.Join( - "worldtimeapi.org/api/timezone/", - getTimezone(lonlat), - ) - - m := make(map[string]string) - r, err := http.Get("https://" + url) - if err != nil { - return "", err - } - - json.NewDecoder(r.Body).Decode(&m) - timestamp := m["datetime"] - t, _ := time.Parse(time.RFC3339Nano, timestamp) - pretty := t.Format("2006-02-01 03:04 PM") + loc, _ := time.LoadLocation(getTimezone(lonlat)) + now := time.Now().In(loc) + pretty := now.Format("2006-02-01 03:04 PM") out := fmt.Sprintf("\x02%s\x02: %s", label, pretty) return out, nil }