From 881fe4b2dcecef61e22406fbcf1f3f03c83b7e9f Mon Sep 17 00:00:00 2001 From: andi242 Date: Tue, 25 Aug 2026 12:31:50 +0200 Subject: [PATCH 1/2] add date format parse and tests parse and test YYYY/MM/DD format add some different date formats to testing --- frontend/src/lib/import-csv.js | 4 ++-- frontend/src/lib/import-csv.test.js | 10 +++++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/frontend/src/lib/import-csv.js b/frontend/src/lib/import-csv.js index 73a9bd2..7649507 100644 --- a/frontend/src/lib/import-csv.js +++ b/frontend/src/lib/import-csv.js @@ -258,10 +258,10 @@ const LB_TO_KG = 0.45359237 const p2 = n => String(n).padStart(2, '0') const MON = { jan: 1, feb: 2, mar: 3, apr: 4, may: 5, jun: 6, jul: 7, aug: 8, sep: 9, oct: 10, nov: 11, dec: 12 } -/** "2020-12-30 18:51:52" · "2024-03-07" · "22 Dec 2025, 08:00" · "07/03/2024" -> { d, t } */ +/** "2020-12-30 18:51:52" · "2024-03-07" · "2024/03/07" · "2024.03.07" · "22 Dec 2025, 08:00" · "07/03/2024" -> { d, t } */ export function parseWhen(s) { const v = String(s || '').trim() - let m = v.match(/^(\d{4})-(\d{1,2})-(\d{1,2})(?:[T ](\d{1,2}):(\d{2}))?/) + let m = v.match(/^(\d{4})[-/.](\d{1,2})[-/.](\d{1,2})(?:[T ](\d{1,2}):(\d{2}))?/) if (m) return { d: `${m[1]}-${p2(m[2])}-${p2(m[3])}`, t: hm(m[4], m[5]) } m = v.match(/^(\d{1,2})\s+([A-Za-z]{3})[a-z]*\.?\s+(\d{4})(?:,?\s+(\d{1,2}):(\d{2}))?/) if (m && MON[m[2].toLowerCase()]) return { d: `${m[3]}-${p2(MON[m[2].toLowerCase()])}-${p2(m[1])}`, t: hm(m[4], m[5]) } diff --git a/frontend/src/lib/import-csv.test.js b/frontend/src/lib/import-csv.test.js index 4a8b164..346c715 100644 --- a/frontend/src/lib/import-csv.test.js +++ b/frontend/src/lib/import-csv.test.js @@ -4,7 +4,9 @@ import { parseWorkoutCSV } from './import-csv.js' const CSV = [ 'Date,Exercise,Weight,Reps,Set Type', '2026-08-08,Bench Press,100,5,Warm-up', - '2026-08-08,Bench Press,80,5,Working', + '2026.08.08,Bench Press,80,5,Working', + '8 Aug 2026,Bench Press,80,5,Working', + '2026/08/08,Bench Press,85,3,Working', ].join('\n') describe('CSV warm-up provenance', () => { @@ -16,7 +18,9 @@ describe('CSV warm-up provenance', () => { expect(entry.sets).toEqual([ { w: 100, r: 5, done: true, phase: 'warmup' }, { w: 80, r: 5, done: true }, + { w: 80, r: 5, done: true }, + { w: 85, r: 3, done: true }, ]) - expect(entry.topW).toBe(80) + expect(entry.topW).toBe(85) }) -}) \ No newline at end of file +}) From 9c4bc16967ff791704dad5c103d2ac4df9617d39 Mon Sep 17 00:00:00 2001 From: andi242 Date: Tue, 25 Aug 2026 13:21:44 +0200 Subject: [PATCH 2/2] add fields for gravl csv import --- frontend/src/lib/import-csv.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/frontend/src/lib/import-csv.js b/frontend/src/lib/import-csv.js index 7649507..a3a049c 100644 --- a/frontend/src/lib/import-csv.js +++ b/frontend/src/lib/import-csv.js @@ -58,12 +58,12 @@ const norm = h => h.toLowerCase().replace(/[^a-z0-9]+/g, ' ').trim() const COLUMNS = [ ['exercise', ['exercise', 'exercise name', 'exercise title']], ['date', ['date', 'workout date']], - ['startTime', ['start time']], + ['startTime', ['start time', 'start date']], ['endTime', ['end time']], - ['workoutName', ['workout name', 'title']], + ['workoutName', ['workout name', 'title', 'workout']], ['category', ['category', 'body part', 'muscle group']], - ['weightKg', ['weight kg']], - ['weightLb', ['weight lbs', 'weight lb']], + ['weightKg', ['weight kg', 'weight (kg)']], + ['weightLb', ['weight lbs', 'weight lb', 'weight (lb)']], ['weight', ['weight']], ['weightUnit', ['weight unit', 'unit']], ['reps', ['reps', 'repetitions']], @@ -71,13 +71,13 @@ const COLUMNS = [ // when it is there rather than dropping the column on the floor. ['rpe', ['rpe', 'rpe rating']], ['rir', ['rir', 'reps in reserve']], - ['distanceKm', ['distance km']], + ['distanceKm', ['distance km', 'distance (km)']], ['distance', ['distance']], ['distanceUnit', ['distance unit']], ['seconds', ['seconds', 'duration seconds']], - ['time', ['time', 'duration']], + ['time', ['time', 'duration', 'set duration (sec)']], ['setType', ['set type']], - ['note', ['comment', 'comments', 'notes', 'note']], + ['note', ['comment', 'comments', 'notes', 'note', 'workout notes']], ] function mapHeader(header) {