busdepartures/utils.go

29 lines
477 B
Go

package main
import (
"strconv"
"time"
)
// parseUnixTimestamp parses a string containing a UNIX timestamp to a time.Time.
func parseUnixTimestamp(timestamp string) (time.Time, error) {
var t = time.Time{}
loc, err := time.LoadLocation("Europe/Amsterdam")
if err != nil {
return t, err
}
i, err := strconv.ParseInt(timestamp, 10, 64)
if err != nil {
return t, err
}
t, err = time.Unix(i, 0), nil
if err != nil {
return t, err
}
return t.In(loc), nil
}