Repository navigation
fix: prevent negative task durations and day end times - #277
Merged
Merged
Conversation
endDay rounded the end time to 15 minutes while a running task's start was unrounded, so the rounded end could precede the task start. Clamp endDay to the latest recorded moment, route all duration subtraction through a zero-floored elapsedMs helper, and ignore legacy negative values in calculations and formatters. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UqjLGeuTJHemDQZo6PbAja
ArchivedTaskRow, the ArchiveEditDialog Add Task form, and the day summary form now flag an end before the start inline and block saving. Adds isEndBeforeStart/END_BEFORE_START_MESSAGE, documents the invariant in AGENTS.md, pitfalls, README, README-EXT, and CHANGELOG. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UqjLGeuTJHemDQZo6PbAja
Deploying timetrackerpro with
|
| Latest commit: |
52f5495
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://6b814965.timetrackerpro.pages.dev |
| Branch Preview URL: | https://fix-negative-durations.timetrackerpro.pages.dev |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Task durations and a day's end time could go negative.
endDayrounds the end time to the nearest 15 minutes while a running task's start is unrounded, so ending a day shortly after starting a task (task started 9:20, day ended 9:21, end rounded to 9:15) produced a negative duration and an end time before the task began. This PR removes that path and the other places that subtract timestamps without a floor, and rejects end-before-start entries in the archive editors.Type of Change
Related Issue
No linked issue.
Changes Made
src/utils/timeUtil.ts: new zero-flooredelapsedMs, plusisEndBeforeStartandEND_BEFORE_START_MESSAGE.formatDurationandformatDurationLongshow negatives as zero.src/contexts/TimeTrackingContext.tsx:endDaynever ends earlier than the day start, the running task's start, or the latest recorded task end.beginTask,adjustTaskTime, and the planned-task completion path useelapsedMs.adjustTaskTimecollapses an end-before-start edit to a zero-length task.src/utils/calculationUtils.ts,src/utils/reportUtils.ts: ignore or zero negative values already in storage (task, day, period, hours, revenue, report formatting).src/components/ArchivedTaskRow.tsx,src/components/ArchiveEditDialog.tsx: an end before the start is flagged inline (role="alert",aria-invalid,aria-describedby), and Save/Add Task stays disabled until corrected. The day form rejects it through its zod schema, and Save Changes reopens a collapsed summary editor so the error is visible. Equal start and end times stay allowed, since 15-minute rounding can collapse a short task to zero length.src/components/ui/scroll-time-picker.tsx:TimePickeracceptsaria-invalid.TimeTracking.test.tsx,calculationUtils.test.ts,timeUtil.test.ts,ArchivedTaskRow.test.tsx, andArchiveEditDialog.test.tsx.CHANGELOG.md,README.md,README-EXT.md,AGENTS.md(new "Time Tracking Invariants" section), andagents/pitfalls.md.Checklist
Documentation
README.mdCHANGELOG.mdupdated accordinglyGeneral
mainpnpm test,pnpm lint, andpnpm buildNotes for Reviewers
endDayandadjustTaskTimecontext tests and the four archive validation tests fail without the fix and pass with it.TaskEditDialog(current-day task edit) does not show the inline validation. It relies on theadjustTaskTimeclamp, so an end-before-start edit there saves as zero length. That could be a follow-up if you want the same inline error.docs/TESTING.md,agents/testing.md, anddocs/CI_CD.mdcarry test counts that were already stale. I left them alone.Generated by Claude Code