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
History: a saved workout's duration can be corrected from its detail sheet, for the session nobody ended until they got home
Duarte Santosc05a1c6896b3
diff --git a/frontend/src/lib/pt-br-locale.test.js b/frontend/src/lib/pt-br-locale.test.jsindex 9bffc496a..8d6bc61de 100644--- a/frontend/src/lib/pt-br-locale.test.js+++ b/frontend/src/lib/pt-br-locale.test.js@@ -41,7 +41,7 @@ describe('Brazilian Portuguese locale', () => {// has to be taught is a number nobody reads. What the numbers stood for is asserted above.// If the hash fails, review the changed keys and wording before accepting a new one. From// frontend/: node scripts/pt-br-inheritance-fingerprint.mjs --list- expect(fingerprint, 'pt-PT inheritance changed; review the inherited pt-BR wording').toBe('bdf1fb1dc4d882d1cfd51328ba1b79bfc1b8e598567ff8662cb2c10d3e3701a6')+ expect(fingerprint, 'pt-PT inheritance changed; review the inherited pt-BR wording').toBe('234dd9b792d0e74555054650c8cd29b0318590fd89b8aedf3812e79985253f3c')})test('does not leak European Portuguese UI terms', () => {diff --git a/frontend/src/lib/workout-date.js b/frontend/src/lib/workout-date.jsindex ce06dc68e..bd725c046 100644--- a/frontend/src/lib/workout-date.js+++ b/frontend/src/lib/workout-date.js@@ -96,3 +96,22 @@ export function moveWorkout(workouts, ref, iso, time, now = Date.now()) {const filed = insertChronological(list.filter(w => w !== current), moved)return rebuildPrHistory(filed, (current.entries || []).map(e => e.id), moved)}++// How long a saved session ran, in whole minutes — what the duration row starts from. At least a+// minute, the way a logged past session is at least one (backfillEnd).+export const durationMinOf = w => Math.max(1, Math.round(Math.max(0, (w?.end ?? w?.start ?? 0) - (w?.start ?? 0)) / 60000))++// The history after a session's length is corrected — the workout nobody ended until they got+// home, and that now reads three hours. The start stays where it was and the end follows it;+// nothing else changes, since neither the order of history nor any badge depends on the length.+// Stamped like every edit of a saved workout (stampWorkout), for a conflict to keep it. Returns+// the new array, or `null` when the workout is not there or already runs that long.+export function setWorkoutDuration(workouts, ref, minutes, now = Date.now()) {+ const list = Array.isArray(workouts) ? workouts : []+ const current = list.find(w => sameWorkout(w, ref))+ const min = Math.max(1, Math.round(Number(minutes) || 0))+ if (!current || !Number.isFinite(current.start) || (current.end != null && min === durationMinOf(current))) return null+ // A record from before ids is keyed by its day and start, and neither moves here.+ const edited = stampWorkout({ ...current, end: current.start + min * 60000 }, now)+ return list.map(w => (w === current ? edited : w))+}diff --git a/frontend/src/lib/workout-date.test.js b/frontend/src/lib/workout-date.test.jsindex db90b25e4..979ba6141 100644--- a/frontend/src/lib/workout-date.test.js+++ b/frontend/src/lib/workout-date.test.js@@ -1,5 +1,5 @@import { describe, expect, it } from 'vitest'-import { legacySyncKey, startTimeOf, sameWorkout, retimeWorkout, rebuildPrHistory, moveWorkout } from './workout-date.js'+import { legacySyncKey, startTimeOf, sameWorkout, retimeWorkout, rebuildPrHistory, moveWorkout, durationMinOf, setWorkoutDuration } from './workout-date.js'import { backfillStart } from './backfill.js'const set = w => ({ w, r: 5, done: true })@@ -232,3 +232,36 @@ describe('moveWorkout', () => {expect(out[0].d).toBe('2026-01-03')})})++// The workout nobody ended until they got home: its length is corrected, nothing else moves.+describe('setWorkoutDuration', () => {+ it('reads a saved length in whole minutes, at least one', () => {+ expect(durationMinOf(w('a', '2026-01-01', '18:00', 47))).toBe(47)+ expect(durationMinOf({ start: 1000, end: 1000 })).toBe(1)+ expect(durationMinOf({ start: 1000 })).toBe(1)+ })+ it('moves the end, keeps the start, the day, the order and the badges, and stamps the edit', () => {+ const list = [w('a', '2026-01-01', '18:00', 300, [entry('bench', 100)], ['bench']), w('b', '2026-01-05', '18:00', 60)]+ const out = setWorkoutDuration(list, list[0], 75, 4242)+ expect(out.map(x => x.id)).toEqual(['a', 'b'])+ expect(out[0]).toEqual({ ...list[0], end: list[0].start + 75 * 60000, _ts: 4242 })+ expect(out[1]).toBe(list[1])+ expect(list[0].end - list[0].start).toBe(300 * 60000) // the input is left alone+ })+ it('never makes a session shorter than a minute', () => {+ const list = [w('a', '2026-01-01', '18:00', 30)]+ expect(setWorkoutDuration(list, list[0], 0)[0].end - list[0].start).toBe(60000)+ })+ it('returns null for no change, and for a workout that is gone', () => {+ const list = [w('a', '2026-01-01', '18:00', 30)]+ expect(setWorkoutDuration(list, list[0], 30)).toBeNull()+ expect(setWorkoutDuration(list, { id: 'gone' }, 45)).toBeNull()+ })+ it('a record from before ids keeps the key the sync knows it by', () => {+ const legacy = { d: '2026-01-01', start: 5000, end: 5000 + 600000, entries: [], prs: [] }+ const out = setWorkoutDuration([legacy], legacy, 20)+ expect(out[0]).not.toHaveProperty('id')+ expect(legacySyncKey(out[0])).toBe(legacySyncKey(legacy))+ expect(out[0].end).toBe(5000 + 20 * 60000)+ })+})diff --git a/frontend/src/locales/de.js b/frontend/src/locales/de.jsindex 3755e5b38..41b806746 100644--- a/frontend/src/locales/de.js+++ b/frontend/src/locales/de.js@@ -1155,6 +1155,9 @@ export default {'Pick a day up to today': 'Wähle einen Tag bis heute','Change date & time': 'Datum & Uhrzeit ändern','Workout moved': 'Training verschoben',+ 'Change duration': 'Dauer ändern',+ 'Duration changed': 'Dauer geändert',+ 'Forgot to finish on time? Set how long the session really took. It keeps its start time and its sets.': 'Vergessen, rechtzeitig zu beenden? Stell ein, wie lange die Einheit wirklich gedauert hat. Startzeit und Sätze bleiben, wie sie sind.','The session keeps its length. Personal records are worked out again from the new order.': 'Die Einheit behält ihre Dauer. Persönliche Rekorde werden nach der neuen Reihenfolge neu berechnet.','There is already a workout on that day.': 'An diesem Tag gibt es bereits ein Training.','Replace': 'Ersetzen',diff --git a/frontend/src/locales/es.js b/frontend/src/locales/es.jsindex 1b082a4f1..1a272f02a 100644--- a/frontend/src/locales/es.js+++ b/frontend/src/locales/es.js@@ -1135,6 +1135,9 @@ export default {'Pick a day up to today': 'Elige un día hasta hoy','Change date & time': 'Cambiar fecha y hora','Workout moved': 'Entrenamiento movido',+ 'Change duration': 'Cambiar duración',+ 'Duration changed': 'Duración cambiada',+ 'Forgot to finish on time? Set how long the session really took. It keeps its start time and its sets.': '¿Olvidaste terminar a tiempo? Indica cuánto duró de verdad la sesión. Conserva su hora de inicio y sus series.','The session keeps its length. Personal records are worked out again from the new order.': 'La sesión mantiene su duración. Los récords personales se recalculan según el nuevo orden.','There is already a workout on that day.': 'Ya hay un entrenamiento ese día.','Replace': 'Reemplazar',diff --git a/frontend/src/locales/fr.js b/frontend/src/locales/fr.jsindex 801889f60..aa3cd6d3f 100644--- a/frontend/src/locales/fr.js+++ b/frontend/src/locales/fr.js@@ -1135,6 +1135,9 @@ export default {'Pick a day up to today': 'Choisis un jour jusqu’à aujourd’hui','Change date & time': 'Modifier la date et l’heure','Workout moved': 'Séance déplacée',+ 'Change duration': 'Modifier la durée',+ 'Duration changed': 'Durée modifiée',+ 'Forgot to finish on time? Set how long the session really took. It keeps its start time and its sets.': 'Oublié de terminer à temps ? Indique combien de temps la séance a vraiment duré. Elle garde son heure de début et ses séries.','The session keeps its length. Personal records are worked out again from the new order.': 'La séance conserve sa durée. Les records personnels sont recalculés selon le nouvel ordre.','There is already a workout on that day.': 'Il y a déjà une séance ce jour-là.','Replace': 'Remplacer',diff --git a/frontend/src/locales/hi.js b/frontend/src/locales/hi.jsindex 2dd675854..3d165917c 100644--- a/frontend/src/locales/hi.js+++ b/frontend/src/locales/hi.js@@ -1135,6 +1135,9 @@ export default {'Pick a day up to today': 'आज तक का कोई दिन चुनें','Change date & time': 'दिनांक और समय बदलें','Workout moved': 'वर्कआउट खिसकाया गया',+ 'Change duration': 'अवधि बदलें',+ 'Duration changed': 'अवधि बदली गई',+ 'Forgot to finish on time? Set how long the session really took. It keeps its start time and its sets.': 'समय पर खत्म करना भूल गए? बताएं कि सेशन असल में कितनी देर चला। शुरू होने का समय और सेट वैसे ही रहेंगे।','The session keeps its length. Personal records are worked out again from the new order.': 'सेशन की अवधि वही रहती है। नए क्रम के अनुसार निजी रिकॉर्ड दोबारा निकाले जाते हैं।','There is already a workout on that day.': 'उस दिन पहले से एक वर्कआउट है।','Replace': 'बदलें',diff --git a/frontend/src/locales/hu.js b/frontend/src/locales/hu.jsindex 536b05ee1..7eb703d37 100644--- a/frontend/src/locales/hu.js+++ b/frontend/src/locales/hu.js@@ -798,6 +798,9 @@ export default {'Pick a day up to today': 'Válassz egy napot a mai napig','Change date & time': 'Dátum és idő módosítása','Workout moved': 'Edzés áthelyezve',+ 'Change duration': 'Időtartam módosítása',+ 'Duration changed': 'Időtartam módosítva',+ 'Forgot to finish on time? Set how long the session really took. It keeps its start time and its sets.': 'Elfelejtetted időben befejezni? Add meg, valójában meddig tartott az edzés. A kezdési idő és a sorozatok megmaradnak.','The session keeps its length. Personal records are worked out again from the new order.': 'Az edzés hossza megmarad. A személyes rekordok az új sorrend szerint újraszámolódnak.','There is already a workout on that day.': 'Azon a napon már van egy edzés.','Replace': 'Csere',diff --git a/frontend/src/locales/it.js b/frontend/src/locales/it.jsindex 72ef43ab1..9536b374c 100644--- a/frontend/src/locales/it.js+++ b/frontend/src/locales/it.js@@ -1135,6 +1135,9 @@ export default {'Pick a day up to today': 'Scegli un giorno fino a oggi','Change date & time': 'Cambia data e ora','Workout moved': 'Allenamento spostato',+ 'Change duration': 'Cambia durata',+ 'Duration changed': 'Durata modificata',+ 'Forgot to finish on time? Set how long the session really took. It keeps its start time and its sets.': 'Hai dimenticato di terminare in tempo? Imposta quanto è durata davvero la sessione. Mantiene l’ora di inizio e le serie.','The session keeps its length. Personal records are worked out again from the new order.': 'La sessione mantiene la sua durata. I record personali vengono ricalcolati secondo il nuovo ordine.','There is already a workout on that day.': 'C’è già un allenamento quel giorno.','Replace': 'Sostituisci',diff --git a/frontend/src/locales/ko.js b/frontend/src/locales/ko.jsindex 31564a971..d0aadd3bd 100644--- a/frontend/src/locales/ko.js+++ b/frontend/src/locales/ko.js@@ -1135,6 +1135,9 @@ export default {'Pick a day up to today': '오늘까지의 날짜를 선택하세요','Change date & time': '날짜 및 시간 변경','Workout moved': '운동을 옮겼습니다',+ 'Change duration': '시간 변경',+ 'Duration changed': '시간을 변경했습니다',+ 'Forgot to finish on time? Set how long the session really took. It keeps its start time and its sets.': '제때 종료하는 걸 잊으셨나요? 세션이 실제로 걸린 시간을 설정하세요. 시작 시간과 세트는 그대로 유지됩니다.','The session keeps its length. Personal records are worked out again from the new order.': '세션 길이는 그대로 유지됩니다. 개인 기록은 새 순서에 따라 다시 계산됩니다.','There is already a workout on that day.': '그날에 이미 운동이 있습니다.','Replace': '바꾸기',diff --git a/frontend/src/locales/pl.js b/frontend/src/locales/pl.jsindex 77fb4eb8b..01f464aa6 100644--- a/frontend/src/locales/pl.js+++ b/frontend/src/locales/pl.js@@ -1135,6 +1135,9 @@ export default {'Pick a day up to today': 'Wybierz dzień do dzisiaj','Change date & time': 'Zmień datę i godzinę','Workout moved': 'Trening przeniesiony',+ 'Change duration': 'Zmień czas',+ 'Duration changed': 'Czas zmieniony',+ 'Forgot to finish on time? Set how long the session really took. It keeps its start time and its sets.': 'Zapomniałeś zakończyć na czas? Ustaw, ile naprawdę trwała sesja. Godzina rozpoczęcia i serie zostają bez zmian.','The session keeps its length. Personal records are worked out again from the new order.': 'Sesja zachowuje swoją długość. Rekordy osobiste są przeliczane według nowej kolejności.','There is already a workout on that day.': 'Tego dnia jest już trening.','Replace': 'Zastąp',diff --git a/frontend/src/locales/pt-BR.js b/frontend/src/locales/pt-BR.jsindex f62db230c..22af8dfbb 100644--- a/frontend/src/locales/pt-BR.js+++ b/frontend/src/locales/pt-BR.js@@ -617,6 +617,7 @@ export const PT_BR_OVERRIDES = {'Change date & time': 'Alterar data e hora','Workout moved': 'Treino movido','The session keeps its length. Personal records are worked out again from the new order.': 'A sessão mantém a duração. Os recordes pessoais são recalculados pela nova ordem.',+ 'Forgot to finish on time? Set how long the session really took. It keeps its start time and its sets.': 'Esqueceu de terminar na hora? Defina quanto tempo a sessão realmente durou. Ela mantém o horário de início e as séries.','Finish the current workout first.': 'Termine primeiro o treino atual.','Logging a past workout — no rest timers.': 'Registrando um treino passado — sem temporizadores de descanso.',// --- bar weight (plate math) --- ('Peso da barra', 'Barra ({0})', 'Barra {0}' inherit)diff --git a/frontend/src/locales/pt.js b/frontend/src/locales/pt.jsindex 5555c3d15..cbfef679f 100644--- a/frontend/src/locales/pt.js+++ b/frontend/src/locales/pt.js@@ -1135,6 +1135,9 @@ export default {'Pick a day up to today': 'Escolhe um dia até hoje','Change date & time': 'Alterar data e hora','Workout moved': 'Treino movido',+ 'Change duration': 'Alterar duração',+ 'Duration changed': 'Duração alterada',+ 'Forgot to finish on time? Set how long the session really took. It keeps its start time and its sets.': 'Esqueceste-te de terminar a tempo? Indica quanto tempo a sessão durou de facto. Mantém a hora de início e as séries.','The session keeps its length. Personal records are worked out again from the new order.': 'A sessão mantém a sua duração. Os recordes pessoais são recalculados pela nova ordem.','There is already a workout on that day.': 'Já existe um treino nesse dia.','Replace': 'Substituir',diff --git a/frontend/src/locales/ru.js b/frontend/src/locales/ru.jsindex f3ee77ec7..19f388af1 100644--- a/frontend/src/locales/ru.js+++ b/frontend/src/locales/ru.js@@ -1135,6 +1135,9 @@ export default {'Pick a day up to today': 'Выбери день не позже сегодняшнего','Change date & time': 'Изменить дату и время','Workout moved': 'Тренировка перенесена',+ 'Change duration': 'Изменить время',+ 'Duration changed': 'Время изменено',+ 'Forgot to finish on time? Set how long the session really took. It keeps its start time and its sets.': 'Забыли вовремя завершить? Укажите, сколько на самом деле длилась тренировка. Время начала и подходы останутся прежними.','The session keeps its length. Personal records are worked out again from the new order.': 'Длительность тренировки сохраняется. Личные рекорды пересчитываются по новому порядку.','There is already a workout on that day.': 'В этот день уже есть тренировка.','Replace': 'Заменить',diff --git a/frontend/src/locales/th.js b/frontend/src/locales/th.jsindex 9d6e681e4..4facdfd61 100644--- a/frontend/src/locales/th.js+++ b/frontend/src/locales/th.js@@ -806,6 +806,9 @@ export default {'Pick a day up to today': 'เลือกวันได้ไม่เกินวันนี้','Change date & time': 'เปลี่ยนวันที่และเวลา','Workout moved': 'ย้ายการฝึกแล้ว',+ 'Change duration': 'เปลี่ยนระยะเวลา',+ 'Duration changed': 'เปลี่ยนระยะเวลาแล้ว',+ 'Forgot to finish on time? Set how long the session really took. It keeps its start time and its sets.': 'ลืมกดจบตรงเวลาใช่ไหม ตั้งระยะเวลาที่เซสชันใช้จริง เวลาเริ่มและเซ็ตจะยังคงเดิม','The session keeps its length. Personal records are worked out again from the new order.': 'ระยะเวลาของเซสชันยังเท่าเดิม ระบบจะคำนวณสถิติส่วนตัวใหม่ตามลำดับใหม่','There is already a workout on that day.': 'วันนั้นมีการฝึกอยู่แล้ว','Replace': 'แทนที่',diff --git a/frontend/src/locales/tr.js b/frontend/src/locales/tr.jsindex 52d232c62..9e474aa79 100644--- a/frontend/src/locales/tr.js+++ b/frontend/src/locales/tr.js@@ -1135,6 +1135,9 @@ export default {'Pick a day up to today': 'Bugüne kadar bir gün seç','Change date & time': 'Tarih ve saati değiştir','Workout moved': 'Antrenman taşındı',+ 'Change duration': 'Süreyi değiştir',+ 'Duration changed': 'Süre değiştirildi',+ 'Forgot to finish on time? Set how long the session really took. It keeps its start time and its sets.': 'Zamanında bitirmeyi mi unuttun? Antrenmanın gerçekte ne kadar sürdüğünü ayarla. Başlangıç saati ve setler aynı kalır.','The session keeps its length. Personal records are worked out again from the new order.': 'Antrenmanın süresi korunur. Kişisel rekorlar yeni sıralamaya göre yeniden hesaplanır.','There is already a workout on that day.': 'O gün zaten bir antrenman var.','Replace': 'Değiştir',diff --git a/frontend/src/locales/zh.js b/frontend/src/locales/zh.jsindex dd600b984..e0713dd31 100644--- a/frontend/src/locales/zh.js+++ b/frontend/src/locales/zh.js@@ -1135,6 +1135,9 @@ export default {'Pick a day up to today': '请选择今天或之前的日期','Change date & time': '修改日期和时间','Workout moved': '训练已移动',+ 'Change duration': '修改时长',+ 'Duration changed': '时长已修改',+ 'Forgot to finish on time? Set how long the session really took. It keeps its start time and its sets.': '忘了及时结束?设置本次训练的实际时长。开始时间和组数保持不变。','The session keeps its length. Personal records are worked out again from the new order.': '训练时长保持不变。个人记录会按新的顺序重新计算。','There is already a workout on that day.': '那天已经有一次训练了。','Replace': '替换',diff --git a/frontend/src/sheets.jsx b/frontend/src/sheets.jsxindex 40fa9e575..e63dc411c 100644--- a/frontend/src/sheets.jsx+++ b/frontend/src/sheets.jsx@@ -38,7 +38,7 @@ import { isFav, toggleFav, sortFavouritesFirst } from './lib/favourites.js'import { buildSessionEntries, buildPlannedEntry } from './lib/session-start.js'import { buildCombinedEntries, deriveSessionName } from './lib/session-merge.js'import { workoutsOn, backfillStart, backfillEnd, completeBackfill } from './lib/backfill.js'-import { moveWorkout, sameWorkout, startTimeOf } from './lib/workout-date.js'+import { moveWorkout, sameWorkout, startTimeOf, durationMinOf, setWorkoutDuration } from './lib/workout-date.js'import { editCompletedSession } from './lib/session-edit.js'import { stampWorkout } from './lib/sync-merge.js'@@ -1720,6 +1720,32 @@ function WorkoutDateEdit({ w, onDone, close }) {}export const workoutDateSheet = (w, onDone) => ui().openSheet(close => <WorkoutDateEdit w={w} onDone={onDone} close={close} />)+// Correcting how long a saved session ran — mostly the workout nobody ended until they got home+// (Discord). The start stays, the end follows it; the sets, the order of history and the badges+// do not depend on the length and are left alone.+function WorkoutDurationEdit({ w, onDone, close }) {+ const [dur, setDur] = useState(durationMinOf(w))+ const save = () => {+ let changed = false+ update(s => {+ const next = setWorkoutDuration(s.workouts, w, dur)+ if (next) { s.workouts = next; changed = true }+ })+ close()+ if (!changed) return+ onDone && onDone()+ toast(t('Duration changed'))+ }+ return <>+ <h3>{t('Change duration')}</h3>+ <div className="muted small" style={{ marginBottom: 12 }}>{t('Forgot to finish on time? Set how long the session really took. It keeps its start time and its sets.')}</div>+ <Stepper label={t('Duration')} unit="min" value={dur} step={5} decimal={false} onChange={v => setDur(Math.max(1, Math.round(v)))} />+ <div style={{ height: 18 }} />+ <Button variant="primary" onClick={save}>{t('Save')}</Button>+ </>+}+export const workoutDurationSheet = (w, onDone) => ui().openSheet(close => <WorkoutDurationEdit w={w} onDone={onDone} close={close} />)+function WorkoutDetail({ w, close }) {const noteRef = useRef(null)const onNoteFocus = useSheetKeyboard(noteRef)@@ -1816,6 +1842,11 @@ function WorkoutDetail({ w, close }) {initial.current = latest.current.trim().slice(0, NOTE_MAX)workoutDateSheet(w, close)}}>{t('Change date & time')}</Button>+ <Button icon="timer" style={{ marginBottom: 8 }} onClick={() => {+ saveNote()+ initial.current = latest.current.trim().slice(0, NOTE_MAX)+ workoutDurationSheet(w, close)+ }}>{t('Change duration')}</Button><Button icon="plus" onClick={() => confirmSheet({title: t('Save as routine?'),message: t('Create an independent routine from these exercise targets. Your workout history is kept.'),diff --git a/frontend/src/sheets.workoutdate.test.jsx b/frontend/src/sheets.workoutdate.test.jsxindex 6056f6033..9e4960979 100644--- a/frontend/src/sheets.workoutdate.test.jsx+++ b/frontend/src/sheets.workoutdate.test.jsx@@ -7,7 +7,7 @@ import React, { act } from 'react'import { createRoot } from 'react-dom/client'import { useStore } from './store/useStore.js'import { useUI } from './store/useUI.js'-import { workoutDateSheet, workoutDetailSheet } from './sheets.jsx'+import { workoutDateSheet, workoutDetailSheet, workoutDurationSheet } from './sheets.jsx'import { backfillStart } from './lib/backfill.js'import { startTimeOf } from './lib/workout-date.js'@@ -152,3 +152,66 @@ describe('changing the date of a saved workout', () => {expect(useUI.getState().toast).not.toHaveBeenCalledWith('Workout moved')})})++// People forget to end a workout (Discord): a 47-minute session saved as five hours. The detail+// sheet corrects the length; the start, the day, the sets and the badges stay.+describe('changing the duration of a saved workout', () => {+ beforeEach(() => {+ globalThis.IS_REACT_ACT_ENVIRONMENT = true+ useUI.setState({ sheets: [], toasts: [], toast: vi.fn() })+ document.body.innerHTML = ''+ setHistory([+ workout('early', '2026-08-20', '18:00', 60, [entry('bench', 80)], ['bench']),+ workout('forgot', '2026-08-25', '07:30', 300, [entry('bench', 90)], ['bench']),+ ])+ })+ afterEach(unmountAll)++ it('is offered from the workout detail sheet and opens at the length it has', () => {+ const host = render(() => workoutDetailSheet(history()[1]))+ const open = button(host, 'Change duration')+ expect(open).toBeTruthy()+ const edit = render(() => open.click())+ expect(edit.querySelector('h3').textContent).toBe('Change duration')+ expect(edit.querySelector('input.num').value).toBe('300')+ })++ it('shortens the session from its start and leaves everything else as it was', () => {+ const before = history()[1]+ const host = render(() => workoutDurationSheet(before))+ act(() => { type(host.querySelector('input.num'), '50') })+ act(() => { host.querySelector('button[aria-label="Decrease"]').click() })+ act(() => { button(host, 'Save').click() })++ const after = history()[1]+ expect(after.end - after.start).toBe(45 * 60000)+ expect(after.start).toBe(before.start)+ expect(after.d).toBe(before.d)+ expect(after.entries).toEqual(before.entries)+ expect(after.prs).toEqual(['bench'])+ expect(after._ts).toBeGreaterThan(0) // stamped: the sync keeps it over an older copy+ expect(history().map(w => w.id)).toEqual(['early', 'forgot'])+ expect(useUI.getState().toast).toHaveBeenCalledWith('Duration changed')+ })++ it('saving the same length closes and touches nothing', () => {+ const before = history()+ const host = render(() => workoutDurationSheet(before[1]))+ act(() => { button(host, 'Save').click() })+ expect(history()).toEqual(before)+ expect(useUI.getState().toast).not.toHaveBeenCalled()+ expect(useUI.getState().sheets).toHaveLength(0)+ })++ it('keeps a note typed in the detail sheet but never blurred', () => {+ const host = render(() => workoutDetailSheet(history()[1]))+ act(() => { type(host.querySelector('textarea'), 'forgot to stop') })+ const edit = render(() => button(host, 'Change duration').click())+ act(() => { type(edit.querySelector('input.num'), '60') })+ act(() => { button(edit, 'Save').click() })+ unmountAll()+ const saved = history().find(w => w.id === 'forgot')+ expect(saved.note).toBe('forgot to stop')+ expect(saved.end - saved.start).toBe(60 * 60000)+ })+})