forked from adrianmo/go-nmea
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathzda.go
52 lines (48 loc) · 1.17 KB
/
zda.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
45
46
47
48
49
50
51
52
package nmea
const (
// TypeZDA type for ZDA sentences
TypeZDA = "ZDA"
)
// ZDA represents date & time data.
// http://aprs.gids.nl/nmea/#zda
type ZDA struct {
BaseSentence
Time Time
Day int64
Month int64
Year int64
OffsetHours int64 // Local time zone offset from GMT, hours
OffsetMinutes int64 // Local time zone offset from GMT, minutes
}
func (s ZDA) ToMap() (map[string]interface{}, error) {
m := map[string]interface{}{
"time": s.Time.String(),
"day": s.Day,
"month": s.Month,
"year": s.Year,
"offset_hours": s.OffsetHours,
"offset_minutes": s.OffsetMinutes,
}
bm, err := s.BaseSentence.toMap()
if err != nil {
return m, err
}
for k, v := range bm {
m[k] = v
}
return m, nil
}
// newZDA constructor
func newZDA(s BaseSentence) (ZDA, error) {
p := NewParser(s)
p.AssertType(TypeZDA)
return ZDA{
BaseSentence: s,
Time: p.Time(0, "time"),
Day: p.Int64(1, "day"),
Month: p.Int64(2, "month"),
Year: p.Int64(3, "year"),
OffsetHours: p.Int64(4, "offset (hours)"),
OffsetMinutes: p.Int64(5, "offset (minutes)"),
}, p.Err()
}