Skip to content

workouts JSON: numeric bodyweight + sessionDurationSeconds (#33, #36)#54

Merged
DTTerastar merged 1 commit into
quantcli:mainfrom
vinistoisr:fix/33-36-workouts-json-numeric-types
Jul 21, 2026
Merged

workouts JSON: numeric bodyweight + sessionDurationSeconds (#33, #36)#54
DTTerastar merged 1 commit into
quantcli:mainfrom
vinistoisr:fix/33-36-workouts-json-numeric-types

Conversation

@vinistoisr

Copy link
Copy Markdown
Contributor

Fixes #33 and #36. Both touch the same workouts list/show JSON output, so they're handled together to avoid a self-conflicting diff.

Problems

Fix

Add Post.MarshalJSON (decoding is untouched — the API still sends strings; only output is normalized):

  • bodyweight → JSON number, or null when absent/unparseable (matches workouts stats).
  • keep the human sessionDuration string and add a numeric sessionDurationSeconds beside it.

Example:

{
  "startedAt": "2026-06-11T03:14:12.665Z",
  "sessionDuration": "01 hours 06 minutes 01 seconds",
  "bodyweight": 175,
  "sessionDurationSeconds": 3961,
  ...
}

Design notes

  • I chose null (not 0) for a missing bodyweight so it isn't mistaken for a real measurement; happy to switch to 0 if you'd prefer strict number-always.
  • sessionDurationSeconds is additive — the existing sessionDuration string is preserved, so nothing breaks for current consumers. The duration parser returns null on any shape it doesn't recognize rather than guessing.

Tests

TestPostMarshalJSON_NumericFields, TestPostMarshalJSON_EmptyBodyweightIsNull, and a table-driven TestParseDurationSeconds (including empty/non-numeric/unknown-unit/odd-field cases). go test ./... and go vet ./... pass.

🤖 Generated with Claude Code

…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 DTTerastar left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@DTTerastar
DTTerastar merged commit 880a673 into quantcli:main Jul 21, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

JSON 'bodyweight' field inconsistent type: string in workouts list, number in workouts stats

3 participants