Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,7 @@ Both the refusal and the read-back failure carry their per-item detail in the er
| Keyword | `today`, `tomorrow`, `evening`, `anytime`, `someday` |
| Date | `2026-05-01` |
| Time | `HH:MM` (`21:30`) or a 12-hour time (`9:30PM`, `6pm`), sent to Things as `HH:MM` |
| Date + time | `2026-05-01@09:30` |
| Date + time | `2026-05-01@09:30`, or `today@6pm`, `tomorrow@18:00`, `2026-05-01@9pm` (sent to Things as `YYYY-MM-DD@HH:MM`, with today and tomorrow as their dates) |
| RFC3339 | `2026-05-01T09:30:00Z` (rewritten to `YYYY-MM-DD@HH:MM`; offset preserved as wall-clock, no conversion to local time) |
| Natural language | `friday`, `next monday` (English locales only; passed through verbatim) |

Expand Down
6 changes: 4 additions & 2 deletions cmd/things/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"fmt"

"github.com/ryanlewis/things-cli/internal/clock"
"github.com/ryanlewis/things-cli/internal/db"
"github.com/ryanlewis/things-cli/internal/model"
"github.com/ryanlewis/things-cli/internal/things"
Expand All @@ -27,11 +28,12 @@ func (c *AddCmd) Run(d *Deps) error {
if list == "" {
list = c.Project
}
when := things.ResolveWhen(c.When, clock.Now())
params := things.AddParams{
AddCommon: things.AddCommon{
Title: c.Title,
Notes: c.Notes,
When: c.When,
When: when,
Deadline: c.Deadline,
Tags: c.Tags,
},
Expand All @@ -47,7 +49,7 @@ func (c *AddCmd) Run(d *Deps) error {
if target.ByUUID {
params.List, params.ListID = "", target.UUID
}
return applyAdd(d, model.TypeTask, c.Title, dest, c.When, func() error {
return applyAdd(d, model.TypeTask, c.Title, dest, c.When, when, func() error {
return things.AddTask(params)
})
}
Expand Down
68 changes: 67 additions & 1 deletion cmd/things/add_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ func TestAddNotFoundSearchHintKeepsGlobalFlags(t *testing.T) {
Stderr: io.Discard,
}

err := applyAdd(d, model.TypeTask, "Buy oat milk", createdDest{}, "", func() error {
err := applyAdd(d, model.TypeTask, "Buy oat milk", createdDest{}, "", "", func() error {
return things.AddTask(things.AddParams{AddCommon: things.AddCommon{Title: "Buy oat milk"}})
})
want := "things --db '/tmp/my things.sqlite' --config /tmp/c.toml search 'Buy oat milk'"
Expand Down Expand Up @@ -1236,3 +1236,69 @@ func TestWhen12HourReadBack(t *testing.T) {
})
}
}

// A date or today or tomorrow with a time after the @ is sent as the
// YYYY-MM-DD@HH:MM Things was measured with, and read back like one: an add
// that lands with no start date, or an edit Things applies without moving the
// item, is misfiled instead of confirmed unchecked. Messages name the value as
// typed.
func TestWhenDatedTimeReadBack(t *testing.T) {
date := func(days int) string { return testNow.AddDate(0, 0, days).Format("2006-01-02") }
later, year := date(2), testNow.Format("2006")
for in, sent := range map[string]string{
"today@6pm": date(0) + "@18:00",
"TODAY@9:30PM": date(0) + "@21:30",
"tomorrow@18:00": date(1) + "@18:00",
"tomorrow@9:05": date(1) + "@09:05",
later + "@9pm": later + "@21:00",
later + "@9:30": later + "@09:30",
year + "-1-5@6am": year + "-01-05@06:00",
} {
t.Run(in, func(t *testing.T) {
fastVerify(t)
database, sqlDB := seedWritable(t)
var urls []string
prev := things.SetExecCommandForTest(func(_ string, args ...string) *exec.Cmd {
urls = append(urls, strings.Join(args, " "))
bumpModificationDates(t, sqlDB)
return exec.Command("true")
})
t.Cleanup(func() { things.SetExecCommandForTest(prev) })
_, _, err := runStreams(t, database, "--json", "edit", "one-1", "--when", in)
if err == nil || !strings.Contains(err.Error(), "edit did not apply as sent") || !strings.Contains(err.Error(), strconv.Quote(in)) {
t.Errorf("edit --when %s = %v; want it misfiled, naming the value as typed", in, err)
}
if want := "when=" + url.QueryEscape(sent); len(urls) != 1 || !strings.Contains(urls[0], want) {
t.Errorf("edit --when %s sent %q, want %s", in, urls, want)
}

for _, add := range [][]string{{"add", "Buy oat milk"}, {"project", "add", "Buy oat milk"}} {
typ := model.TypeTask
if add[0] == "project" {
typ = model.TypeProject
}
uuid := "new-" + add[0]
urls = nil
prev := things.SetExecCommandForTest(func(_ string, args ...string) *exec.Cmd {
urls = append(urls, strings.Join(args, " "))
now := model.TimeToUnix(time.Now())
if _, err := sqlDB.Exec(`INSERT INTO TMTask (uuid, title, type, status, trashed, start, creationDate, userModificationDate) VALUES (?, 'Buy oat milk', ?, 0, 0, 0, ?, ?)`, uuid, int(typ), now, now); err != nil {
t.Errorf("simulating Things add: %v", err)
}
return exec.Command("true")
})
t.Cleanup(func() { things.SetExecCommandForTest(prev) })
_, _, err = runStreams(t, database, append(add, "--when", in)...)
if err == nil || !strings.Contains(err.Error(), "add did not apply as sent") || !strings.Contains(err.Error(), strconv.Quote(in)) {
t.Errorf("%s --when %s = %v; want it misfiled, naming the value as typed", add[0], in, err)
}
if want := "when=" + url.QueryEscape(sent); len(urls) != 1 || !strings.Contains(urls[0], want) {
t.Errorf("%s --when %s sent %q, want %s", add[0], in, urls, want)
}
if _, err := sqlDB.Exec(`DELETE FROM TMTask WHERE uuid = ?`, uuid); err != nil {
t.Fatal(err)
}
}
})
}
}
2 changes: 1 addition & 1 deletion cmd/things/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
// Help for --when and --deadline, which add, project add, edit and project
// edit share. parserOptions hands them to kong as helpVars.
const (
whenValues = "today|tomorrow|evening|anytime|someday, YYYY-MM-DD, HH:MM or a 12-hour time such as 6pm or 9:30PM (sent as HH:MM), YYYY-MM-DD@HH:MM"
whenValues = "today|tomorrow|evening|anytime|someday, YYYY-MM-DD, HH:MM or a 12-hour time such as 6pm or 9:30PM (sent as HH:MM), YYYY-MM-DD@HH:MM (today@ or tomorrow@ and a 12-hour time too, sent as YYYY-MM-DD@HH:MM)"
deadlineNoKeyword = "Keywords such as today and tomorrow are rejected."
)

Expand Down
10 changes: 9 additions & 1 deletion cmd/things/edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -419,12 +419,20 @@ func runEdit[P interface {
// that may differ from the item: any field flag outside coveredFields,
// or a covered one whose value the item does not provably have already
// (coveredFields.unchanged).
// The no-op check judges --when as sent (things.ResolveWhen), as the
// read-back does, so tomorrow@8am on an item already filed there is
// caught here rather than waited on.
if f.When != nil {
sent := things.ResolveWhen(*f.When, now)
common.When = &sent
}
cf := f.covered()
cf.when = common.When
changed := uncovered || cf.set() && !cf.unchanged(task, foldTags(unknown), reads, now)
var when *whenCheck
if f.When != nil && changed {
whenOnly := !uncovered && f.onlyWhen()
when = &whenCheck{value: *f.When, phraseOnly: whenOnly && whenPhrase(*f.When)}
when = &whenCheck{value: *f.When, sentAs: *common.When, phraseOnly: whenOnly && whenPhrase(*f.When)}
if !s.Duplicate && !d.NoVerify {
if h := heldIn(task, now, reads.stored); h == heldUnmoved || h == heldCarried {
when.before = task
Expand Down
6 changes: 6 additions & 0 deletions cmd/things/edit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,12 @@ func TestEditCertainNoOpSkipsTheWait(t *testing.T) {
{"whenTimeOtherClock", []string{"edit", "rem-1", "--when", "18:30"}, false},
// Things records no change for the reminder an item already has.
{"whenSameDateTime", []string{"edit", "tom-1", "--when", day(1) + "@08:00"}, true},
// A dated time or tomorrow with a time is judged as sent
// (YYYY-MM-DD@HH:MM), so the same reminder is no change.
{"whenTomorrowAtSameClock", []string{"edit", "tom-1", "--when", "tomorrow@8am"}, true},
{"whenTomorrowAtSameClock24", []string{"edit", "tom-1", "--when", "Tomorrow@08:00"}, true},
{"whenSameDate12Hour", []string{"edit", "tom-1", "--when", day(1) + "@8am"}, true},
{"whenTomorrowAtOtherClock", []string{"edit", "tom-1", "--when", "tomorrow@9am"}, false},
{"whenDateTimeOtherClock", []string{"edit", "tom-1", "--when", day(1) + "@09:00"}, false},
{"whenPastDateTimeOnReminder", []string{"edit", "rem-1", "--when", day(-2) + "@18:00"}, true},
{"whenTomorrowKeepsReminder", []string{"edit", "tom-1", "--when", "tomorrow"}, true},
Expand Down
6 changes: 4 additions & 2 deletions cmd/things/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"strings"

"github.com/ryanlewis/things-cli/internal/clock"
"github.com/ryanlewis/things-cli/internal/db"
"github.com/ryanlewis/things-cli/internal/model"
"github.com/ryanlewis/things-cli/internal/things"
Expand All @@ -27,11 +28,12 @@ type ProjectAddCmd struct {
}

func (c *ProjectAddCmd) Run(d *Deps) error {
when := things.ResolveWhen(c.When, clock.Now())
params := things.AddProjectParams{
AddCommon: things.AddCommon{
Title: c.Title,
Notes: c.Notes,
When: c.When,
When: when,
Deadline: c.Deadline,
Tags: c.Tags,
},
Expand All @@ -55,7 +57,7 @@ func (c *ProjectAddCmd) Run(d *Deps) error {
if target.UUID != "" {
noteTarget(d, params.Area, "areas", target)
}
return applyAdd(d, model.TypeProject, c.Title, dest, c.When, func() error {
return applyAdd(d, model.TypeProject, c.Title, dest, c.When, when, func() error {
return things.AddProject(params)
})
}
Expand Down
9 changes: 5 additions & 4 deletions cmd/things/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -589,11 +589,12 @@ var unconfirmedMsg = map[string]string{
// same place at the same moment — is reported unconfirmed with the
// candidates rather than guessed. Under
// --no-verify, or when the database cannot be read, the write still goes out
// and the output says it is unconfirmed. when is the --when value, "" for
// none: the item found must be filed where it says (whenCheck). Things
// and the output says it is unconfirmed. when is the --when value as typed, "" for
// none, and sentAs the value write sends (things.ResolveWhen): the item
// found must be filed where that says (whenCheck). Things
// creates the item in one write, so a new item filed anywhere else is the
// write's and is reported as such, not waited on.
func applyAdd(d *Deps, typ model.TaskType, title string, dest createdDest, when string, write func() error) error {
func applyAdd(d *Deps, typ model.TaskType, title string, dest createdDest, when, sentAs string, write func() error) error {
if d.NoVerify {
if err := write(); err != nil {
return err
Expand Down Expand Up @@ -623,7 +624,7 @@ func applyAdd(d *Deps, typ model.TaskType, title string, dest createdDest, when

var whenSent *whenCheck
if strings.TrimSpace(when) != "" {
whenSent = &whenCheck{value: when, sent: clock.Now()}
whenSent = &whenCheck{value: when, sentAs: sentAs, sent: clock.Now()}
}
if err := write(); err != nil {
return err
Expand Down
33 changes: 23 additions & 10 deletions cmd/things/when.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,14 +321,19 @@ func unmovedKeeps(p whenPlace, now time.Time, task *model.Task) bool {
return p.bucket != 1 || task.StartBucket == 1
}

// whenCheck is the --when part of a read-back: the value sent and when it was
// sent. before is the item as read before the write when it was a row Things
// had not moved into today yet or one in Today from an earlier day (heldIn),
// nil otherwise; carried says it was the second. whenOnly says the edit
// changes nothing but --when, so such a row Things left as it was, with
// nothing recorded, is the edit applied (unmovedKeeps).
// whenCheck is the --when part of a read-back: the value, as typed and as
// sent, and when it was sent. before is the item as read before the write
// when it was a row Things had not moved into today yet or one in Today
// from an earlier day (heldIn), nil otherwise; carried says it was the
// second. whenOnly says the edit changes nothing but --when, so such a row
// Things left as it was, with nothing recorded, is the edit applied
// (unmovedKeeps).
type whenCheck struct {
value string
value string
// sentAs is the value as sent (things.ResolveWhen), "" when it went as
// value, as an import's when does. It is what the read-back judges;
// messages name value, as typed.
sentAs string
sent time.Time
before *model.Task
carried bool
Expand All @@ -354,14 +359,22 @@ func (c *whenCheck) holds(t *model.Task, now time.Time) bool {
if c == nil {
return true
}
p, ok := placeWhen(c.value, c.sent)
p, ok := placeWhen(c.judged(), c.sent)
if !ok || c.landed(p, c.sent, t) {
return true
}
p, ok = placeWhen(c.value, now)
p, ok = placeWhen(c.judged(), now)
return ok && c.landed(p, now, t)
}

// judged is the value as sent, which the read-back judges.
func (c *whenCheck) judged() string {
if c.sentAs != "" {
return c.sentAs
}
return c.value
}

// landed reports whether t is where p, read at now, puts it.
func (c *whenCheck) landed(p whenPlace, now time.Time, t *model.Task) bool {
return p.holds(t, model.ThingsDateFromTime(now)) || c.kept(p, now, t)
Expand Down Expand Up @@ -389,7 +402,7 @@ func (c *whenCheck) keptQuietly(t *model.Task, now time.Time) bool {
return false
}
for _, at := range []time.Time{c.sent, now} {
if p, ok := placeWhen(c.value, at); ok && c.kept(p, at, t) {
if p, ok := placeWhen(c.judged(), at); ok && c.kept(p, at, t) {
return true
}
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/things/when_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ func TestMisfiledAddHint(t *testing.T) {
stubExecAdding(t, sqlDB, createdRow{uuid: "new-p", title: "Launch", typ: model.TypeProject, extra: "start = 1"})
d := &Deps{DB: database, DBPath: "/tmp/x.sqlite", Stdout: io.Discard, Stderr: io.Discard}

err := applyAdd(d, model.TypeProject, "Launch", createdDest{}, "someday", func() error {
err := applyAdd(d, model.TypeProject, "Launch", createdDest{}, "someday", "", func() error {
return things.AddProject(things.AddProjectParams{AddCommon: things.AddCommon{Title: "Launch", When: "someday"}})
})
if err == nil {
Expand Down
14 changes: 11 additions & 3 deletions docs/content/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -515,8 +515,15 @@ time, not the local time of 09:00 at +05:00. `--deadline` accepts a
`YYYY-MM-DD` date or an English phrase such as `next friday`; the `--when`
keywords, such as `today`, are rejected. A 12-hour time on its own is
sent to Things as `HH:MM` (`6pm` as `18:00`, `9:30PM` as `21:30`), the
form Things was measured with, and is read back like one; after an `@` it
is sent as typed.
form Things was measured with, and is read back like one. A date, `today`
or `tomorrow` with a time after the `@` is sent as the measured
`YYYY-MM-DD@HH:MM`: `today@6pm` goes as today's date at `18:00`,
`tomorrow@9:30` as tomorrow's date at `09:30`, and `2026-10-12@9pm` as
`2026-10-12@21:00`, and each is read back like a date and time. Today and
tomorrow are the dates when the command runs, so `tomorrow@6pm` sent just
before midnight is the next day, even if Things reads it after midnight.
`evening@6pm` and anything else with an `@` are sent as typed and not
checked.

Things files the to-do by matching `--list` (or `--project`) against the
titles of the projects and areas it shows, and `--heading` against the
Expand Down Expand Up @@ -689,7 +696,8 @@ it already has is detected before the wait when every flag is `--title`,
`--notes`, `--tags`, `--add-tags` (tags compared case-insensitively), a
`--deadline` date, an empty `--append-notes` or `--prepend-notes`, or a
`--when` of `anytime`, `someday`, `today`, `evening`, `tomorrow`, empty,
a date, an `HH:MM` time or a `YYYY-MM-DD@HH:MM` date and time. A past date
a date, an `HH:MM` time or a `YYYY-MM-DD@HH:MM` date and time (`today@6pm`
and `tomorrow@18:00` included, judged as the date and time sent). A past date
files the item under today. `--when today`, `evening`, today's date or a
past date clears a reminder, so on an item with one it counts as a change
and waits; a later day keeps the reminder. A time sets the reminder, for
Expand Down
2 changes: 1 addition & 1 deletion internal/skill/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ A plain listing prints each task on one line: a line break or tab in a title, ta

## Date and multi-line values

`--when` takes a keyword (`today`, `tomorrow`, `evening`, `anytime`, `someday`), a date `YYYY-MM-DD`, a time `HH:MM` or a 12-hour time (`9:30PM`, `6pm`; sent to Things as `21:30`, `18:00` and read back like one), a date+time `YYYY-MM-DD@HH:MM`, or an RFC3339 timestamp. An RFC3339 timestamp keeps its wall-clock time and ignores its offset: `2026-05-01T09:00:00+05:00` sets 09:00 local, so convert to local time before passing one. English phrases (`friday`, `next monday`) are passed through to Things. A date and time with no offset (`2026-10-09T10:00`) is read as that wall-clock time. A value shaped like a date or time that names none (`2026-13-01`, `25:00`, `tomorrow@25:00`, `2026-10-09T25:00:00Z`), or a time after `anytime@`/`someday@`, is refused before anything is sent. A free phrase (anything but a keyword, a weekday name, a date or a time) is not checked: `add` warns on stderr when the new item has no start date, and still prints the item and exits 0 (it exists, without the `--when`); an `edit` whose only change is a free phrase is not read back and returns at once unconfirmed, with a warning (`{"uuid", "title", "confirmed": false, "reason": "when"}`: check it with `things show`), since Things records nothing when it ignores one; with other changes the edit waits as usual, and if nothing was modified its error names the phrase. Likely keyword typos (edit distance ≤ 2, e.g. `tommorrow`) are rejected with a "did you mean" hint.
`--when` takes a keyword (`today`, `tomorrow`, `evening`, `anytime`, `someday`), a date `YYYY-MM-DD`, a time `HH:MM` or a 12-hour time (`9:30PM`, `6pm`; sent to Things as `21:30`, `18:00` and read back like one), a date+time `YYYY-MM-DD@HH:MM` (also `today@6pm`, `tomorrow@18:00`, `2026-05-01@9pm`: sent to Things as `YYYY-MM-DD@HH:MM`, with today and tomorrow as their dates when the command runs, and read back like one; `evening@6pm` is sent as typed and not checked), or an RFC3339 timestamp. An RFC3339 timestamp keeps its wall-clock time and ignores its offset: `2026-05-01T09:00:00+05:00` sets 09:00 local, so convert to local time before passing one. English phrases (`friday`, `next monday`) are passed through to Things. A date and time with no offset (`2026-10-09T10:00`) is read as that wall-clock time. A value shaped like a date or time that names none (`2026-13-01`, `25:00`, `tomorrow@25:00`, `2026-10-09T25:00:00Z`), or a time after `anytime@`/`someday@`, is refused before anything is sent. A free phrase (anything but a keyword, a weekday name, a date or a time) is not checked: `add` warns on stderr when the new item has no start date, and still prints the item and exits 0 (it exists, without the `--when`); an `edit` whose only change is a free phrase is not read back and returns at once unconfirmed, with a warning (`{"uuid", "title", "confirmed": false, "reason": "when"}`: check it with `things show`), since Things records nothing when it ignores one; with other changes the edit waits as usual, and if nothing was modified its error names the phrase. Likely keyword typos (edit distance ≤ 2, e.g. `tommorrow`) are rejected with a "did you mean" hint.

`--deadline` takes `YYYY-MM-DD` or an English phrase; keywords like `today` are rejected.

Expand Down
Loading
Loading