Sun, 21 Jun 2009 18:49:06 +0100
Restore 'on day_name' match
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 | |
44416491923e
Initial commit of ndp, the natural date processing library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
9 | local function check(input, output) |
44416491923e
Initial commit of ndp, the natural date processing library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
10 | local ret = when(input, 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; |
44416491923e
Initial commit of ndp, the natural date processing library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
15 | end |
44416491923e
Initial commit of ndp, the natural date processing library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
16 | end |
44416491923e
Initial commit of ndp, the natural date processing library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
17 | |
44416491923e
Initial commit of ndp, the natural date processing library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
18 | check("today", 0); |
44416491923e
Initial commit of ndp, the natural date processing library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
19 | check("tomorrow", 86400); |
44416491923e
Initial commit of ndp, the natural date processing library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
20 | check("tomorrow morning", 117000); |
44416491923e
Initial commit of ndp, the natural date processing library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
21 | check("tomorrow noon", 126000); |
44416491923e
Initial commit of ndp, the natural date processing library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
22 | check("tomorrow afternoon", 131400); |
44416491923e
Initial commit of ndp, the natural date processing library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
23 | check("tomorrow evening", 145800); |
44416491923e
Initial commit of ndp, the natural date processing library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
24 | 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
|
25 | |
44416491923e
Initial commit of ndp, the natural date processing library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
26 | check("in 1 hour", 3600); |
44416491923e
Initial commit of ndp, the natural date processing library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
27 | check("in an hour", 3600); |
44416491923e
Initial commit of ndp, the natural date processing library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
28 | check("in 2 hours", 7200); |
44416491923e
Initial commit of ndp, the natural date processing library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
29 | 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
|
30 | check("in 3 hours", 10800); |
44416491923e
Initial commit of ndp, the natural date processing library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
31 | check("in a few hours", 10800); |
44416491923e
Initial commit of ndp, the natural date processing library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
32 | |
44416491923e
Initial commit of ndp, the natural date processing library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
33 | check("in a day", 86400); |
44416491923e
Initial commit of ndp, the natural date processing library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
34 | check("in 2 days", 172800); |
44416491923e
Initial commit of ndp, the natural date processing library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
35 | 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
|
36 | check("in 3 days", 259200); |
44416491923e
Initial commit of ndp, the natural date processing library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
37 | check("in a few days", 259200); |
44416491923e
Initial commit of ndp, the natural date processing library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
38 | |
44416491923e
Initial commit of ndp, the natural date processing library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
39 | check("next week", 604800); |
44416491923e
Initial commit of ndp, the natural date processing library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
40 | check("next year", 31536000); |
44416491923e
Initial commit of ndp, the natural date processing library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
41 | |
2
bb0892bc9687
Add tests for days of the week
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
42 | check("monday", 345600); |
bb0892bc9687
Add tests for days of the week
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
43 | check("Monday", 345600); |
bb0892bc9687
Add tests for days of the week
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
44 | check("tuesday", 432000); |
bb0892bc9687
Add tests for days of the week
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
45 | check("wednesday", 518400); |
bb0892bc9687
Add tests for days of the week
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
46 | check("thursday", 604800); |
bb0892bc9687
Add tests for days of the week
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
47 | check("friday", 86400); |
bb0892bc9687
Add tests for days of the week
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
48 | check("the friday after tomorrow", 691200); |
bb0892bc9687
Add tests for days of the week
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
49 | check("the friday morning after tomorrow", 721800) |
bb0892bc9687
Add tests for days of the week
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
50 | check("the friday afternoon after tomorrow", 736200) |
bb0892bc9687
Add tests for days of the week
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
51 | |
0
44416491923e
Initial commit of ndp, the natural date processing library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
52 | if all_ok then |
44416491923e
Initial commit of ndp, the natural date processing library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
53 | print("OK"); |
44416491923e
Initial commit of ndp, the natural date processing library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
54 | end |