2 test_description="date/time parser module"
3 . $(dirname "$0")/test-lib.sh || exit 1
5 # Sanity/smoke tests for the date/time parser independent of notmuch
14 ${TEST_DIRECTORY}/parse-time --format=%s "$*"
17 test_begin_subtest "date(1) default format without TZ code"
18 test_expect_equal "$(_parse_time Fri Aug 3 23:06:06 2012)" "$(_date Fri Aug 3 23:06:06 2012)"
20 test_begin_subtest "date(1) --rfc-2822 format"
21 test_expect_equal "$(_parse_time Fri, 03 Aug 2012 23:07:46 +0100)" "$(_date Fri, 03 Aug 2012 23:07:46 +0100)"
23 test_begin_subtest "date(1) --rfc=3339=seconds format"
24 test_expect_equal "$(_parse_time 2012-08-03 23:09:37+03:00)" "$(_date 2012-08-03 23:09:37+03:00)"
26 test_begin_subtest "Date parser tests"
27 REFERENCE=$(_date Tue Jan 11 12:13:14 +0000 2011)
29 now ==> Tue Jan 11 12:13:14 +0000 2011
30 2010-1-1 ==> ERROR: DATEFORMAT
31 Jan 2 ==> Sun Jan 02 12:13:14 +0000 2011
32 Mon ==> Mon Jan 10 12:13:14 +0000 2011
33 last Friday ==> ERROR: FORMAT
34 2 hours ago ==> Tue Jan 11 10:13:14 +0000 2011
35 last month ==> Sat Dec 11 12:13:14 +0000 2010
36 month ago ==> Sat Dec 11 12:13:14 +0000 2010
37 two mo ==> Thu Nov 11 12:13:14 +0000 2010
38 3M ==> Mon Oct 11 12:13:14 +0000 2010
39 4-mont ==> Sat Sep 11 12:13:14 +0000 2010
40 5m ==> Tue Jan 11 12:08:14 +0000 2011
41 dozen mi ==> Tue Jan 11 12:01:14 +0000 2011
42 8am ==> Tue Jan 11 08:00:00 +0000 2011
43 monday ==> Mon Jan 10 12:13:14 +0000 2011
44 yesterday ==> Mon Jan 10 12:13:14 +0000 2011
45 tomorrow ==> ERROR: KEYWORD
46 ==> Tue Jan 11 12:13:14 +0000 2011 # empty string is reference time
48 Aug 3 23:06:06 2012 ==> Fri Aug 03 23:06:06 +0000 2012 # date(1) default format without TZ code
49 Fri, 03 Aug 2012 23:07:46 +0100 ==> Fri Aug 03 22:07:46 +0000 2012 # rfc-2822
50 2012-08-03 23:09:37+03:00 ==> Fri Aug 03 20:09:37 +0000 2012 # rfc-3339 seconds
52 10:30:40 ==> Tue Jan 11 10:30:40 +0000 2011
53 10:30:40 ==^> Tue Jan 11 10:30:40 +0000 2011
54 10:30:40 ==^^> Tue Jan 11 10:30:40 +0000 2011
55 10:30:40 ==_> Tue Jan 11 10:30:40 +0000 2011
57 10s ==> Tue Jan 11 12:13:04 +0000 2011
58 19701223s ==> Fri May 28 11:39:31 +0000 2010
59 19701223 ==> Wed Dec 23 12:13:14 +0000 1970
61 19701223 +0100 ==> Wed Dec 23 12:13:14 +0000 1970 # Timezone is ignored without an error
63 today ==^^> Wed Jan 12 00:00:00 +0000 2011
64 today ==^> Tue Jan 11 23:59:59 +0000 2011
65 today ==_> Tue Jan 11 00:00:00 +0000 2011
67 this week ==^^> Sun Jan 16 00:00:00 +0000 2011
68 this week ==^> Sat Jan 15 23:59:59 +0000 2011
69 this week ==_> Sun Jan 09 00:00:00 +0000 2011
71 two months ago ==> Thu Nov 11 12:13:14 +0000 2010
72 two months ==> Thu Nov 11 12:13:14 +0000 2010
74 @1348569850 ==> Tue Sep 25 10:44:10 +0000 2012
75 @10 ==> Thu Jan 01 00:00:10 +0000 1970
78 ${TEST_DIRECTORY}/parse-time --ref=${REFERENCE} < INPUT > OUTPUT
79 test_expect_equal_file INPUT OUTPUT
81 test_begin_subtest "Second rounding tests"
82 REFERENCE=$(_date Tue Jan 11 12:13:14 +0000 2011)
84 9:15 ==> Tue Jan 11 09:15:14 +0000 2011
85 12:34 ==> Tue Jan 11 12:34:14 +0000 2011
86 10:30 ==> Tue Jan 11 10:30:14 +0000 2011
87 10:30 ==^> Tue Jan 11 10:30:59 +0000 2011
88 10:30 ==^^> Tue Jan 11 10:31:00 +0000 2011
89 10:30 ==_> Tue Jan 11 10:30:00 +0000 2011
91 ${TEST_DIRECTORY}/parse-time --ref=${REFERENCE} < INPUT > OUTPUT
92 test_expect_equal_file INPUT OUTPUT