workouts JSON: numeric bodyweight + sessionDurationSeconds (#33, #36)#54
Merged
DTTerastar merged 1 commit intoJul 21, 2026
Merged
Conversation
…uantcli#33, quantcli#36) The workouts JSON marshalled two fields in shapes that are awkward for downstream consumers: - bodyweight came through as a quoted string ("175") while `workouts stats` emits it as a number, so the same field had two types depending on the subcommand (quantcli#33). - sessionDuration is a human phrase ("01 hours 06 minutes 01 seconds"), so it cannot be summed or averaged without parsing prose (quantcli#36). Add a Post.MarshalJSON that: - emits bodyweight as a JSON number (null when absent/unparseable), matching `workouts stats`; - keeps the human sessionDuration string and adds a numeric sessionDurationSeconds beside it. Decoding is unchanged (the API still sends strings; only output is normalized). Adds tests for the marshalled types and the duration parser, including null/empty and malformed-input cases. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
DTTerastar
approved these changes
Jul 21, 2026
DTTerastar
left a comment
Collaborator
There was a problem hiding this comment.
Verified locally: build, go vet, go test ./... all pass. Checked the marshaled output directly — single bodyweight key emitted as a number, no duplicate from the embedded alias, and sessionDurationSeconds lands alongside the preserved human string. Decoding path is untouched and nothing round-trips our own output back into Post, so no break for existing consumers. Agreed on null over 0 for a missing bodyweight — 0 would read as a real measurement.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #33 and #36. Both touch the same
workouts list/showJSON output, so they're handled together to avoid a self-conflicting diff.Problems
bodyweightis emitted as a quoted string ("175") inworkouts list/show, but as a number inworkouts stats. Same field, two types depending on subcommand.sessionDurationis a human phrase ("01 hours 06 minutes 01 seconds") sitting next to numericcaloriesBurned/prCount; you can't do arithmetic on it without parsing prose.Fix
Add
Post.MarshalJSON(decoding is untouched — the API still sends strings; only output is normalized):bodyweight→ JSON number, ornullwhen absent/unparseable (matchesworkouts stats).sessionDurationstring and add a numericsessionDurationSecondsbeside it.Example:
{ "startedAt": "2026-06-11T03:14:12.665Z", "sessionDuration": "01 hours 06 minutes 01 seconds", "bodyweight": 175, "sessionDurationSeconds": 3961, ... }Design notes
null(not0) for a missing bodyweight so it isn't mistaken for a real measurement; happy to switch to0if you'd prefer strict number-always.sessionDurationSecondsis additive — the existingsessionDurationstring is preserved, so nothing breaks for current consumers. The duration parser returnsnullon any shape it doesn't recognize rather than guessing.Tests
TestPostMarshalJSON_NumericFields,TestPostMarshalJSON_EmptyBodyweightIsNull, and a table-drivenTestParseDurationSeconds(including empty/non-numeric/unknown-unit/odd-field cases).go test ./...andgo vet ./...pass.🤖 Generated with Claude Code