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.

feat(history): edit the date and start time of a saved workout (#218)

parth0f3034329989
diff --git a/README.md b/README.md
index ae209c69a..15862e938 100644
--- a/README.md
+++ b/README.md
@@ -88,6 +88,7 @@ as a home-screen app, passkey sign-in, offline support, sync across your phone a
- ↔️ **Reps per side** — for lunges, single-arm rows and the rest. You log the total, the app shows the split ("8 per side"), and the target steps in twos so it never lands on a number one side can't have
- 🏋️ **Plate math for barbell work** — barbell, EZ, trap bar and Smith machine carry a bar weight (20 kg / 45 lb and friends, or your own per exercise), and the workout screen tells you what goes on each side: *Bar 20 kg · 30 kg per side*. You still log the total, so your history, progression and 1RM keep meaning exactly what they always did
- 📝 **Log a past workout** — forgot your phone, trained on paper, or switched apps? Add a session after the fact from History: date, start time, duration, routine or freestyle, then the normal workout screen — weights, reps, RIR/RPE, timed sets and all. If that day already has a workout you choose: replace it, keep both, or cancel. Backfilled sessions never claim PRs against workouts that came later
+- ✏️ **Change when a workout happened** — typed a session in from another app, or logged it on the wrong day? Edit the date and start time of any workout in History. What you lifted is the record and is never touched — the sets, the volume and the notes stay put, and the session keeps the length it had; it just moves to where it belongs. PR badges the new order falsifies are taken back, and only the session you moved can earn one, so imported history never sprouts trophies it never had
- 🎲 **Freestyle sessions** — train without a plan and pick exercises as you go. Each one arrives prefilled from the last time you did it — same sets, same reps and weight by position — so an unplanned session doesn't start by asking you to retype last week
- 🏃 **Cardio** — log time + speed, not just weight × reps
- 📤 **Share a plan** — send someone your routines and week schedule as a small file (no workouts, no weigh-ins), or print it as a clean PDF. Importing merges, so their plan is never overwritten
diff --git a/frontend/src/lib/pt-br-locale.test.js b/frontend/src/lib/pt-br-locale.test.js
index f692c6095..f205af923 100644
--- a/frontend/src/lib/pt-br-locale.test.js
+++ b/frontend/src/lib/pt-br-locale.test.js
@@ -27,7 +27,7 @@ describe('Brazilian Portuguese locale', () => {
.sort(byCodeUnit)
const fingerprint = createHash('sha256').update(JSON.stringify(inherited)).digest('hex')
- expect(Object.keys(PT_BR_OVERRIDES)).toHaveLength(644)
+ expect(Object.keys(PT_BR_OVERRIDES)).toHaveLength(647)
expect(inherited).toHaveLength(647)
// If this fails, review the changed keys and wording before accepting a new hash. From
// frontend/: node scripts/pt-br-inheritance-fingerprint.mjs --list
diff --git a/frontend/src/lib/sync-merge.test.js b/frontend/src/lib/sync-merge.test.js
index 62c6a6fbe..b96b7d09f 100644
--- a/frontend/src/lib/sync-merge.test.js
+++ b/frontend/src/lib/sync-merge.test.js
@@ -1,5 +1,6 @@
import { describe, expect, it } from 'vitest'
import { localExtras, mergeBodyweight, mergeStates, newerOf, unionById } from './sync-merge.js'
+import { retimeWorkout } from './workout-date.js'
const workout = (id, d = '2026-09-01', start = 1) => ({ id, d, start, entries: [] })
const routine = (id, name = id) => ({ id, name, ex: [] })
@@ -119,6 +120,26 @@ describe('mergeStates', () => {
expect(m.workouts).toHaveLength(2)
})
+ // Editing the date of a pre-id workout changes the very thing it is keyed by, so the other
+ // device's untouched copy has to be recognised as the same record. retimeWorkout freezes the
+ // old day-and-start as the id, which is what makes that hold.
+ it('a legacy workout moved to another day replaces its untouched copy', () => {
+ const legacy = { d: '2026-09-01', start: 5, entries: [], prs: [] }
+ const moved = retimeWorkout(legacy, '2026-08-20', '07:00')
+ const m = mergeStates({ _ts: 2, workouts: [moved] }, { _ts: 1, workouts: [{ ...legacy }] })
+ expect(m.workouts).toHaveLength(1)
+ expect(m.workouts[0].d).toBe('2026-08-20')
+ })
+
+ // Why the id is the old key rather than a fresh one: a new id shares nothing with the copy
+ // on the other device, so the union keeps both and the workout comes back twice.
+ it('a fresh id on the same edit would have duplicated it', () => {
+ const legacy = { d: '2026-09-01', start: 5, entries: [], prs: [] }
+ const renamed = { ...legacy, id: 'brand-new', d: '2026-08-20' }
+ const m = mergeStates({ _ts: 2, workouts: [renamed] }, { _ts: 1, workouts: [{ ...legacy }] })
+ expect(m.workouts).toHaveLength(2)
+ })
+
// The report that started this: desktop adopted the server copy at T0, the phone logged a
// workout at T1, the desktop then changed one setting at T2 and pushed its whole document.
it('the desktop setting and the phone workout both survive', () => {
diff --git a/frontend/src/lib/workout-date.js b/frontend/src/lib/workout-date.js
new file mode 100644
index 000000000..41b91a25a
--- /dev/null
+++ b/frontend/src/lib/workout-date.js
@@ -0,0 +1,90 @@
+// Moving a workout that is already in history to another date or start time.
+//
+// Nothing about what was lifted changes here: the sets, the volume and the notes are the
+// record. What changes is when it happened — which means the history has to be re-filed in
+// date order, the session has to keep the length it had, and the PR badges have to be
+// re-derived, because "this was a personal record" is a claim about what came before it.
+//
+// Kept pure and separate from backfill.js (which is about logging a session that never
+// existed) so the date arithmetic and the badge surgery are testable without the UI.
+import { insertChronological, backfillStart } from './backfill.js'
+import { bestWeightForEntry } from './history.js'
+
+// Before ids existed a workout was keyed for sync by its day and start time
+// (`workoutKey` in sync-merge.js). That is exactly what this edit changes, so moving such a
+// record would give it a new key and the other device's untouched copy would come back from
+// the merge as a second workout. Freezing the old key as the id keeps both sides agreeing on
+// which record this is, and the union-by-id then lets the newer copy win.
+export const legacySyncKey = w => `${w?.d}|${w?.start}`
+
+// `<input type="time">` wants the wall-clock start in the browser's zone — the same zone
+// backfillStart() writes it in, so this round-trips.
+export const startTimeOf = w => {
+ const d = new Date(w?.start || 0)
+ const pad = n => String(n).padStart(2, '0')
+ return `${pad(d.getHours())}:${pad(d.getMinutes())}`
+}
+
+// Which workout an edit is about. Ids are the identity everywhere else, but a legacy record
+// has none and `x.id === undefined` would happily match the wrong one.
+export const sameWorkout = (a, b) =>
+ a?.id != null || b?.id != null ? a?.id === b?.id : legacySyncKey(a) === legacySyncKey(b)
+
+// The workout as it is after the move: same session, new position in time. The duration is
+// carried rather than recomputed, so a session that ran 47 minutes still ran 47 minutes.
+export function retimeWorkout(w, iso, time) {
+ const duration = Math.max(0, (w.end ?? w.start) - w.start)
+ const start = backfillStart(iso, time)
+ const moved = { ...w, d: iso, start, end: start + duration }
+ if (w.id == null) moved.id = legacySyncKey(w)
+ return moved
+}
+
+// `prs` is written once, at finish, against the all-time best (bestWeightFor) — which reads as
+// chronological only because history normally grows forwards. Once a session moves, a badge it
+// was given may no longer be true.
+//
+// The rule is deliberately asymmetric: a move can take a badge away from any session whose
+// claim the new order breaks, but only the session that moved can gain one. Imported and
+// backfilled history is filed with `prs: []` for every session on purpose, so awarding badges
+// by pure chronology would make a year of imported workouts sprout trophies the user never
+// earned the first time one date was nudged. Revoking a claim the order has falsified is a
+// correction; handing out new ones is an invention.
+//
+// Only `exerciseIds` are reconsidered — every other badge in history is left exactly as it was.
+export function rebuildPrHistory(workouts, exerciseIds, moved = null) {
+ const ids = new Set(exerciseIds || [])
+ if (!ids.size) return workouts
+ const best = new Map()
+ return workouts.map(w => {
+ const had = w.prs || []
+ const kept = []
+ let trains = false
+ for (const e of w.entries || []) {
+ if (!ids.has(e.id)) continue
+ trains = true
+ const top = bestWeightForEntry(e)
+ // Leads everything dated before it. The running best grows whether or not a badge is
+ // written, so a session that cannot gain one still raises the bar for the next.
+ const leads = top > 0 && top > (best.get(e.id) || 0)
+ if (leads) best.set(e.id, top)
+ if (leads && (w === moved || had.includes(e.id))) kept.push(e.id)
+ }
+ if (!trains) return w
+ const prs = [...new Set([...had.filter(id => !ids.has(id)), ...kept])]
+ if (prs.length === had.length && prs.every((id, i) => id === had[i])) return w
+ return { ...w, prs }
+ })
+}
+
+// The history after a workout has been moved: the old copy is gone, the moved one sits where
+// its new date and start time put it, and every exercise it touches has its badges rebuilt.
+// Returns the new array, or `null` when there is nothing to move. The caller stores it.
+export function moveWorkout(workouts, ref, iso, time) {
+ const list = Array.isArray(workouts) ? workouts : []
+ const current = list.find(w => sameWorkout(w, ref))
+ if (!current) return null
+ const moved = retimeWorkout(current, iso, time)
+ const filed = insertChronological(list.filter(w => w !== current), moved)
+ return rebuildPrHistory(filed, (current.entries || []).map(e => e.id), moved)
+}
diff --git a/frontend/src/lib/workout-date.test.js b/frontend/src/lib/workout-date.test.js
new file mode 100644
index 000000000..8514dcee4
--- /dev/null
+++ b/frontend/src/lib/workout-date.test.js
@@ -0,0 +1,217 @@
+import { describe, expect, it } from 'vitest'
+import { legacySyncKey, startTimeOf, sameWorkout, retimeWorkout, rebuildPrHistory, moveWorkout } from './workout-date.js'
+import { backfillStart } from './backfill.js'
+
+const set = w => ({ w, r: 5, done: true })
+const entry = (id, w) => ({ id, sets: [set(w)] })
+// A session on `d` starting at `time`, lasting `min` minutes.
+const w = (id, d, time, min, entries = [], prs = []) => {
+ const start = backfillStart(d, time)
+ return { id, d, start, end: start + min * 60000, name: id, entries, prs }
+}
+
+describe('startTimeOf', () => {
+ it('reads back the wall-clock time backfillStart wrote', () => {
+ expect(startTimeOf({ start: backfillStart('2026-03-10', '07:45') })).toBe('07:45')
+ expect(startTimeOf({ start: backfillStart('2026-03-10', '18:00') })).toBe('18:00')
+ })
+ it('pads and survives a missing start', () => {
+ expect(startTimeOf({ start: backfillStart('2026-03-10', '06:05') })).toBe('06:05')
+ expect(startTimeOf({})).toMatch(/^\d\d:\d\d$/)
+ })
+})
+
+describe('sameWorkout / legacySyncKey', () => {
+ it('matches on id when either side has one', () => {
+ expect(sameWorkout({ id: 'a' }, { id: 'a' })).toBe(true)
+ expect(sameWorkout({ id: 'a' }, { id: 'b' })).toBe(false)
+ expect(sameWorkout({ id: 'a', d: '2026-01-01', start: 1 }, { d: '2026-01-01', start: 1 })).toBe(false)
+ })
+ it('falls back to day and start for records written before ids', () => {
+ expect(sameWorkout({ d: '2026-01-01', start: 5 }, { d: '2026-01-01', start: 5 })).toBe(true)
+ expect(sameWorkout({ d: '2026-01-01', start: 5 }, { d: '2026-01-02', start: 5 })).toBe(false)
+ expect(legacySyncKey({ d: '2026-01-01', start: 5 })).toBe('2026-01-01|5')
+ })
+})
+
+describe('retimeWorkout', () => {
+ it('moves the session and keeps the length it had', () => {
+ const moved = retimeWorkout(w('a', '2026-03-10', '18:00', 47), '2026-02-01', '07:30')
+ expect(moved.d).toBe('2026-02-01')
+ expect(startTimeOf(moved)).toBe('07:30')
+ expect(moved.end - moved.start).toBe(47 * 60000)
+ })
+ it('leaves everything else alone and does not mutate the input', () => {
+ const before = w('a', '2026-03-10', '18:00', 60, [entry('bench', 100)], ['bench'])
+ const copy = JSON.parse(JSON.stringify(before))
+ const moved = retimeWorkout(before, '2026-02-01', '07:30')
+ expect(before).toEqual(copy)
+ expect(moved.entries).toBe(before.entries)
+ expect(moved.prs).toEqual(['bench'])
+ expect(moved.name).toBe('a')
+ })
+ it('a zero-length record stays zero-length', () => {
+ const moved = retimeWorkout({ id: 'a', d: '2026-03-10', start: 10, end: 10 }, '2026-02-01', '07:30')
+ expect(moved.end).toBe(moved.start)
+ })
+ it('an end before the start cannot make the session run backwards', () => {
+ const moved = retimeWorkout({ id: 'a', d: '2026-03-10', start: 100, end: 50 }, '2026-02-01', '07:30')
+ expect(moved.end).toBe(moved.start)
+ })
+ it('a record with no end keeps a zero length rather than NaN', () => {
+ const moved = retimeWorkout({ id: 'a', d: '2026-03-10', start: 100 }, '2026-02-01', '07:30')
+ expect(moved.end).toBe(moved.start)
+ })
+ // The sync key of a legacy record is its day and start time, which is what this edit
+ // changes. Freezing the old key as the id is what stops the merge duplicating it.
+ it('gives a legacy record the old day-and-start as its id', () => {
+ const moved = retimeWorkout({ d: '2026-03-10', start: 1741626000000, end: 1741626000000, entries: [] }, '2026-02-01', '07:30')
+ expect(moved.id).toBe('2026-03-10|1741626000000')
+ })
+ it('never rewrites an id it already has', () => {
+ expect(retimeWorkout(w('keep', '2026-03-10', '18:00', 60), '2026-02-01', '07:30').id).toBe('keep')
+ })
+})
+
+describe('rebuildPrHistory', () => {
+ it('gives the moved session the badge when it is now the first to hit a weight', () => {
+ // Logged heavy-first, so the 90 kg session never claimed a record.
+ const heavy = w('heavy', '2026-01-05', '18:00', 60, [entry('bench', 100)], ['bench'])
+ const light = w('light', '2026-01-09', '18:00', 60, [entry('bench', 90)], [])
+ // The light one is moved to before the heavy one; it is now the first 90 kg ever.
+ const out = rebuildPrHistory([light, heavy], ['bench'], light)
+ expect(out.map(x => x.prs)).toEqual([['bench'], ['bench']])
+ })
+ it('takes the badge away from a session that no longer leads', () => {
+ const stale = w('b', '2026-01-05', '18:00', 60, [entry('bench', 90)], ['bench'])
+ const out = rebuildPrHistory([
+ w('a', '2026-01-01', '18:00', 60, [entry('bench', 100)], ['bench']),
+ stale,
+ ], ['bench'])
+ expect(out.map(x => x.prs)).toEqual([['bench'], []])
+ })
+ it('takes it away from the moved session too when it no longer leads', () => {
+ const moved = w('moved', '2026-01-05', '18:00', 60, [entry('bench', 80)], ['bench'])
+ const out = rebuildPrHistory([
+ w('a', '2026-01-01', '18:00', 60, [entry('bench', 100)], ['bench']),
+ moved,
+ ], ['bench'], moved)
+ expect(out.map(x => x.prs)).toEqual([['bench'], []])
+ })
+ // Imports and backfilled sessions are filed with no badges on purpose. Rebuilding by pure
+ // chronology would hand a year of imported history trophies it never had.
+ it('never hands a badge to a session that did not move', () => {
+ const moved = w('mine', '2026-02-01', '18:00', 60, [entry('bench', 120)], ['bench'])
+ const out = rebuildPrHistory([
+ w('imported-1', '2026-01-01', '18:00', 60, [entry('bench', 70)], []),
+ w('imported-2', '2026-01-08', '18:00', 60, [entry('bench', 80)], []),
+ moved,
+ ], ['bench'], moved)
+ expect(out.map(x => [x.id, x.prs])).toEqual([['imported-1', []], ['imported-2', []], ['mine', ['bench']]])
+ })
+ it('a moved session does not gain a badge on an exercise it does not lead', () => {
+ const moved = w('moved', '2026-01-08', '18:00', 60, [entry('bench', 60)], [])
+ const out = rebuildPrHistory([
+ w('imported', '2026-01-01', '18:00', 60, [entry('bench', 80)], []),
+ moved,
+ ], ['bench'], moved)
+ expect(out.map(x => x.prs)).toEqual([[], []])
+ })
+ it('keeps the badges of exercises it was not asked about', () => {
+ const later = w('b', '2026-01-05', '18:00', 60, [entry('bench', 90), entry('squat', 150)], ['squat'])
+ const out = rebuildPrHistory([
+ w('a', '2026-01-01', '18:00', 60, [entry('bench', 100), entry('squat', 140)], ['bench', 'squat']),
+ later,
+ ], ['bench'], later)
+ expect(out[0].prs).toEqual(['squat', 'bench'])
+ expect(out[1].prs).toEqual(['squat'])
+ })
+ it('leaves a session that does not train the exercise untouched', () => {
+ const moved = w('b', '2026-01-05', '18:00', 60, [entry('bench', 90)], [])
+ const list = [w('a', '2026-01-01', '18:00', 60, [entry('squat', 140)], ['squat']), moved]
+ const out = rebuildPrHistory(list, ['bench'], moved)
+ expect(out[0]).toBe(list[0])
+ expect(out[1].prs).toEqual(['bench'])
+ })
+ it('an unloaded or cardio entry is never a record', () => {
+ const moved = w('b', '2026-01-05', '18:00', 60, [entry('pullup', 0)], [])
+ const out = rebuildPrHistory([
+ w('a', '2026-01-01', '18:00', 60, [entry('pullup', 0)], []),
+ moved,
+ ], ['pullup'], moved)
+ expect(out.map(x => x.prs)).toEqual([[], []])
+ })
+ it('equalling a weight is not a new record', () => {
+ const moved = w('b', '2026-01-05', '18:00', 60, [entry('bench', 100)], [])
+ const out = rebuildPrHistory([
+ w('a', '2026-01-01', '18:00', 60, [entry('bench', 100)], ['bench']),
+ moved,
+ ], ['bench'], moved)
+ expect(out.map(x => x.prs)).toEqual([['bench'], []])
+ })
+ it('a session that cannot gain a badge still raises the bar for the next', () => {
+ // The imported 100 kg carries no badge, and must still stop the mover claiming 90 kg.
+ const moved = w('moved', '2026-01-08', '18:00', 60, [entry('bench', 90)], [])
+ const out = rebuildPrHistory([
+ w('imported', '2026-01-01', '18:00', 60, [entry('bench', 100)], []),
+ moved,
+ ], ['bench'], moved)
+ expect(out.map(x => x.prs)).toEqual([[], []])
+ })
+ it('does nothing without exercises and never mutates the input', () => {
+ const list = [w('a', '2026-01-01', '18:00', 60, [entry('bench', 100)], ['bench'])]
+ expect(rebuildPrHistory(list, [])).toBe(list)
+ const copy = JSON.parse(JSON.stringify(list))
+ rebuildPrHistory(list, ['bench'], list[0])
+ expect(list).toEqual(copy)
+ })
+})
+
+describe('moveWorkout', () => {
+ const list = () => [
+ w('a', '2026-01-01', '18:00', 60, [entry('bench', 80)], ['bench']),
+ w('b', '2026-01-05', '18:00', 60, [entry('bench', 100)], ['bench']),
+ w('c', '2026-01-09', '18:00', 60, [entry('bench', 90)], []),
+ ]
+ it('re-files the session in date order', () => {
+ const out = moveWorkout(list(), { id: 'c' }, '2026-01-03', '07:00')
+ expect(out.map(x => x.id)).toEqual(['a', 'c', 'b'])
+ })
+ it('rebuilds the badges of every exercise the session trained', () => {
+ // 90 kg on 2026-01-03 beats the 80 kg before it, and the 100 kg session still leads.
+ const out = moveWorkout(list(), { id: 'c' }, '2026-01-03', '07:00')
+ expect(out.map(x => [x.id, x.prs])).toEqual([['a', ['bench']], ['c', ['bench']], ['b', ['bench']]])
+ })
+ it('a session left where it is never gains a badge from someone else moving', () => {
+ // 'c' (90 kg, no badge) moves to the front. 'a' (80 kg) now trails it and loses its badge;
+ // nothing that stayed put is handed one.
+ const out = moveWorkout(list(), { id: 'c' }, '2025-12-31', '07:00')
+ expect(out.map(x => [x.id, x.prs])).toEqual([['c', ['bench']], ['a', []], ['b', ['bench']]])
+ })
+ it('a session moved after a heavier one loses its badge', () => {
+ const out = moveWorkout(list(), { id: 'a' }, '2026-01-07', '07:00')
+ expect(out.map(x => [x.id, x.prs])).toEqual([['b', ['bench']], ['a', []], ['c', []]])
+ })
+ it('places the session by start time within the day it lands on', () => {
+ const out = moveWorkout(list(), { id: 'c' }, '2026-01-05', '07:00')
+ expect(out.map(x => x.id)).toEqual(['a', 'c', 'b'])
+ expect(moveWorkout(list(), { id: 'c' }, '2026-01-05', '21:00').map(x => x.id)).toEqual(['a', 'b', 'c'])
+ })
+ it('returns null when the workout is not there', () => {
+ expect(moveWorkout(list(), { id: 'zz' }, '2026-01-03', '07:00')).toBe(null)
+ expect(moveWorkout(undefined, { id: 'a' }, '2026-01-03', '07:00')).toBe(null)
+ })
+ it('does not mutate the history it was given', () => {
+ const before = list()
+ const copy = JSON.parse(JSON.stringify(before))
+ moveWorkout(before, { id: 'c' }, '2026-01-03', '07:00')
+ expect(before).toEqual(copy)
+ })
+ it('moves a legacy record and leaves its twin no way to come back', () => {
+ const legacy = { d: '2026-01-05', start: 1767636000000, end: 1767639600000, name: 'Old', entries: [], prs: [] }
+ const out = moveWorkout([legacy], legacy, '2026-01-03', '07:00')
+ expect(out).toHaveLength(1)
+ expect(out[0].id).toBe('2026-01-05|1767636000000')
+ expect(out[0].d).toBe('2026-01-03')
+ })
+})
diff --git a/frontend/src/locales/de.js b/frontend/src/locales/de.js
index fad9cba71..87222c1d3 100644
--- a/frontend/src/locales/de.js
+++ b/frontend/src/locales/de.js
@@ -1143,6 +1143,9 @@ export default {
'Start time': 'Startzeit',
'Continue': 'Weiter',
'Pick a day up to today': 'Wähle einen Tag bis heute',
+ 'Change date & time': 'Datum & Uhrzeit ändern',
+ 'Workout moved': 'Training verschoben',
+ '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',
'Add as second workout': 'Als zweites Training hinzufügen',
diff --git a/frontend/src/locales/es.js b/frontend/src/locales/es.js
index 68e2144a4..a54f271f7 100644
--- a/frontend/src/locales/es.js
+++ b/frontend/src/locales/es.js
@@ -1123,6 +1123,9 @@ export default {
'Start time': 'Hora de inicio',
'Continue': 'Continuar',
'Pick a day up to today': 'Elige un día hasta hoy',
+ 'Change date & time': 'Cambiar fecha y hora',
+ 'Workout moved': 'Entrenamiento movido',
+ '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',
'Add as second workout': 'Añadir como segundo entrenamiento',
diff --git a/frontend/src/locales/fr.js b/frontend/src/locales/fr.js
index ff4b17cfd..228eaac68 100644
--- a/frontend/src/locales/fr.js
+++ b/frontend/src/locales/fr.js
@@ -1123,6 +1123,9 @@ export default {
'Start time': 'Heure de début',
'Continue': 'Continuer',
'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',
+ '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',
'Add as second workout': 'Ajouter comme deuxième séance',
diff --git a/frontend/src/locales/hi.js b/frontend/src/locales/hi.js
index da466b3f2..051da7ebc 100644
--- a/frontend/src/locales/hi.js
+++ b/frontend/src/locales/hi.js
@@ -1123,6 +1123,9 @@ export default {
'Start time': 'शुरू होने का समय',
'Continue': 'जारी रखें',
'Pick a day up to today': 'आज तक का कोई दिन चुनें',
+ 'Change date & time': 'दिनांक और समय बदलें',
+ 'Workout moved': 'वर्कआउट खिसकाया गया',
+ 'The session keeps its length. Personal records are worked out again from the new order.': 'सेशन की अवधि वही रहती है। नए क्रम के अनुसार निजी रिकॉर्ड दोबारा निकाले जाते हैं।',
'There is already a workout on that day.': 'उस दिन पहले से एक वर्कआउट है।',
'Replace': 'बदलें',
'Add as second workout': 'दूसरे वर्कआउट के रूप में जोड़ें',
diff --git a/frontend/src/locales/hu.js b/frontend/src/locales/hu.js
index f99fa4ff9..01ca1049f 100644
--- a/frontend/src/locales/hu.js
+++ b/frontend/src/locales/hu.js
@@ -788,6 +788,9 @@ export default {
'Start time': 'Kezdés ideje',
'Continue': 'Tovább',
'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',
+ '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',
'Add as second workout': 'Hozzáadás második edzésként',
diff --git a/frontend/src/locales/it.js b/frontend/src/locales/it.js
index 3c8c8415f..cc711fd0b 100644
--- a/frontend/src/locales/it.js
+++ b/frontend/src/locales/it.js
@@ -1123,6 +1123,9 @@ export default {
'Start time': 'Ora di inizio',
'Continue': 'Continua',
'Pick a day up to today': 'Scegli un giorno fino a oggi',
+ 'Change date & time': 'Cambia data e ora',
+ 'Workout moved': 'Allenamento spostato',
+ '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',
'Add as second workout': 'Aggiungi come secondo allenamento',
diff --git a/frontend/src/locales/ko.js b/frontend/src/locales/ko.js
index 48ea492ff..9e0db6069 100644
--- a/frontend/src/locales/ko.js
+++ b/frontend/src/locales/ko.js
@@ -1123,6 +1123,9 @@ export default {
'Start time': '시작 시간',
'Continue': '계속',
'Pick a day up to today': '오늘까지의 날짜를 선택하세요',
+ 'Change date & time': '날짜 및 시간 변경',
+ 'Workout moved': '운동을 옮겼습니다',
+ 'The session keeps its length. Personal records are worked out again from the new order.': '세션 길이는 그대로 유지됩니다. 개인 기록은 새 순서에 따라 다시 계산됩니다.',
'There is already a workout on that day.': '그날에 이미 운동이 있습니다.',
'Replace': '바꾸기',
'Add as second workout': '두 번째 운동으로 추가',
diff --git a/frontend/src/locales/pl.js b/frontend/src/locales/pl.js
index 213baab72..156f1779e 100644
--- a/frontend/src/locales/pl.js
+++ b/frontend/src/locales/pl.js
@@ -1123,6 +1123,9 @@ export default {
'Start time': 'Godzina rozpoczęcia',
'Continue': 'Dalej',
'Pick a day up to today': 'Wybierz dzień do dzisiaj',
+ 'Change date & time': 'Zmień datę i godzinę',
+ 'Workout moved': 'Trening przeniesiony',
+ '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',
'Add as second workout': 'Dodaj jako drugi trening',
diff --git a/frontend/src/locales/pt-BR.js b/frontend/src/locales/pt-BR.js
index 324b0f2ae..983363dbe 100644
--- a/frontend/src/locales/pt-BR.js
+++ b/frontend/src/locales/pt-BR.js
@@ -618,6 +618,9 @@ export const PT_BR_OVERRIDES = {
'Log a past workout': 'Registrar um treino passado',
'Logged on the usual workout screen, without timers.': 'Registrado na tela de treino habitual, só sem temporizadores.',
'Pick a day up to today': 'Escolha um dia até hoje',
+ '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.',
'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.js
index ea44d465c..95b5c601b 100644
--- a/frontend/src/locales/pt.js
+++ b/frontend/src/locales/pt.js
@@ -1123,6 +1123,9 @@ export default {
'Start time': 'Hora de início',
'Continue': 'Continuar',
'Pick a day up to today': 'Escolhe um dia até hoje',
+ '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 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',
'Add as second workout': 'Adicionar como segundo treino',
diff --git a/frontend/src/locales/ru.js b/frontend/src/locales/ru.js
index 46ce8efb2..f7140eae1 100644
--- a/frontend/src/locales/ru.js
+++ b/frontend/src/locales/ru.js
@@ -1123,6 +1123,9 @@ export default {
'Start time': 'Время начала',
'Continue': 'Продолжить',
'Pick a day up to today': 'Выбери день не позже сегодняшнего',
+ 'Change date & time': 'Изменить дату и время',
+ 'Workout moved': 'Тренировка перенесена',
+ 'The session keeps its length. Personal records are worked out again from the new order.': 'Длительность тренировки сохраняется. Личные рекорды пересчитываются по новому порядку.',
'There is already a workout on that day.': 'В этот день уже есть тренировка.',
'Replace': 'Заменить',
'Add as second workout': 'Добавить как вторую тренировку',
diff --git a/frontend/src/locales/th.js b/frontend/src/locales/th.js
index f2b372dbd..c956f2241 100644
--- a/frontend/src/locales/th.js
+++ b/frontend/src/locales/th.js
@@ -796,6 +796,9 @@ export default {
'Start time': 'เวลาเริ่ม',
'Continue': 'ดำเนินการต่อ',
'Pick a day up to today': 'เลือกวันได้ไม่เกินวันนี้',
+ 'Change date & time': 'เปลี่ยนวันที่และเวลา',
+ 'Workout moved': 'ย้ายการฝึกแล้ว',
+ 'The session keeps its length. Personal records are worked out again from the new order.': 'ระยะเวลาของเซสชันยังเท่าเดิม ระบบจะคำนวณสถิติส่วนตัวใหม่ตามลำดับใหม่',
'There is already a workout on that day.': 'วันนั้นมีการฝึกอยู่แล้ว',
'Replace': 'แทนที่',
'Add as second workout': 'เพิ่มเป็นการฝึกครั้งที่สอง',
diff --git a/frontend/src/locales/tr.js b/frontend/src/locales/tr.js
index 95720d15e..ac9dbb846 100644
--- a/frontend/src/locales/tr.js
+++ b/frontend/src/locales/tr.js
@@ -1123,6 +1123,9 @@ export default {
'Start time': 'Başlangıç saati',
'Continue': 'Devam',
'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ı',
+ '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',
'Add as second workout': 'İkinci antrenman olarak ekle',
diff --git a/frontend/src/locales/zh.js b/frontend/src/locales/zh.js
index f45110eec..8818afecc 100644
--- a/frontend/src/locales/zh.js
+++ b/frontend/src/locales/zh.js
@@ -1123,6 +1123,9 @@ export default {
'Start time': '开始时间',
'Continue': '继续',
'Pick a day up to today': '请选择今天或之前的日期',
+ 'Change date & time': '修改日期和时间',
+ 'Workout moved': '训练已移动',
+ 'The session keeps its length. Personal records are worked out again from the new order.': '训练时长保持不变。个人记录会按新的顺序重新计算。',
'There is already a workout on that day.': '那天已经有一次训练了。',
'Replace': '替换',
'Add as second workout': '添加为第二次训练',
diff --git a/frontend/src/sheets.jsx b/frontend/src/sheets.jsx
index 4c04e4720..f312f796d 100644
--- a/frontend/src/sheets.jsx
+++ b/frontend/src/sheets.jsx
@@ -37,6 +37,7 @@ import { isFav, toggleFav, sortFavouritesFirst } from './lib/favourites.js'
import { buildSessionEntries } 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'
const S = () => useStore.getState().S
const update = (...a) => useStore.getState().update(...a)
@@ -1617,6 +1618,41 @@ function DayAddRoutine({ day, close }) {
export const dayAddRoutineSheet = day => ui().openSheet(close => <DayAddRoutine day={day} close={close} />)
/* ============================ workout detail ============================ */
+// Correcting when a saved session happened: typed in from another app, or logged on the wrong
+// day. Only its place in history moves — the sets, the volume and the notes are the record, and
+// the session keeps the length it had. The PR badges of the exercises it trained are worked out
+// again, because "this was a record" is a claim about the sessions before it.
+function WorkoutDateEdit({ w, onDone, close }) {
+ const [date, setDate] = useState(w.d)
+ const [time, setTime] = useState(startTimeOf(w))
+ const today = todayISO()
+ const save = () => {
+ if (!date || date > today) { toast(t('Pick a day up to today')); return }
+ // Nothing to do, and nothing to push: a no-op save and a workout deleted from another
+ // sheet both just close.
+ if (date === w.d && time === startTimeOf(w)) { close(); return }
+ if (!(S().workouts || []).some(x => sameWorkout(x, w))) { close(); return }
+ update(s => {
+ const next = moveWorkout(s.workouts, w, date, time)
+ if (next) s.workouts = next
+ })
+ close()
+ onDone && onDone()
+ toast(t('Workout moved'))
+ }
+ return <>
+ <h3>{t('Change date & time')}</h3>
+ <div className="muted small" style={{ marginBottom: 12 }}>{t('The session keeps its length. Personal records are worked out again from the new order.')}</div>
+ <Row icon="calendar" title={t('Date')}>
+ <input type="date" className="timef" value={date} max={today} onChange={e => setDate(e.target.value)} /></Row>
+ <Row icon="clock" title={t('Start time')}>
+ <input type="time" className="timef" value={time} onChange={e => setTime(e.target.value)} /></Row>
+ <div style={{ height: 18 }} />
+ <Button variant="primary" onClick={save}>{t('Save')}</Button>
+ </>
+}
+export const workoutDateSheet = (w, onDone) => ui().openSheet(close => <WorkoutDateEdit w={w} onDone={onDone} close={close} />)
+
function WorkoutDetail({ w, close }) {
const noteRef = useRef(null)
const onNoteFocus = useSheetKeyboard(noteRef)
@@ -1690,6 +1726,13 @@ function WorkoutDetail({ w, close }) {
placeholder={t('How the session went as a whole.')}
onFocus={onNoteFocus} onChange={e => setNote(e.target.value)} onBlur={saveNote} />
<div style={{ height: 14 }} />
+ {/* The note lives in a textarea that only writes on blur, and moving the workout re-keys a
+ legacy record — so flush it first and stop the unmount hook writing it a second time. */}
+ <Button icon="calendar" style={{ marginBottom: 8 }} onClick={() => {
+ saveNote()
+ initial.current = latest.current.trim().slice(0, NOTE_MAX)
+ workoutDateSheet(w, close)
+ }}>{t('Change date & time')}</Button>
<Button variant="danger" onClick={() => confirmSheet({ title: t('Delete workout?'), message: t('This removes it from your history for good.'), confirmText: t('Delete'), danger: true, onConfirm: () => { update(s => { s.workouts = s.workouts.filter(x => x.id !== w.id) }); close(); toast(t('Workout deleted')) } })}>{t('Delete workout')}</Button>
</>
}
diff --git a/frontend/src/sheets.workoutdate.test.jsx b/frontend/src/sheets.workoutdate.test.jsx
new file mode 100644
index 000000000..6056f6033
--- /dev/null
+++ b/frontend/src/sheets.workoutdate.test.jsx
@@ -0,0 +1,154 @@
+// @vitest-environment happy-dom
+// Editing when a saved workout happened (#218). The sets are the record and are never touched;
+// what moves is where the session sits in history — which is also what the PR badges and the
+// legacy sync key depend on, so both are checked from the sheet, not just from the helper.
+import { describe, expect, it, beforeEach, afterEach, vi } from 'vitest'
+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 { backfillStart } from './lib/backfill.js'
+import { startTimeOf } from './lib/workout-date.js'
+
+const mounted = []
+function render(open) {
+ open()
+ const sheet = useUI.getState().sheets.at(-1)
+ const host = document.createElement('div')
+ document.body.appendChild(host)
+ const root = createRoot(host)
+ mounted.push(root)
+ act(() => root.render(sheet.render(() => useUI.getState().closeSheet(sheet.id))))
+ return host
+}
+const type = (el, value) => {
+ Object.getOwnPropertyDescriptor(el.constructor.prototype, 'value').set.call(el, value)
+ el.dispatchEvent(new Event('input', { bubbles: true }))
+}
+const button = (host, text) => [...host.querySelectorAll('button')].find(b => b.textContent.trim() === text)
+const unmountAll = () => act(() => { mounted.splice(0).forEach(r => r.unmount()) })
+
+const entry = (id, w) => ({ id, sets: [{ w, r: 5, done: true }] })
+const workout = (id, d, time, min, entries, prs = []) => {
+ const start = backfillStart(d, time)
+ return { id, d, start, end: start + min * 60000, name: id, vol: 100, entries, prs }
+}
+const history = () => useStore.getState().S.workouts
+const setHistory = workouts => useStore.setState(s => ({ S: { ...s.S, workouts } }))
+
+describe('changing the date 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('late', '2026-08-25', '07:30', 47, [entry('bench', 90)], ['bench']),
+ ])
+ })
+ afterEach(unmountAll)
+
+ it('is offered from the workout detail sheet and opens prefilled', () => {
+ const host = render(() => workoutDetailSheet(history()[1]))
+ const open = button(host, 'Change date & time')
+ expect(open).toBeTruthy()
+ const edit = render(() => open.click())
+ expect(edit.querySelector('h3').textContent).toBe('Change date & time')
+ expect(edit.querySelector('input[type=date]').value).toBe('2026-08-25')
+ expect(edit.querySelector('input[type=time]').value).toBe('07:30')
+ })
+
+ it('moves the session, keeps the length it had and re-files it in date order', () => {
+ const host = render(() => workoutDateSheet(history()[1]))
+ act(() => { type(host.querySelector('input[type=date]'), '2026-08-18') })
+ act(() => { type(host.querySelector('input[type=time]'), '06:15') })
+ act(() => { button(host, 'Save').click() })
+
+ expect(history().map(w => w.id)).toEqual(['late', 'early'])
+ const moved = history()[0]
+ expect(moved.d).toBe('2026-08-18')
+ expect(startTimeOf(moved)).toBe('06:15')
+ expect(moved.end - moved.start).toBe(47 * 60000)
+ expect(moved.entries).toEqual([entry('bench', 90)])
+ expect(useUI.getState().toast).toHaveBeenCalledWith('Workout moved')
+ })
+
+ it('rebuilds the PR badges the new order implies', () => {
+ // 90 kg was logged second, so 80 kg held the badge too. Moved first, the 80 kg session
+ // is no longer a record and the 90 kg one is.
+ const host = render(() => workoutDateSheet(history()[1]))
+ act(() => { type(host.querySelector('input[type=date]'), '2026-08-18') })
+ act(() => { button(host, 'Save').click() })
+ expect(history().map(w => [w.id, w.prs])).toEqual([['late', ['bench']], ['early', []]])
+ })
+
+ it('refuses a day in the future and leaves history alone', () => {
+ const before = history()
+ const host = render(() => workoutDateSheet(before[1]))
+ act(() => { type(host.querySelector('input[type=date]'), '2099-01-01') })
+ act(() => { button(host, 'Save').click() })
+ expect(history()).toEqual(before)
+ expect(useUI.getState().toast).toHaveBeenCalledWith('Pick a day up to today')
+ expect(useUI.getState().sheets).toHaveLength(1) // still open to correct the date
+ })
+
+ it('an empty date is refused rather than moving the workout to nowhere', () => {
+ const before = history()
+ const host = render(() => workoutDateSheet(before[1]))
+ act(() => { type(host.querySelector('input[type=date]'), '') })
+ act(() => { button(host, 'Save').click() })
+ expect(history()).toEqual(before)
+ expect(useUI.getState().toast).toHaveBeenCalledWith('Pick a day up to today')
+ })
+
+ it('saving without changing anything closes and touches nothing', () => {
+ const before = history()
+ const host = render(() => workoutDateSheet(before[1]))
+ act(() => { button(host, 'Save').click() })
+ expect(history()).toEqual(before)
+ expect(useUI.getState().toast).not.toHaveBeenCalled()
+ expect(useUI.getState().sheets).toHaveLength(0)
+ })
+
+ it('leaves a second workout on the same day in start-time order', () => {
+ const host = render(() => workoutDateSheet(history()[1]))
+ act(() => { type(host.querySelector('input[type=date]'), '2026-08-20') })
+ act(() => { type(host.querySelector('input[type=time]'), '21:00') })
+ act(() => { button(host, 'Save').click() })
+ expect(history().map(w => w.id)).toEqual(['early', 'late'])
+ expect(history()).toHaveLength(2)
+ })
+
+ // The note field only writes on blur, and moving a legacy record re-keys it — so a note
+ // typed and left focused has to be flushed before the move, not after it.
+ it('keeps a note typed but never blurred', () => {
+ const host = render(() => workoutDetailSheet(history()[1]))
+ act(() => { type(host.querySelector('textarea'), 'felt strong') })
+ const edit = render(() => button(host, 'Change date & time').click())
+ act(() => { type(edit.querySelector('input[type=date]'), '2026-08-18') })
+ act(() => { button(edit, 'Save').click() })
+ unmountAll()
+ expect(history().find(w => w.id === 'late').note).toBe('felt strong')
+ })
+
+ it('a record written before ids keeps one identity for sync', () => {
+ const legacy = { d: '2026-08-25', start: 1767636000000, end: 1767639600000, name: 'Old', vol: 0, entries: [], prs: [] }
+ setHistory([legacy])
+ const host = render(() => workoutDateSheet(legacy))
+ act(() => { type(host.querySelector('input[type=date]'), '2026-08-18') })
+ act(() => { button(host, 'Save').click() })
+ expect(history()).toHaveLength(1)
+ expect(history()[0].id).toBe('2026-08-25|1767636000000')
+ expect(history()[0].d).toBe('2026-08-18')
+ })
+
+ it('does nothing when the workout was deleted from another sheet meanwhile', () => {
+ const host = render(() => workoutDateSheet(history()[1]))
+ setHistory([history()[0]])
+ act(() => { type(host.querySelector('input[type=date]'), '2026-08-18') })
+ act(() => { button(host, 'Save').click() })
+ expect(history().map(w => w.id)).toEqual(['early'])
+ expect(useUI.getState().toast).not.toHaveBeenCalledWith('Workout moved')
+ })
+})