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.

Rotation: Start the loop over mid-workout still counts that workout

Duarte Santosf8b7b439cb28
diff --git a/frontend/src/lib/rotation.js b/frontend/src/lib/rotation.js
index 6a7b11326..cce490f29 100644
--- a/frontend/src/lib/rotation.js
+++ b/frontend/src/lib/rotation.js
@@ -166,7 +166,13 @@ export function startNewPass(s, today = todayISO(), now = Date.now()) {
if (!ids.length) return
const q = queueOf(s)
if (q) sweepPins(s, q.ids, today)
- s.queue = { ...newPass(ids, s.rotation.label || '', s.rotation.id, today, q ? sinceAfter(s, q, now) : now), strict: true }
+ // A live workout on one of the loop's routines, already running when the loop is started over,
+ // belongs to the new pass: otherwise `strict` + since=now means it never counts once finished.
+ // Still never earlier than the old pass's own workouts (sinceAfter's floor).
+ const a = s.active
+ const running = a && !a.backfill && Number.isFinite(a.start) && a.start <= now && routineIdsOf(a).some(id => ids.includes(id))
+ const since = running ? (q ? sinceAfter(s, q, a.start) : a.start) : (q ? sinceAfter(s, q, now) : now)
+ s.queue = { ...newPass(ids, s.rotation.label || '', s.rotation.id, today, since), strict: true }
}
/** Is `ids` some circular ordering of `seq`? (Both already normalized, so ids are unique.) */
diff --git a/frontend/src/lib/rotation.test.js b/frontend/src/lib/rotation.test.js
index 8a596fe4e..fa46c9a1c 100644
--- a/frontend/src/lib/rotation.test.js
+++ b/frontend/src/lib/rotation.test.js
@@ -148,6 +148,20 @@ describe('editing the sequence', () => {
expect(effectiveRoutineIds(fresh, TODAY, TODAY)).toEqual(['b'])
})
+ it('Start the loop over during a running workout on a loop routine: that workout counts once finished', () => {
+ const s = S({ rotation: { id: 'r1', sequence: ['a', 'b', 'c'], label: 'My split' }, queue: pass(['a', 'b', 'c'], { rotationId: 'r1' }) })
+ s.active = { id: 'live', d: TODAY, start: NOW - 600_000, routineIds: ['a'], name: 'A', entries: [] }
+ startNewPass(s, TODAY, NOW)
+ expect(s.queue.since).toBe(NOW - 600_000)
+ s.workouts.push({ ...s.active, end: NOW + 60_000 }); s.active = null
+ expect(queueView(s, TODAY).items.map(i => i.state)).toEqual(['done', 'next', 'later'])
+ // a past-workout backfill is not a running session: the strict start stays now
+ const b = S({ rotation: { id: 'r1', sequence: ['a', 'b'], label: 'My split' }, queue: pass(['a', 'b'], { rotationId: 'r1' }) })
+ b.active = { id: 'bf', d: '2026-09-11', start: NOW - 86400000, routineIds: ['a'], backfill: { durationMin: 60 } }
+ startNewPass(b, TODAY, NOW)
+ expect(b.queue.since).toBe(NOW)
+ })
+
it('an edit keeps a new pass strict', () => {
const s = S({ rotation: { id: 'r1', sequence: ['a', 'b'], label: 'My split' }, queue: pass(['a', 'b'], { rotationId: 'r1' }), workouts: [w('a', TODAY)] })
startNewPass(s, TODAY, NOW)