Skip to content

fix: Total Hours showing NaN on new work log form - #395

Closed
thinkclay wants to merge 1 commit into
mainfrom
worktree-fix-worklog-nan
Closed

thinkclay wants to merge 1 commit into
mainfrom
worktree-fix-worklog-nan

Conversation

@thinkclay

Copy link
Copy Markdown
Contributor

Fixes #380.

Root cause

calculateTotalHours in useWorkLogForm.ts split each time entry on ":" and guarded against Number.isNaN on the resulting hour/minute values. But an empty or partial time string (e.g. "") produces a one-element array from .split(":"), leaving the minute undefined rather than NaN. Number.isNaN(undefined) is false, so the guard let it through, and undefined arithmetic downstream turned the total into NaN.

Fix

  • Switched the guard from Number.isNaN to Number.isFinite, which correctly rejects both NaN and undefined.
  • Gave the default time entry actual values (08:00–16:30) instead of empty strings, so a fresh form immediately shows "Total Hours: 8.5" as the issue's acceptance criteria expects, rather than relying on placeholder text that was never written to form state.
  • Moved calculateTotalHours into its own utils/time-entries.ts module so it can be unit tested directly, without pulling in useWorkLogForm's full dependency graph (react-query hooks, offline sync, etc).

Testing

  • Added packages/scf-core/features/work-logs/utils/__tests__/time-entries.test.ts (5 cases: default entry, multiple entries, empty strings, partial strings, invalid end-before-start) — all pass.
  • pnpm exec biome lint clean on changed files.
  • tsc --noEmit shows no new errors introduced by this change (pre-existing errors in this sandbox are all from the @scaffald/ui/@scaffald/sdk git submodules not being checked out — an environment limitation, not something from this diff).

Note: I wasn't able to run the full pnpm prepush (nx affected -t build) in this sandbox because the packages/ui and packages/sdk git submodules aren't initialized here (no access to Scaffald/ui/Scaffald/sdk), which breaks the Nx project graph repo-wide regardless of this change. Verified correctness via targeted unit tests, typecheck, and lint instead.

🤖 Opened by the Friday weekly-improvement routine.


Generated by Claude Code

calculateTotalHours split each time on ":" and checked Number.isNaN
on the resulting hour/minute pair, but an empty or partial time
string (e.g. "") produces a one-element array, leaving the minute
undefined rather than NaN. Number.isNaN(undefined) is false, so the
guard let it through and undefined arithmetic turned the total into
NaN. Switch the guard to Number.isFinite, which catches both NaN and
undefined.

Also give the default time entry actual values (08:00-16:30) instead
of empty strings, so a fresh form shows "Total Hours: 8.5" as
expected instead of relying on placeholder text that was never
written to the form state.

Moved calculateTotalHours into its own utils module so it can be
unit tested without pulling in useWorkLogForm's full dependency
graph (react-query hooks, offline sync, etc).

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@github-actions

Copy link
Copy Markdown
Contributor

Test Results

0 tests   0 ✅  0s ⏱️
0 suites  0 💤
0 files    0 ❌

Results for commit 5694671.

@thinkclay

Copy link
Copy Markdown
Contributor Author

Superseded by #403, which landed the same #380 fix (strict HH:MM parsing in calculateTotalHours + pre-filled 08:00–16:30 default, with unit tests) and has been merged to main. Closing to avoid a conflicting duplicate — thanks!

@thinkclay thinkclay closed this Jul 22, 2026
@thinkclay
thinkclay deleted the worktree-fix-worklog-nan branch July 22, 2026 05:03
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.

Work log form: "Total Hours: NaN" with the default time entry

2 participants