Open-source gym & body-weight tracker, now in the App Store (iPhone + Apple Watch) and as an Android APK. Plan routines, log workouts, see which muscles are trained, import from Strong/Hevy/FitNotes. Self-host it or use it on the phone alone.
JavaScript apple-watchbodyweightdockerfitnessfitness-trackergymhealthiosmcpnodejspasskeysprogressive-web-applicationspwareactself-hostedself-hostingvitewebauthnweightliftingworkout-tracker
Sync: a weigh-in corrected on a phone whose clock runs behind keeps the correction
Duarte Santos78c5fd8290c9
diff --git a/frontend/src/lib/sync-merge.js b/frontend/src/lib/sync-merge.jsindex fa2ebf6e2..0d98565b7 100644--- a/frontend/src/lib/sync-merge.js+++ b/frontend/src/lib/sync-merge.js@@ -772,6 +772,7 @@ export function highestStamp(S) {}}for (const f of ['balanceOverrides', 'loadKind', 'plates']) if (isMap(S[f])) for (const v of Object.values(S[f])) see(stampOf(v))+ for (const e of list(S.bodyweight)) if (e && typeof e === 'object') see(e.t)return m}@@ -797,6 +798,15 @@ export function stampChange(prev, next, wall = Date.now()) {if (!n) continuefor (const [k, v] of Object.entries(n)) if (isMap(v) && v._ts != null && stampOf(v) !== stampOf(p[k])) v._ts = now}+ // A weigh-in the change logged or corrected (its `t` moved): the newer entry of a day wins the+ // merge (mergeBodyweight), so it takes the change's time like any other stamp. One whose weight+ // only a unit switch converted keeps its own.+ const bwBefore = new Map(list(prev?.bodyweight).filter(e => e && e.d != null).map(e => [e.d, e]))+ for (const e of list(next.bodyweight)) {+ if (!e || typeof e !== 'object' || e.d == null || e.t == null) continue+ const old = bwBefore.get(e.d)+ if (!old || old.t !== e.t) e.t = Math.max(Number(e.t) || 0, now)+ }stampRoutines(prev?.routines, next.routines, now)stampCustomEx(prev?.customEx, next.customEx, now)stampEntries(prev?.equipProfiles, next.equipProfiles, now)diff --git a/frontend/src/store/useStore.clock.test.jsx b/frontend/src/store/useStore.clock.test.jsxindex b74ce7e95..e37182827 100644--- a/frontend/src/store/useStore.clock.test.jsx+++ b/frontend/src/store/useStore.clock.test.jsx@@ -34,4 +34,25 @@ describe('update stamps after what the copy has seen', () => {expect(n.deleted.workouts.w2).toBeGreaterThan(AHEAD)expect(n._ts).toBeGreaterThan(AHEAD)})+ // QA retest 2026-10-06: a weigh-in corrected on the phone that runs behind kept its raw clock+ // time and lost to the entry it had just corrected on the next merge.+ it('a weigh-in logged or corrected comes after the newest stamp too, and wins the merge', async () => {+ const { mergeStates } = await import('../lib/sync-merge.js')+ const S = { ...clone(DEF), _ts: AHEAD, bodyweight: [{ d: '2026-10-06', w: 80, t: AHEAD }] }+ useStore.setState({ S })+ useStore.getState().update(s => { s.bodyweight[0].w = 78.4; s.bodyweight[0].t = Date.now() })+ useStore.getState().update(s => { s.bodyweight.push({ d: '2026-10-07', w: 78.1, t: Date.now() }) })+ const n = useStore.getState().S+ expect(n.bodyweight[0].t).toBeGreaterThan(AHEAD)+ expect(n.bodyweight[1].t).toBeGreaterThan(AHEAD)+ const other = { ...clone(S), restSec: 120, edited: { restSec: AHEAD + 5 }, _ts: AHEAD + 5 } // the laptop changed something else+ for (const m of [mergeStates(other, n), mergeStates(n, other)]) expect(m.bodyweight.map(e => e.w)).toEqual([78.4, 78.1])+ })++ it('a unit switch does not re-stamp weigh-ins it only converted', () => {+ const S = { ...clone(DEF), _ts: 100, bodyweight: [{ d: '2026-10-06', w: 80, t: 50 }] }+ useStore.setState({ S })+ useStore.getState().update(s => { s.bodyweight[0].w = 176.4 })+ expect(useStore.getState().S.bodyweight[0].t).toBe(50)+ })})