Skip to content

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.

Finish: a cardio row or hold ticked when it started no longer cuts the workout's duration; the session reaches to its tick plus its length

Duarte Santos4d9b78b81d50
diff --git a/frontend/src/lib/finish-workout.js b/frontend/src/lib/finish-workout.js
index 44cd5e6e6..5700f7116 100644
--- a/frontend/src/lib/finish-workout.js
+++ b/frontend/src/lib/finish-workout.js
@@ -53,12 +53,16 @@ export function sessionEnd(active, now = Date.now(), gap = FORGOTTEN_GAP_MS) {
.map(s => ({ at: s.at, len: rowLengthMs(s) }))
.sort((a, b) => a.at - b.at)
if (!ticks.length) return now
- let end = ticks[0].at
+ // A row may have been ticked when it was done or when it was started (a treadmill row ticked,
+ // then run for 30 minutes before Finish, QA 10-06), so the session reaches to the later of the
+ // two: its tick plus its own length. That reach, not the bare tick, is what the next tick and
+ // the Finish tap are measured against, and where a forgotten session ends.
+ let reach = ticks[0].at + ticks[0].len
for (const { at, len } of ticks.slice(1)) {
- if (at - len - end > gap) break
- end = at
+ if (at - len - reach > gap) break
+ reach = Math.max(reach, at + len)
}
- return now - end > gap ? end : now
+ return now - reach > gap ? reach : now
}
export function buildCompletedWorkout(active, { end = Date.now(), prs = [], snapshotFor } = {}) {
diff --git a/frontend/src/lib/finish-workout.test.js b/frontend/src/lib/finish-workout.test.js
index eacc6f5d9..375f3d9c5 100644
--- a/frontend/src/lib/finish-workout.test.js
+++ b/frontend/src/lib/finish-workout.test.js
@@ -308,6 +308,20 @@ describe('sessionEnd: a workout finished long after its last set', () => {
expect(sessionEnd(hold, T0 + 31 * MIN)).toBe(T0 + 31 * MIN)
})
+ it('does not cut a cardio row ticked when it started and finished more than the gap later', () => {
+ // Bench 0 and 20, a 30-minute run ticked at 25 when it began, Finish at 56 after it.
+ const active = { entries: [
+ { id: 'x', sets: [0, 20].map(m => ({ done: true, w: 50, r: 8, at: T0 + m * MIN })) },
+ { id: 'run', sets: [{ done: true, min: 30, speed: 10, at: T0 + 25 * MIN }] },
+ ] }
+ expect(sessionEnd(active, T0 + 56 * MIN)).toBe(T0 + 56 * MIN)
+ // The same session left open overnight ends where the run could have, not at its tick.
+ expect(sessionEnd(active, T0 + 24 * 60 * MIN)).toBe(T0 + 55 * MIN)
+ // A hold started and ticked before a 25-minute stretch is the same.
+ const hold = { entries: [{ id: 'plank', sets: [{ done: true, sec: 300, at: T0 }] }] }
+ expect(sessionEnd(hold, T0 + 25 * MIN)).toBe(T0 + 25 * MIN)
+ })
+
it('counts a per-side set once one side is done', () => {
const active = { entries: [{ id: 'x', sets: [{
w: 20, r: 8, done: false, at: T0,