#!/usr/bin/env bash test_description="date/time parser module" . ./test-lib.sh # This is currently just a quick sanity/smoke test. _date () { date -d "$*" +%s } _parse_time () { ${TEST_DIRECTORY}/parse-time --format=%s "$*" } test_begin_subtest "Date parser tests" cat < INPUT now -> Tue Jan 11 11:11:00 +0000 2011 2010-1-1 -> parse_time_string() error: 5 Jan 2 -> Sat Jan 02 11:11:00 +0000 2010 # Why 2010? Mon -> Mon Jan 10 11:11:00 +0000 2011 last Friday -> parse_time_string() error: 4 2 hours ago -> parse_time_string() error: 1 last month -> Sat Dec 11 11:11:00 +0000 2010 month ago -> parse_time_string() error: 1 8am -> Tue Jan 11 08:00:00 +0000 2011 9:15 -> Tue Jan 11 09:15:00 +0000 2011 12:34 -> Tue Jan 11 12:34:00 +0000 2011 monday -> Mon Jan 10 11:11:00 +0000 2011 yesterday -> Mon Jan 10 11:11:00 +0000 2011 tomorrow -> parse_time_string() error: 1 -> Tue Jan 11 11:11:00 +0000 2011 # Shouldn't empty string return an error??? Aug 3 23:06:06 2012 -> Fri Aug 03 23:06:06 +0000 2012 # date(1) default format without TZ code Fri, 03 Aug 2012 23:07:46 +0100 -> Fri Aug 03 22:07:46 +0000 2012 # rfc-2822 2012-08-03 23:09:37+03:00 -> Fri Aug 03 20:09:37 +0000 2012 # rfc-3339 seconds 10s -> Tue Jan 11 11:10:50 +0000 2011 19701223s -> Wed Dec 23 11:10:59 +0000 1970 # Surprising - number is parsed as date and 's' as '1 second' 19701223 -> Wed Dec 23 11:11:00 +0000 1970 19701223 +0100 -> Wed Dec 23 11:11:00 +0000 1970 # Timezone is ignored without an error today ^-> Wed Jan 12 00:00:00 +0000 2011 # This should be 11 23:59:59 today v-> Tue Jan 11 00:00:00 +0000 2011 thisweek ^-> Sun Jan 16 00:00:00 +0000 2011 # This should be Sunday 23:59:59 thisweek v-> Sun Jan 09 00:00:00 +0000 2011 # This should be Monday 00:00:00 two months ago-> parse_time_string() error: 1 # Comments in the code suggest that this is supported two months -> Thu Nov 11 11:11:00 +0000 2010 1348569850 -> parse_time_string() error: 4 # Seconds since epoch not yet supported? Backward compatibility in notmuch??? 10 -> parse_time_string() error: 4 # Seconds since epoch? EOF ${TEST_DIRECTORY}/parse-time --now="Tue Jan 11 11:11:00 +0000 2011" < INPUT > OUTPUT test_expect_equal_file INPUT OUTPUT test_done