fix: autofill creation date when a task has a priority#82
Open
ronload wants to merge 8 commits into
Open
Conversation
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
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.
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.
What
Tasks created with a leading priority were saved without a creation date.
Adding
(A) buy milkproduced(A) buy milk, whilebuy breadcorrectlybecame
2026-06-27 buy bread.Why
finalize_lineonly prepended today's date when the line did not start witha 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-99is now correctly treated as bodytext 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, andcargo fmt --checkall pass.Fixes #77