all repos — paprika @ e0be121a9aae75ae30392da6e48156116d781ca4

go rewrite of taigabot

Use time.LoadLocation instead
Anirudh Oppiliappan x@icyphox.sh
Sun, 21 Nov 2021 17:02:52 +0530
commit

e0be121a9aae75ae30392da6e48156116d781ca4

parent

8f52ee8c2bb889f5d5fdf2171d169e28b6f68081

1 files changed, 3 insertions(+), 18 deletions(-)

jump to
M plugins/time/time.goplugins/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 }