add date format parse and tests

parse and test YYYY/MM/DD format
add some different date formats to testing
This commit is contained in:
andi242 committed 2026-08-25 12:31:50 +02:00
1 parent cc036406dc
commit 881fe4b2dc
2 files changed
+9 -5

No files matched your search

+2 -2
View File
@@ -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]) }
+7 -3
View File
@@ -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)
})
})
})