-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.go
39 lines (33 loc) · 945 Bytes
/
util.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package njtapi
import (
"log"
"strconv"
"strings"
"time"
)
// LatLng models the latitude and longitude of an object.
type LatLng struct {
Lat float64 // Latitude
Lng float64 // Longitude
}
var tz *time.Location
func init() {
var err error
// Hardcode the timezone to New York.
// While New Jersey and New York are separate states,
// New Jersey would never dream of using a different timezone
// than New York without triggering some sort of proxy-war.
tz, err = time.LoadLocation("America/New_York")
if err != nil {
log.Fatalf("unable to load timezone: %v", err)
}
}
// Convert a timestamp returned from the API to a time.Time.
func parseTime(ts string) (time.Time, error) {
return time.ParseInLocation("02-Jan-2006 03:04:05 PM", ts, tz)
}
// Convert a lat or long string to an actual number.
func parseDegrees(degrees string) (float64, error) {
trim := strings.TrimSpace(degrees)
return strconv.ParseFloat(trim, 64)
}