Skip to content

Commit 7ca701d

Browse files
authored
Merge pull request #876 from wader/fit-date-time
fit: Formatted date/time description for timestamp fields
2 parents 2a90479 + 76307e4 commit 7ca701d

File tree

7 files changed

+6147
-6131
lines changed

7 files changed

+6147
-6131
lines changed

doc/formats.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,7 @@ $ fq '[.data_records[] | select(.record_header.message_type == "data").data_mess
591591

592592
### References
593593
- https://developer.garmin.com/fit/protocol/
594+
- https://developer.garmin.com/fit/cookbook/decoding-activity-files/
594595

595596
## flac_frame
596597

format/fit/fit.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package fit
22

3+
// https://developer.garmin.com/fit/protocol/
4+
// https://developer.garmin.com/fit/cookbook/decoding-activity-files/
5+
36
import (
47
"embed"
58
"fmt"

format/fit/fit.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ $ fq '[.data_records[] | select(.record_header.message_type == "data").data_mess
1616

1717
### References
1818
- https://developer.garmin.com/fit/protocol/
19+
- https://developer.garmin.com/fit/cookbook/decoding-activity-files/

format/fit/mappers/values.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@ package mappers
22

33
import (
44
"math"
5+
"time"
56

67
"github.com/wader/fq/pkg/scalar"
78
)
89

10+
var epochDate = time.Date(1989, time.December, 31, 0, 0, 0, 0, time.UTC)
11+
912
// Used for conversion from semicircles to decimal longitude latitude
1013
var scConst = 180 / math.Pow(2, 31)
1114

@@ -51,12 +54,20 @@ func GetUintFormatter(fDef LocalFieldDef) scalar.UintFn {
5154
}
5255
}
5356

54-
s.Description = fDef.Unit
5557
if t, ok := TypeDefMap[fDef.Format]; ok {
5658
if u, innerOk := t[s.Actual]; innerOk {
5759
s.Sym = u.Name
5860
}
5961
}
62+
63+
switch fDef.Format {
64+
case "date_time",
65+
"local_date_time":
66+
s.Description = epochDate.Add(time.Duration(s.Actual) * time.Second).Format(time.RFC3339)
67+
default:
68+
s.Description = fDef.Unit
69+
}
70+
6071
return s, nil
6172
})
6273
}

format/fit/testdata/activity.fqtest

Lines changed: 2158 additions & 2158 deletions
Large diffs are not rendered by default.

format/fit/testdata/activity_dev.fqtest

Lines changed: 3611 additions & 3611 deletions
Large diffs are not rendered by default.

format/fit/testdata/activity_invalid_strings.fqtest

Lines changed: 361 additions & 361 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)