Skip to content

fix(cli): sort timeline and archive date groups by calendar date - #71

Open
alycda wants to merge 1 commit into
taskbook-sh:masterfrom
alycda:fix/timeline-date-order
Open

alycda wants to merge 1 commit into
taskbook-sh:masterfrom
alycda:fix/timeline-date-order

Conversation

@alycda

@alycda alycda commented Nov 8, 2026

Copy link
Copy Markdown

tb --timeline and tb --archive list days out of order. Render::display_by_date sorts its group keys with a string compare, and the keys are display strings in the %a %b %d %Y format items are created with ("Wed Oct 21 2026"). So days are ordered by weekday name, then month name: Wed Oct 21 2026 is listed above Sat Jan 02 2027. The comment above the sort says it is chronological; it is not.

Change

  • New dates_newest_first in render.rs parses each key with the same format (chrono::NaiveDate::parse_from_str) and sorts newest first.
  • A key that does not parse (hand-edited storage) sorts after every dated key, in the descending string order it had before, so nothing disappears.
  • Two unit tests: calendar order across a year boundary, and unparseable keys last.

The TUI timeline already sorts by timestamp (tui/app.rs), so this makes the CLI match it.

Not in this PR

The order of items inside a date group comes from HashMap iteration and changes between runs. #66 fixes that (ID order within board and date groups); this PR only touches the order of the groups, and the two don't conflict.

🤖 Generated with Claude Code

display_by_date sorted its group keys with a plain string compare. The
keys are display strings ("Wed Oct 21 2026", the %a %b %d %Y format items
are created with), so tb --timeline and tb --archive ordered days by
weekday name, then month name, despite the comment saying the order was
chronological. Wed Oct 21 came before Sat Jan 02 of the next year.

Parse each key with the same format and sort newest first. A key that
does not parse (hand-edited storage) sorts after every dated key, in the
descending string order it had before.

Ordering by the newest item timestamp in each group was the other option;
parsing keeps the order a property of the keys alone, so it does not
depend on what the group holds.

The order of items inside a group is a separate HashMap-order issue,
handled by taskbook-sh#66; this change touches only the order of the groups.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@alycda
alycda marked this pull request as ready for review November 8, 2026 04:05
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.

1 participant