Skip to content

Commit

Permalink
Merge pull request #876 from wader/fit-date-time
Browse files Browse the repository at this point in the history
fit: Formatted date/time description for timestamp fields
  • Loading branch information
wader authored Feb 11, 2024
2 parents 2a90479 + 76307e4 commit 7ca701d
Show file tree
Hide file tree
Showing 7 changed files with 6,147 additions and 6,131 deletions.
1 change: 1 addition & 0 deletions doc/formats.md
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,7 @@ $ fq '[.data_records[] | select(.record_header.message_type == "data").data_mess

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

## flac_frame

Expand Down
3 changes: 3 additions & 0 deletions format/fit/fit.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package fit

// https://developer.garmin.com/fit/protocol/
// https://developer.garmin.com/fit/cookbook/decoding-activity-files/

import (
"embed"
"fmt"
Expand Down
1 change: 1 addition & 0 deletions format/fit/fit.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ $ fq '[.data_records[] | select(.record_header.message_type == "data").data_mess

### References
- https://developer.garmin.com/fit/protocol/
- https://developer.garmin.com/fit/cookbook/decoding-activity-files/
13 changes: 12 additions & 1 deletion format/fit/mappers/values.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ package mappers

import (
"math"
"time"

"github.com/wader/fq/pkg/scalar"
)

var epochDate = time.Date(1989, time.December, 31, 0, 0, 0, 0, time.UTC)

// Used for conversion from semicircles to decimal longitude latitude
var scConst = 180 / math.Pow(2, 31)

Expand Down Expand Up @@ -51,12 +54,20 @@ func GetUintFormatter(fDef LocalFieldDef) scalar.UintFn {
}
}

s.Description = fDef.Unit
if t, ok := TypeDefMap[fDef.Format]; ok {
if u, innerOk := t[s.Actual]; innerOk {
s.Sym = u.Name
}
}

switch fDef.Format {
case "date_time",
"local_date_time":
s.Description = epochDate.Add(time.Duration(s.Actual) * time.Second).Format(time.RFC3339)
default:
s.Description = fDef.Unit
}

return s, nil
})
}
Expand Down
4,316 changes: 2,158 additions & 2,158 deletions format/fit/testdata/activity.fqtest

Large diffs are not rendered by default.

7,222 changes: 3,611 additions & 3,611 deletions format/fit/testdata/activity_dev.fqtest

Large diffs are not rendered by default.

722 changes: 361 additions & 361 deletions format/fit/testdata/activity_invalid_strings.fqtest

Large diffs are not rendered by default.

0 comments on commit 7ca701d

Please sign in to comment.