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: a session past midnight keeps its length

Duarte Santosfe5d40dc240d
diff --git a/frontend/src/lib/import-csv.js b/frontend/src/lib/import-csv.js
index 08955988e..bebab92af 100644
--- a/frontend/src/lib/import-csv.js
+++ b/frontend/src/lib/import-csv.js
@@ -396,6 +396,11 @@ export function parseWhen(s) {
}
return null
}
+/** Whole calendar days from one "YYYY-MM-DD" to another (0 when either is unreadable). */
+export const daysBetween = (a, b) => {
+ const n = (Date.UTC(+b.slice(0, 4), +b.slice(5, 7) - 1, +b.slice(8, 10)) - Date.UTC(+a.slice(0, 4), +a.slice(5, 7) - 1, +a.slice(8, 10))) / 86400000
+ return isFinite(n) && n > 0 && n < 2 ? n : 0
+}
const hm = (h, mi) => (h === undefined ? null : (parseInt(h, 10) || 0) * 3600000 + (parseInt(mi, 10) || 0) * 60000)
/** "HH:MM:SS" · "MM:SS" · "90" -> minutes */
@@ -541,7 +546,9 @@ export function parseWorkoutCSV(text, { unit = 'kg' } = {}) {
}
if (!day.name) day.name = cell(r, 'workoutName') || ''
if (!day.note) day.note = cell(r, 'workoutNote')
- if (map.endTime !== undefined) { const e = parseWhen(cell(r, 'endTime')); if (e && e.t != null) day.end = e.t }
+ // The end is kept as time since the start day's midnight, so a session that runs past
+ // midnight ends on the next day's clock plus 24 h rather than before it began.
+ if (map.endTime !== undefined) { const e = parseWhen(cell(r, 'endTime')); if (e && e.t != null) day.end = e.t + daysBetween(when.d, e.d) * 86400000 }
else if ((map.workoutDuration !== undefined || map.workoutDurationSec !== undefined) && day.end == null) {
const len = map.workoutDurationSec !== undefined
? num(cell(r, 'workoutDurationSec')) / 60
diff --git a/frontend/src/lib/import-csv.test.js b/frontend/src/lib/import-csv.test.js
index 5402d0ae5..f13d4600c 100644
--- a/frontend/src/lib/import-csv.test.js
+++ b/frontend/src/lib/import-csv.test.js
@@ -214,3 +214,15 @@ describe('Strong semicolon export', () => {
expect(legs.entries[0].sets[0]).toMatchObject({ min: 25, speed: 12 })
})
})
+
+describe('session past midnight', () => {
+ it('Hevy CSV: 23:30 to 00:20 the next day is 50 minutes on the start day', () => {
+ const csv = [
+ '"title","start_time","end_time","description","exercise_title","superset_id","exercise_notes","set_index","set_type","weight_kg","reps","distance_km","duration_seconds","rpe"',
+ '"Run","6 Sep 2026, 23:30","7 Sep 2026, 00:20","","Running",,"",0,"normal",,,8.2,2900,',
+ ].join('\n')
+ const [w] = parseWorkoutCSV(csv, { unit: 'kg' }).workouts
+ expect(w.d).toBe('2026-09-06')
+ expect((w.end - w.start) / 60000).toBe(50)
+ })
+})
diff --git a/frontend/src/lib/import-hevy.js b/frontend/src/lib/import-hevy.js
index 899e981c1..eb0879e98 100644
--- a/frontend/src/lib/import-hevy.js
+++ b/frontend/src/lib/import-hevy.js
@@ -9,6 +9,7 @@ import { EXIDX } from './exercises.js'
import { uid } from './format.js'
import { isWarmupRow } from './workout-model.js'
import { HEVY_ID_MAP, HEVY_TITLE_MAP } from './hevy-id-map.js'
+import { daysBetween } from './import-csv.js'
export { HEVY_ID_MAP, HEVY_TITLE_MAP }
export const HEVY_API = 'https://api.hevyapp.com'
@@ -230,7 +231,8 @@ export function parseHevyWorkouts(workouts, templates, { unit = 'kg' } = {}) {
day = { ex: new Map(), name: title, start: start.t, end: end?.t ?? null }
byDate.set(start.d, day)
} else if (!day.name && title) day.name = title
- if (end?.t != null) day.end = end.t
+ // Past midnight the end's clock restarts; count it from the start day's midnight instead.
+ if (end?.t != null) day.end = end.t + daysBetween(start.d, end.d) * 86400000
for (const ex of w.exercises || []) {
const id = R.resolve(ex.exercise_template_id, ex.title)
diff --git a/frontend/src/lib/import-hevy.test.js b/frontend/src/lib/import-hevy.test.js
index b395ea782..50f245a2b 100644
--- a/frontend/src/lib/import-hevy.test.js
+++ b/frontend/src/lib/import-hevy.test.js
@@ -303,3 +303,13 @@ describe('buildHevyExerciseMap', () => {
expect(map.size).toBe(TEMPLATES.length)
})
})
+
+describe('parseHevyWorkouts past midnight', () => {
+ it('a session ending after midnight keeps its length', () => {
+ // Local-time ISO strings, so the test reads the same in every time zone.
+ const late = { ...WORKOUT, start_time: '2026-09-06T23:30:00', end_time: '2026-09-07T00:20:00' }
+ const [w] = parseHevyWorkouts([late], TEMPLATES, { unit: 'kg' }).workouts
+ expect(w.d).toBe('2026-09-06')
+ expect((w.end - w.start) / 60000).toBe(50)
+ })
+})