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
16 changes: 16 additions & 0 deletions internal/things/dates.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,23 @@ import (

var whenKeywords = []string{"today", "tomorrow", "evening", "anytime", "someday"}

// weekdayWords are natural-language day names Things accepts verbatim. They are
// allowlisted so the typo detector never mistakes them for a keyword — e.g.
// "monday" is Levenshtein distance 2 from "today" and would otherwise be
// rejected as a typo. Abbreviations are included for the same reason.
var weekdayWords = []string{
"monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday",
"mon", "tue", "tues", "wed", "thu", "thur", "thurs", "fri", "sat", "sun",
}

func isWhenKeyword(s string) bool {
return slices.Contains(whenKeywords, s)
}

func isWeekdayWord(s string) bool {
return slices.Contains(weekdayWords, s)
}

// NormalizeWhen validates and canonicalises a --when value.
//
// Accepted forms:
Expand All @@ -37,6 +50,9 @@ func NormalizeWhen(s string) (string, error) {
if t, ok := parseISO8601(v); ok {
return t.Format("2006-01-02") + "@" + t.Format("15:04"), nil
}
if isWeekdayWord(strings.ToLower(v)) {
return v, nil
}
if k, ok := nearKeyword(v); ok {
return "", fmt.Errorf("unrecognised --when value %q (did you mean %q? valid keywords: %s)", v, k, strings.Join(whenKeywords, ", "))
}
Expand Down
5 changes: 5 additions & 0 deletions internal/things/dates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ func TestNormalizeWhen(t *testing.T) {
{"21:30", "21:30"},
{"next friday", "next friday"},
{"friday", "friday"},
{"monday", "monday"}, // dist 2 from "today" — must not be flagged as a typo
{"Monday", "Monday"}, // case preserved for NL pass-through
{"tuesday", "tuesday"},
{"sunday", "sunday"},
{"mon", "mon"},
{"tonight", "tonight"},
{"noon", "noon"},
{"2026-03-10T14:30:00Z", "2026-03-10@14:30"},
Expand Down