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
Workout: "Last time" says how long ago, counted from the session's day (#363)
Duarte Santosb9c66818d85c
diff --git a/frontend/src/lib/format-ago.test.js b/frontend/src/lib/format-ago.test.jsindex da8dd931c..49165a268 100644--- a/frontend/src/lib/format-ago.test.js+++ b/frontend/src/lib/format-ago.test.js@@ -1,5 +1,5 @@import { afterEach, describe, expect, it } from 'vitest'-import { fmtAgo, changeCount, setsWorkCount, fmtDur } from './format.js'+import { fmtAgo, fmtDaysAgo, changeCount, setsWorkCount, fmtDur, fmtDate } from './format.js'import { _setLangState } from './i18n-core.js'import ar from '../locales/ar.js'import uk from '../locales/uk.js'@@ -63,3 +63,52 @@ describe('fmtDur', () => {expect(fmtDur(65 * 60000)).toBe('1 год 5 хв')})})++// The "Last time (…)" line of a workout (#363): calendar days back from the session's own day.+describe('fmtDaysAgo', () => {+ afterEach(() => _setLangState('en', {}, null, null))+ const day = '2026-10-04'+ const back = n => { const d = new Date(Date.UTC(2026, 9, 4 - n)); return d.toISOString().slice(0, 10) }++ it('days for the first week, then weeks, then months', () => {+ expect(fmtDaysAgo(back(0), day)).toBe('today')+ expect(fmtDaysAgo(back(1), day)).toBe('yesterday')+ expect(fmtDaysAgo(back(2), day)).toBe('2 days ago')+ expect(fmtDaysAgo(back(6), day)).toBe('6 days ago')+ expect(fmtDaysAgo(back(7), day)).toBe('last week')+ expect(fmtDaysAgo(back(13), day)).toBe('last week')+ expect(fmtDaysAgo(back(14), day)).toBe('2 weeks ago')+ expect(fmtDaysAgo(back(34), day)).toBe('4 weeks ago')+ expect(fmtDaysAgo(back(35), day)).toBe('last month')+ expect(fmtDaysAgo(back(60), day)).toBe('last month')+ expect(fmtDaysAgo(back(61), day)).toBe('2 months ago')+ expect(fmtDaysAgo(back(364), day)).toBe('11 months ago')+ })++ it('a year or more back is the date with its year', () => {+ expect(fmtDaysAgo(back(365), day)).toBe(fmtDate(back(365), false, true))+ expect(fmtDaysAgo('2024-03-02', day)).toMatch(/2024/)+ })++ it('counts calendar days across a DST change, not 24-hour blocks', () => {+ // Europe: clocks go forward on 2026-03-29 and back on 2026-10-25.+ expect(fmtDaysAgo('2026-03-28', '2026-03-30')).toBe('2 days ago')+ expect(fmtDaysAgo('2026-10-24', '2026-10-26')).toBe('2 days ago')+ expect(fmtDaysAgo('2026-03-29', '2026-03-30')).toBe('yesterday')+ })++ it('counts from the given day, so a workout logged into the past reads correctly', () => {+ expect(fmtDaysAgo('2026-09-01', '2026-09-04')).toBe('3 days ago')+ })++ it('a day after the reference day (a clock set back) reads as today', () => {+ expect(fmtDaysAgo('2026-10-06', day)).toBe('today')+ })++ it('in the UI language, from the platform', () => {+ _setLangState('de', {}, null, null)+ expect(fmtDaysAgo(back(1), day)).toBe('gestern')+ expect(fmtDaysAgo(back(3), day)).toBe('vor 3 Tagen')+ expect(fmtDaysAgo(back(14), day)).toBe('vor 2 Wochen')+ })+})diff --git a/frontend/src/lib/format.js b/frontend/src/lib/format.jsindex 31a7f7c5d..3ea394b82 100644--- a/frontend/src/lib/format.js+++ b/frontend/src/lib/format.js@@ -82,6 +82,24 @@ export function fmtAgo(ts, now = Date.now()) {catch { return new Date(ts).toLocaleString(dateLocale()) }}+// How long before `dayIso` a logged day was, in calendar days (#363): "yesterday", "3 days ago",+// "2 weeks ago", "last month". For the "Last time (…)" line of a workout, so `dayIso` is the+// session's own day, not the wall clock: a workout logged into the past counts back from its+// day. Whole calendar days at noon, so a DST weekend between the two is not a day short.+// The words come from Intl.RelativeTimeFormat, so no pack carries them; it has no compound form+// ("1 week 1 day ago"), which is why a span rounds down to its coarsest unit. A year or more+// back reads as the date with its year, which says more than "1 year ago". A day after `dayIso`+// (a clock set back) reads as today.+export function fmtDaysAgo(iso, dayIso = todayISO()) {+ const at = s => Date.UTC(+s.slice(0, 4), +s.slice(5, 7) - 1, +s.slice(8, 10))+ const days = Math.max(0, Math.round((at(dayIso) - at(iso)) / 86400000))+ if (!(days >= 0)) return fmtDate(iso)+ if (days >= 365) return fmtDate(iso, false, true)+ const [n, unit] = days < 7 ? [days, 'day'] : days < 35 ? [Math.floor(days / 7), 'week'] : [Math.max(1, Math.floor(days / 30.44)), 'month']+ try { return new Intl.RelativeTimeFormat(dateLocale(), { numeric: 'auto' }).format(-n, unit) }+ catch { return fmtDate(iso) }+}+/* ---------------------------------------------------------------- week start --Where a week begins is a local convention, not a fact: most of Europe starts onMonday, most of the Americas and much of Asia on Sunday. The app used to assumediff --git a/frontend/src/views/Workout.jsx b/frontend/src/views/Workout.jsxindex 39340a4ed..2e6084635 100644--- a/frontend/src/views/Workout.jsx+++ b/frontend/src/views/Workout.jsx@@ -8,7 +8,7 @@ import { exOr, betterWeight } from '../lib/exercises.js'import { usesBar } from '../lib/bar.js'import { loadKindFor, baseWeightFor, inventoryFor, rowLoad, sameLoad, plateDelta, dropGrid } from '../lib/plates.js'import { effectiveRoutines, effectiveRoutineIds, lastEntryFor, bestWeightFor, bestWeightForEntry, buildSets, freestyleConfig, defaultConfig, setsDoneActive, setUnitsTotal, supersetUnits, unitOf, setLabel, modeOf, isBw, isPerSide, repStep, EFFORT, effortOf, stepEffort, capEffort, cascadeWeight, insertWarmupRow, removeRowAt, pairAdjacent, unpairSuperset, cleanupSg, applyIntensifierPlan, pinnedNoteFor, exNoteFor, setsRepsOf } from '../lib/history.js'-import { fmtNum, fmtPlate, exerciseNameText, fmtDate, todayISO, exCount, DAYN } from '../lib/format.js'+import { fmtNum, fmtPlate, exerciseNameText, fmtDate, fmtDaysAgo, todayISO, exCount, DAYN } from '../lib/format.js'import { speedUnitOf, toSpeed, fromSpeed } from '../lib/speed.js'import { beep, vibrate, unlock } from '../lib/sound.js'import { t, exerciseNameFor, exerciseNameClass } from '../lib/i18n.js'@@ -207,9 +207,13 @@ function ExerciseBlock({ entryIdx, compact, dense, editing, onToggle, onToggleSi// An exercise logged before only in another mode (reps then, a hold today) has a last time but// no best set to hold today's rows against. The line stays and says so: gone, it took the// switch back to "Last time" with it, reachable then only from Settings or another card.- const refHead = ref ? `${refBest ? t('Best set') : t('Last time')} (${fmtDate(ref.d)}): ` : ''+ // How long ago reads at a glance (#363): "3 days ago", counted from the session's own day, so a+ // workout logged into the past is not told its last time was "today". The date itself stays+ // in the hover title and in what a screen reader hears.+ const refLabel = refBest ? t('Best set') : t('Last time')+ const refAgo = ref ? fmtDaysAgo(ref.d, S.active.d || todayISO()) : ''const refSets = ref ? (refBest ? [ref.set] : ref.sets).map(s => setLabel(entry.id, s, ref.target, speedUnitOf(S))) : []- const refText = ref ? refHead + refSets.join(', ') : refBest && last ? t('Best set: nothing logged this way yet') : null+ const refText = ref ? `${refLabel} (${refAgo}, ${fmtDate(ref.d, true, true)}): ` + refSets.join(', ') : refBest && last ? t('Best set: nothing logged this way yet') : nullconst refAction = refBest ? t('Show last time instead') : t('Show your best set instead')// The button's text is the reference, which says nothing about what a tap does; its name// carries both, the reference first as it reads on screen, then the switch.@@ -219,7 +223,7 @@ function ExerciseBlock({ entryIdx, compact, dense, editing, onToggle, onToggleSi{/* Each set on its own left-to-right island. In Arabic the first one followed the label'sdirection and read 8×60, while those after a Latin "RIR" read 60×8. A set that carrieswords of a right-to-left script keeps its own direction, still isolated (RTL_LETTER). */}- <span>{ref ? <>{refHead}{refSets.map((l, i) => <Fragment key={i}>{i ? ', ' : ''}<bdi dir={RTL_LETTER.test(l) ? 'auto' : 'ltr'}>{l}</bdi></Fragment>)}</> : refText}</span>+ <span>{ref ? <>{refLabel} (<time dateTime={ref.d} title={fmtDate(ref.d, true, true)}>{refAgo}</time>): {refSets.map((l, i) => <Fragment key={i}>{i ? ', ' : ''}<bdi dir={RTL_LETTER.test(l) ? 'auto' : 'ltr'}>{l}</bdi></Fragment>)}</> : refText}</span><Icon name="shuffle" /></button> : null// A bodyweight set has no weight to type, so the column is not there (issue #32) — onediff --git a/frontend/src/views/Workout.test.jsx b/frontend/src/views/Workout.test.jsxindex f9413ea94..160aaafd1 100644--- a/frontend/src/views/Workout.test.jsx+++ b/frontend/src/views/Workout.test.jsx@@ -1951,6 +1951,20 @@ describe('the reference line: last time or best set', () => {expect(mocks.S.logRef).toBe('last')})+ // #363: how long ago, counted from the session's own day; the date stays in the title and name.+ it('says how long ago, counted from the day the session is logged on', async () => {+ await mount([exercise('plain-bench', [false], { rid: 'A' })], 0, { workouts: history, active: { d: '2026-08-29' } })+ expect(line().textContent).toBe('Last time (3 days ago): 55×8')+ const time = line().querySelector('time')+ expect(time.outerHTML).toMatch(/datetime="2026-08-26"/i)+ expect(time.getAttribute('title')).toMatch(/2026/)+ expect(line().getAttribute('aria-label')).toMatch(/^Last time \(3 days ago, .+2026\): 55×8\. Show your best set instead$/)+ await unmount()+ // back-filled into the past: last time is counted from that day, not from today+ await mount([exercise('plain-bench', [false], { rid: 'A' })], 0, { workouts: history.slice(0, 2), active: { d: '2026-08-25' } })+ expect(line().textContent).toBe('Last time (yesterday): 60×10')+ })+it('is not there before the exercise was ever logged', async () => {await mount([exercise('plain-bench', [false])], 0, { logRef: 'best' })expect(line()).toBeNull()