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.

Import summary: the date range shows the year when it spans years or is not this year

Duarte Santos35a7de44d544
diff --git a/frontend/src/lib/format.js b/frontend/src/lib/format.js
index 3be41b9c5..0540d9bbc 100644
--- a/frontend/src/lib/format.js
+++ b/frontend/src/lib/format.js
@@ -18,6 +18,15 @@ export function fmtDate(iso, long, withYear = false) {
if (withYear) options.year = 'numeric'
return d.toLocaleDateString(dateLocale(), options)
}
+// A span of days, e.g. an import's first and last workout. The year is shown when the span
+// crosses one or lies outside the current year: "3 Feb – 21 Dec" over two years read as one.
+export function fmtDateRange(from, to, long, now = new Date()) {
+ if (!from) return ''
+ const last = to || from
+ const year = String(now.getFullYear())
+ const withYear = from.slice(0, 4) !== last.slice(0, 4) || from.slice(0, 4) !== year
+ return from === last ? fmtDate(from, long, withYear) : fmtDate(from, long, withYear) + ' – ' + fmtDate(last, long, withYear)
+}
// In the UI language: the Latin h, m and min stood inside Arabic and Ukrainian rows.
export function fmtDur(ms) {
const m = Math.floor(ms / 60000)
diff --git a/frontend/src/sheets.import-summary.test.jsx b/frontend/src/sheets.import-summary.test.jsx
new file mode 100644
index 000000000..3bc193c13
--- /dev/null
+++ b/frontend/src/sheets.import-summary.test.jsx
@@ -0,0 +1,49 @@
+// @vitest-environment happy-dom
+import React, { act } from 'react'
+import { createRoot } from 'react-dom/client'
+import { afterEach, beforeEach, describe, expect, it } from 'vitest'
+import { useStore } from './store/useStore.js'
+import { useUI } from './store/useUI.js'
+import { importFromApp } from './sheets.jsx'
+import { fmtDateRange } from './lib/format.js'
+
+// The import summary's date range said "Sun, 3 Feb – Sun, 21 Dec" for a history that ran over
+// two years: without the year, a span across a new year read as a few months.
+const HEAD = 'Date,Exercise,Weight,Reps'
+const csv = (...days) => [HEAD, ...days.map(d => `${d},Bench Press,60,5`)].join('\n')
+let root, host
+
+async function summaryFor(text) {
+ const file = new File([text], 'export.csv', { type: 'text/csv' })
+ importFromApp(file)
+ for (let i = 0; i < 50 && !useUI.getState().sheets.length; i++) await new Promise(r => setTimeout(r, 5))
+ const sheet = useUI.getState().sheets.at(-1)
+ expect(sheet).toBeTruthy()
+ host = document.createElement('div')
+ document.body.appendChild(host)
+ root = createRoot(host)
+ act(() => root.render(sheet.render(() => {})))
+ return host.querySelector('.muted.small').textContent
+}
+
+describe('the import summary’s dates', () => {
+ beforeEach(() => {
+ globalThis.IS_REACT_ACT_ENVIRONMENT = true
+ useUI.setState({ sheets: [], toasts: [] })
+ useStore.setState(s => ({ S: { ...s.S, unit: 'kg', workouts: [], bodyweight: [] } }))
+ })
+ afterEach(() => { if (root) act(() => root.unmount()); root = null; document.body.innerHTML = '' })
+
+ it('carry the year when the history spans two years', async () => {
+ const text = await summaryFor(csv('2025-02-03', '2026-12-21'))
+ expect(text).toContain('2025')
+ expect(text).toContain('2026')
+ })
+
+ it('carry the year for a range that is not this year', () => {
+ const now = new Date('2026-09-28T12:00:00')
+ expect(fmtDateRange('2024-03-01', '2024-05-01', false, now)).toContain('2024')
+ expect(fmtDateRange('2026-03-01', '2026-05-01', false, now)).not.toContain('2026')
+ expect(fmtDateRange('2026-03-01', '2026-03-01', false, now)).not.toContain('–')
+ })
+})
diff --git a/frontend/src/sheets.jsx b/frontend/src/sheets.jsx
index 355020a87..fc2018c38 100644
--- a/frontend/src/sheets.jsx
+++ b/frontend/src/sheets.jsx
@@ -3,7 +3,7 @@ import { useStore } from './store/useStore.js'
import { useUI } from './store/useUI.js'
import { EXDB, EXIDX, BODYPARTS, isCardio, isBodyweightEq, allExercises, equipmentOf, smOf, searchExercises, exOr, isAssisted, betterWeight, beatsWeight } from './lib/exercises.js'
import { activeProfile, exAvailable, ALL_EQUIPMENT, newProfile } from './lib/equipment.js'
-import { fmtDate, fmtNum, fmtPlate, exerciseNameText, fmtVol, fmtDur, durPart, todayISO, isoOf, uid, exCount, routineCount, setsWorkCount, DAYN, DAYS, weekOrder, weekStartOf, weekDayOffset, MONTHS_LONG, ACCENTS } from './lib/format.js'
+import { fmtDate, fmtDateRange, fmtNum, fmtPlate, exerciseNameText, fmtVol, fmtDur, durPart, todayISO, isoOf, uid, exCount, routineCount, setsWorkCount, DAYN, DAYS, weekOrder, weekStartOf, weekDayOffset, MONTHS_LONG, ACCENTS } from './lib/format.js'
import { lastEntryFor, bestWeightFor, bestWeightForEntry, buildSets, effectiveRoutineIds, workoutDay, workoutVolume, setsDone, setsDoneActive, setUnitsTotal, lastBW, supersetUnits, sessionSections, unitOf, setLabel, defaultConfig, cleanupSg, modeOf, effortOf, EFFORT, capEffort, stepEffort, isBw, isPerSide, sideReps, workSetsDone, applyIntensifierPlan, MAX_PLANNED_WARMUPS, NOTE_MAX } from './lib/history.js'
import { usesBar, defaultBarWeight, hasBarOverride, isNoBar } from './lib/bar.js'
import { PLATE_SIZES, pairsOf, ownsPlates, withPlatePairs, withStandardPlates, withLoadKind, loadKindFor, baseWeightFor } from './lib/plates.js'
@@ -352,7 +352,7 @@ function ImportSummary({ parsed, close }) {
return <>
<h3>{parsed.source ? t('Import from {0}', parsed.source) : t('Import history')}</h3>
<div className="muted small" style={{ marginBottom: 12 }}>
- {parsed.from === parsed.to ? fmtDate(parsed.from, true) : fmtDate(parsed.from, true) + ' – ' + fmtDate(parsed.to, true)}
+ {fmtDateRange(parsed.from, parsed.to, true)}
</div>
<div className="tiles" style={{ textAlign: 'start' }}>