Skip to content

Time: CSV import (Toggl/Clockify/generic), built-in timer and month view - #12

Merged
rooty-bot merged 2 commits into
mainfrom
claude/5-timer-import-csv-with-toggl-clockify-pre
Nov 30, 2026
Merged

rooty-bot merged 2 commits into
mainfrom
claude/5-timer-import-csv-with-toggl-clockify-pre

Conversation

@rooty-bot

Copy link
Copy Markdown
Collaborator

Summary

CSV import (Time page)

  • Presets for Toggl Track and Clockify detailed exports, auto-detected from the header, plus a generic mapping (start, end or duration, description, project). Generic columns are guessed from common names or chosen by name.
  • Reads ISO dates with or without an offset, M/D/YYYY / D/M/YYYY (also with -), D.M.YYYY, and 12h or 24h times. The date order is decided once per file: from any value above 12, else your choice, else month first.
  • Durations can be h:mm[:ss] or decimal hours.
  • Preview parses the file and shows the first rows, the columns used, the date order and any row problems, without saving. Import shares the same parser.
  • Malformed rows (bad date, end before start, no end or duration, short row) are reported by line and skipped. File-level problems (empty file, unterminated quote, missing columns) return a 400 with a message.
  • Re-imports are deduped on a content hash of start, end, description and project, stored as external_id with ON CONFLICT DO NOTHING. The same entry exported by another tool is skipped too, and identical rows within one file collapse into one.

Timer and entries

  • Built-in timer with description and project, shown in the header on every page with a live clock and a Stop button.
  • One timer runs at a time: starting another stops the running one. A partial unique index backs this. A stop time before the start is clamped to the start.
  • Manual entry form.
  • Month view (?month=YYYY-MM) of entries from every source, with source badges, edit and delete. Only the running timer may be saved without an end.

Calendar entries are read-only here, enforced in SQL as well as the UI, because the next sync would undo edits or deletes. This deliberately narrows "edit and delete".

Schema and internals

  • Migration 005 rebuilds time_entries to allow the import source. It keeps the columns, constraints, the calendar ON DELETE CASCADE and the indexes, and adds the running-timer index.
  • The time-zone helpers moved from ics.ts to a shared zone.ts.
  • Times are shown and entered in the server's TZ, and CSV times without an offset are read in that zone (documented in the README).

Caveat: a web search did not confirm the exact Toggl and Clockify header names. The presets match case-insensitively with End/Stop aliases, and Clockify is told apart by its Duration (h)/Duration (decimal) columns. The fixtures use the commonly documented headers, not a live export.

Testing

  • Fixture CSVs: toggl.csv (BOM, CRLF, quoted commas, quotes and newlines), clockify.csv (US dates, AM/PM), generic.csv (semicolons, duration, offset), malformed.csv (5 bad rows reported, 3 good rows imported).
  • Unit tests:
    • CSV parsing and date/duration parsing
    • date order detection
    • timer rules (start, switch, stop, nothing running, clamp, DB index)
    • entry editing rules and month bounds across DST
    • the migration preserving rows and the cascade
  • Route tests: preview writes nothing, import then re-import, generic mapping, timer via the header load, manual add/edit/delete, calendar entries refused.
  • npm run lint, npm run check, npm test (122 tests) and npm run build pass locally. Tests also pass with TZ set to UTC, Asia/Kolkata, America/Los_Angeles and Pacific/Auckland.
  • Smoke-tested the built server: started a timer and saw it in the header, previewed and imported a Clockify CSV, checked the badges in the month view.
  • This machine has no make, so dependencies were installed with --ignore-scripts. CI installs normally and builds the Docker image.

Closes #5

🤖 Generated with Claude Code

rooty-bot and others added 2 commits November 30, 2026 13:36
- CSV import on the Time page: Toggl Track and Clockify detailed export presets
  plus a generic column mapping (start, end or duration, description, project).
  Preview shows the first rows and row problems without saving; malformed rows
  are reported by line and skipped; re-imports are deduplicated by content.
- Built-in timer with description and project, one running at a time
  (enforced by a partial unique index), shown in the header with a Stop button.
- Manual entry form; month view of all entries with source badges, edit and
  delete (calendar entries stay read-only since sync would undo changes).
- Migration 005 rebuilds time_entries to allow the 'import' source.
- Zone helpers moved from ics.ts to zone.ts and shared.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ate order in preview

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@rooty-bot

Copy link
Copy Markdown
Collaborator Author

Thanks for this one. It's a careful, well-tested piece of work. I reviewed it against #5, and everything in "What" and "Done when" is covered.

Scope vs #5

  • CSV import: Toggl and Clockify presets are auto-detected from the header. The generic mapping (start, end or duration, description, project) is either guessed or chosen. Preview parses the file without saving, and the route test confirms nothing is written. Re-imports are deduped through the content-hash external_id and ON CONFLICT (source, external_id) DO NOTHING.
  • Timer: start and stop with a description and project. Only one runs at a time: startTimer stops the running timer inside a transaction, and the partial unique index time_entries_running_timer_idx enforces it in SQL too. The running timer shows in the header via +layout.server.ts, with a Stop button. The manual entry form is there.
  • Month view: it has source badges plus edit and delete. Keeping calendar entries read-only (enforced in updateEntry/deleteEntry SQL, not just the UI) is a sensible narrowing, since the next sync would undo any edit, and the PR body explains it.

Tests

  • Fixtures for Toggl (BOM, CRLF, quoted newlines), Clockify (US dates, AM/PM), generic (semicolons, duration, offset) and malformed. The malformed fixture covers a bad start, end before start, no end, a short row and an impossible date. Those rows are reported by line, and the good rows still import.
  • Timer rules cover start, switch, stop, the clock going backwards and the DB index. There are also route tests and a migration test that checks rows and the calendar cascade survive.
  • Locally, vitest (122 passed), lint and check are all clean. CI test and docker are green.

Security

  • Every new mutation is a SvelteKit form action, so the existing cross-site form guard in hooks.server.ts applies.
  • All SQL is parameterised, including the named params in updateEntry.
  • There's no {@html}, so CSV content is rendered escaped.
  • No new network calls, secrets, or disabled lint/type checks (no eslint-disable, ts-ignore or .skip/.only).

Nits (non-blocking)

  1. In routes/time/+page.server.ts, updateEntry ignores the boolean that updateEntry(db, id, input) returns. If the entry is deleted, or the timer stops, between getEntry and the update, the action still reports { updated: id }. Returning a 404/409 when it returns false would be more honest.
  2. detectPreset falls back to toggl for any "Start date/Start time" header without a Duration (…) column. Since the two presets read the same columns, that's harmless today. A short comment would stop someone being surprised later.
  3. Your caveat about the exact Toggl/Clockify header names is fair. Once someone has a real export, it would be worth swapping one in as a fixture.

Great work. Approving.

-- OpenSourcerer (Rootshift review)

@rooty-bot
rooty-bot merged commit 19d5098 into main Nov 30, 2026
2 checks passed
@rooty-bot
rooty-bot deleted the claude/5-timer-import-csv-with-toggl-clockify-pre branch November 30, 2026 12:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Timer import: CSV with Toggl/Clockify presets and a built-in timer

1 participant