Sun, 21 Jun 2009 23:57:36 +0100
Add initial README
0
44416491923e
Initial commit of ndp, the natural date processing library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1 | local when = require "ndp".when; |
44416491923e
Initial commit of ndp, the natural date processing library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2 | |
44416491923e
Initial commit of ndp, the natural date processing library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3 | if not when then |
44416491923e
Initial commit of ndp, the natural date processing library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
4 | print("No 'when' function ?!"); |
44416491923e
Initial commit of ndp, the natural date processing library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
5 | end |
44416491923e
Initial commit of ndp, the natural date processing library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
6 | |
44416491923e
Initial commit of ndp, the natural date processing library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
7 | local all_ok = true; |
44416491923e
Initial commit of ndp, the natural date processing library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
8 | |
18
d6f0c12c152a
tests: Add support for checking the consumed part of the input
Matthew Wild <mwild1@gmail.com>
parents:
8
diff
changeset
|
9 | local function check(input, output, e_start, e_finish) |
d6f0c12c152a
tests: Add support for checking the consumed part of the input
Matthew Wild <mwild1@gmail.com>
parents:
8
diff
changeset
|
10 | local ret, start, finish = when(input, 0); |
0
44416491923e
Initial commit of ndp, the natural date processing library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
11 | if ret ~= output then |
44416491923e
Initial commit of ndp, the natural date processing library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
12 | print("FAIL: "..input.." [produces "..ret.."/"..os.date("!%c", ret).."]"); |
44416491923e
Initial commit of ndp, the natural date processing library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
13 | all_ok = false; |
44416491923e
Initial commit of ndp, the natural date processing library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
14 | return false; |
18
d6f0c12c152a
tests: Add support for checking the consumed part of the input
Matthew Wild <mwild1@gmail.com>
parents:
8
diff
changeset
|
15 | elseif (e_start and e_finish) and (start ~= e_start or finish ~= e_finish) then |
d6f0c12c152a
tests: Add support for checking the consumed part of the input
Matthew Wild <mwild1@gmail.com>
parents:
8
diff
changeset
|
16 | print("FAIL: "..input.." [uses "..start..","..finish.." instead of "..e_start..","..e_finish.."]"); |
d6f0c12c152a
tests: Add support for checking the consumed part of the input
Matthew Wild <mwild1@gmail.com>
parents:
8
diff
changeset
|
17 | all_ok = false; |
d6f0c12c152a
tests: Add support for checking the consumed part of the input
Matthew Wild <mwild1@gmail.com>
parents:
8
diff
changeset
|
18 | return false; |
0
44416491923e
Initial commit of ndp, the natural date processing library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
19 | end |
44416491923e
Initial commit of ndp, the natural date processing library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
20 | end |
44416491923e
Initial commit of ndp, the natural date processing library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
21 | |
44416491923e
Initial commit of ndp, the natural date processing library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
22 | check("today", 0); |
44416491923e
Initial commit of ndp, the natural date processing library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
23 | check("tomorrow", 86400); |
44416491923e
Initial commit of ndp, the natural date processing library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
24 | check("tomorrow morning", 117000); |
44416491923e
Initial commit of ndp, the natural date processing library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
25 | check("tomorrow noon", 126000); |
44416491923e
Initial commit of ndp, the natural date processing library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
26 | check("tomorrow afternoon", 131400); |
44416491923e
Initial commit of ndp, the natural date processing library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
27 | check("tomorrow evening", 145800); |
44416491923e
Initial commit of ndp, the natural date processing library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
28 | check("tomorrow midnight", 82800); -- Correct, but expected? :) |
44416491923e
Initial commit of ndp, the natural date processing library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
29 | |
44416491923e
Initial commit of ndp, the natural date processing library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
30 | check("in 1 hour", 3600); |
44416491923e
Initial commit of ndp, the natural date processing library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
31 | check("in an hour", 3600); |
44416491923e
Initial commit of ndp, the natural date processing library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
32 | check("in 2 hours", 7200); |
44416491923e
Initial commit of ndp, the natural date processing library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
33 | check("in a couple of hours", 7200); |
44416491923e
Initial commit of ndp, the natural date processing library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
34 | check("in 3 hours", 10800); |
44416491923e
Initial commit of ndp, the natural date processing library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
35 | check("in a few hours", 10800); |
44416491923e
Initial commit of ndp, the natural date processing library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
36 | |
44416491923e
Initial commit of ndp, the natural date processing library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
37 | check("in a day", 86400); |
44416491923e
Initial commit of ndp, the natural date processing library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
38 | check("in 2 days", 172800); |
44416491923e
Initial commit of ndp, the natural date processing library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
39 | check("in a couple of days", 172800); |
44416491923e
Initial commit of ndp, the natural date processing library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
40 | check("in 3 days", 259200); |
44416491923e
Initial commit of ndp, the natural date processing library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
41 | check("in a few days", 259200); |
44416491923e
Initial commit of ndp, the natural date processing library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
42 | |
44416491923e
Initial commit of ndp, the natural date processing library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
43 | check("next week", 604800); |
44416491923e
Initial commit of ndp, the natural date processing library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
44 | check("next year", 31536000); |
44416491923e
Initial commit of ndp, the natural date processing library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
45 | |
2
bb0892bc9687
Add tests for days of the week
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
46 | check("monday", 345600); |
bb0892bc9687
Add tests for days of the week
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
47 | check("Monday", 345600); |
bb0892bc9687
Add tests for days of the week
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
48 | check("tuesday", 432000); |
bb0892bc9687
Add tests for days of the week
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
49 | check("wednesday", 518400); |
bb0892bc9687
Add tests for days of the week
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
50 | check("thursday", 604800); |
bb0892bc9687
Add tests for days of the week
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
51 | check("friday", 86400); |
bb0892bc9687
Add tests for days of the week
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
52 | check("the friday after tomorrow", 691200); |
bb0892bc9687
Add tests for days of the week
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
53 | check("the friday morning after tomorrow", 721800) |
bb0892bc9687
Add tests for days of the week
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
54 | check("the friday afternoon after tomorrow", 736200) |
bb0892bc9687
Add tests for days of the week
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
55 | |
8 | 56 | check("2010", 1262307600); |
57 | check("Tuesday in July 2030", 1909184400); | |
58 | ||
20
1db3ee8b9bc3
Add test for 'feed the cat in 3 days'
Matthew Wild <mwild1@gmail.com>
parents:
18
diff
changeset
|
59 | check("feed the cat in 3 days", 259200, 13, 23); |
1db3ee8b9bc3
Add test for 'feed the cat in 3 days'
Matthew Wild <mwild1@gmail.com>
parents:
18
diff
changeset
|
60 | |
0
44416491923e
Initial commit of ndp, the natural date processing library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
61 | if all_ok then |
44416491923e
Initial commit of ndp, the natural date processing library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
62 | print("OK"); |
44416491923e
Initial commit of ndp, the natural date processing library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
63 | end |