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