Skip to content

fix: autofill creation date when a task has a priority#82

Open
ronload wants to merge 8 commits into
webstonehq:mainfrom
ronload:fix/creation-date-with-priority
Open

fix: autofill creation date when a task has a priority#82
ronload wants to merge 8 commits into
webstonehq:mainfrom
ronload:fix/creation-date-with-priority

Conversation

@ronload

@ronload ronload commented Jun 27, 2026

Copy link
Copy Markdown
Contributor

What

Tasks created with a leading priority were saved without a creation date.
Adding (A) buy milk produced (A) buy milk, while buy bread correctly
became 2026-06-27 buy bread.

Why

finalize_line only prepended today's date when the line did not start with
a priority, an ISO date, or x . It treated "starts with a priority" as
"already dated", but in todo.txt the creation date comes after the priority
((A) 2026-06-27 buy milk), so priority-led tasks silently lost their date.

How

Parse the line first and insert today's date only when the task is not done
and has no creation date, placing it after the optional priority prefix. As a
result an invalid date like 9999-99-99 is now correctly treated as body
text rather than a creation date.

Flipped the two tests that pinned the old behaviour and added coverage for
the priority-with-existing-date and invalid-date cases. cargo test,
cargo clippy, and cargo fmt --check all pass.

Fixes #77

finalize_line skipped the creation date whenever a line started with a
priority, treating "starts with priority" as "already dated". In todo.txt
the creation date follows the priority, so a task like "(A) buy milk" was
saved without one.

Parse first and insert today's date only when the task is not done and
has no creation date, placing it after the optional priority prefix.

Fixes webstonehq#77
ronload added 7 commits June 28, 2026 03:42
The previous change taught finalize_line to insert a creation date
after a leading priority, but preview_parse still used the old
space-only gate. As a result `(A) task` previewed without a date yet
saved with one, breaking the preview-equals-save invariant.

Route preview_parse through the same finalize_line the save path uses
and drop the duplicated insertion logic, so the preview row always
matches what gets stored.
Switching the skip condition to parse_line's created_date.is_some()
meant a date-shaped but invalid leading token like `1234-56-78` was
treated as having no date, so today's date got prepended and produced
a confusing double date `2026-05-13 1234-56-78 ...`.

Re-check the priority-stripped body for an ISO-date shape before
prepending, matching the old starts_with_iso_date gate, so such
prefixes are left as the user typed them.
Address two review findings in the priority-led date insertion path:

- strip_priority leaves a leading space when more than one space
  follows the priority token, so reattaching produced a double space
  (e.g. "(A)  urgent" -> "(A) 2026-05-13  urgent"). Trim the body and
  keep the priority boundary via the untrimmed slice length so the
  rebuilt line always uses a single space.
- The rewrite dropped the old guard that skipped injection on
  priority-led lines, so a malformed today_str would splice a bogus
  token into the body (e.g. "(A) task" -> "(A) BAD task"). Validate
  today_str as an ISO date before inserting; leave the line untouched
  otherwise.

Add regression tests for both paths.
finalize_line already parses the line once to inspect done/created_date,
then re-parsed the rebuilt string to obtain the dated task. Inserting the
creation date between the priority and the body leaves every body-derived
field identical, so reuse the first parse and update only raw, clean_raw,
and created_date. This halves the parse work on the inbox drain and serve
POST paths.

Tighten the today_str guard to require a 10-char zero-padded date: chrono
accepts forms like 2026-5-13 that a later re-parse would not treat as a
creation date, which would make the reused task drift from a fresh parse.
The doc comment still described a plain creation-date prepend, predating
the change that inserts the date after a leading priority and returns done
or already-dated lines unchanged. Bring the comment in line with both.
The pipeline summary said creation-date prepend, but the date now lands
after a leading priority rather than at the line start. Call it insertion
to cover both placements.
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.

[Bug] Creation date doesn't get autofilled if task is assigned priority at creation

1 participant