diff options
author | Koni Marti <koni.marti@gmail.com> | 2022-11-15 21:24:49 +0100 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2022-12-02 22:59:23 +0100 |
commit | ff101bda430dda18e6f150ce6915891139ecccd9 (patch) | |
tree | df7906c7c5379307522ddc21634660fc99f02b2d /worker/lib/daterange_test.go | |
parent | 23a05d17ac1d23466ff73efa19576d43d06efe4b (diff) | |
download | aerc-ff101bda430dda18e6f150ce6915891139ecccd9.tar.gz |
search: handle date ranges in search/filter query
Handle date ranges in the filter and search commands for searching and
filtering based on the Date: header. Implement a flag (-d) that accepts
a date range <start[..end]> where the start date is included in the
range but the end date is not, i.e. [start,end).
The start or end date can be omitted: "start", "start..", "..end", or
"start..end" are all valid inputs.
An example filter query would look like this: :filter -d 2022-11-09..
The dates should be in the YYYY-MM-DD format.
Signed-off-by: Koni Marti <koni.marti@gmail.com>
Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'worker/lib/daterange_test.go')
-rw-r--r-- | worker/lib/daterange_test.go | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/worker/lib/daterange_test.go b/worker/lib/daterange_test.go new file mode 100644 index 00000000..983f99a0 --- /dev/null +++ b/worker/lib/daterange_test.go @@ -0,0 +1,55 @@ +package lib_test + +import ( + "testing" + "time" + + "git.sr.ht/~rjarry/aerc/worker/lib" +) + +func TestParseDateRange(t *testing.T) { + dateFmt := "2006-01-02" + parse := func(s string) time.Time { d, _ := time.Parse(dateFmt, s); return d } + tests := []struct { + s string + start time.Time + end time.Time + }{ + { + s: "2022-11-01", + start: parse("2022-11-01"), + end: parse("2022-11-02"), + }, + { + s: "2022-11-01..", + start: parse("2022-11-01"), + }, + { + s: "..2022-11-05", + end: parse("2022-11-05"), + }, + { + s: "2022-11-01..2022-11-05", + start: parse("2022-11-01"), + end: parse("2022-11-05"), + }, + } + + for _, test := range tests { + start, end, err := lib.ParseDateRange(test.s) + if err != nil { + t.Errorf("ParseDateRange return error for %s: %v", + test.s, err) + } + + if !start.Equal(test.start) { + t.Errorf("wrong start date; expected %v, got %v", + test.start, start) + } + + if !end.Equal(test.end) { + t.Errorf("wrong end date; expected %v, got %v", + test.end, end) + } + } +} |