-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathTimezones.go
44 lines (34 loc) · 924 Bytes
/
Timezones.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
40
41
42
43
44
package connect
// Timezones is the list of known time zones in Garmin Connect.
type Timezones []Timezone
// Timezones will retrieve the list of known timezones in Garmin Connect.
func (c *Client) Timezones() (Timezones, error) {
URL := "https://connect.garmin.com/modern/proxy/system-service/timezoneUnits"
if !c.authenticated() {
return nil, ErrNotAuthenticated
}
timezones := make(Timezones, 0, 100)
err := c.getJSON(URL, &timezones)
if err != nil {
return nil, err
}
return timezones, nil
}
// FindID will search for the timezone with id.
func (ts Timezones) FindID(id int) (Timezone, bool) {
for _, t := range ts {
if t.ID == id {
return t, true
}
}
return Timezone{}, false
}
// FindKey will search for the timezone with key key.
func (ts Timezones) FindKey(key string) (Timezone, bool) {
for _, t := range ts {
if t.Key == key {
return t, true
}
}
return Timezone{}, false
}