Mon, 22 Jun 2009 01:16:01 +0100
Support for accurate 'next month' and 'next year'
4 | 1 | #!/usr/bin/env lua |
2 | ||
0
44416491923e
Initial commit of ndp, the natural date processing library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3 | local ndp = require "ndp"; |
44416491923e
Initial commit of ndp, the natural date processing library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
4 | |
44416491923e
Initial commit of ndp, the natural date processing library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
5 | local base; |
44416491923e
Initial commit of ndp, the natural date processing library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
6 | for line in io.lines() do |
10
6700d4722be7
readdate: Print any text unused by the time calculation
Matthew Wild <mwild1@gmail.com>
parents:
4
diff
changeset
|
7 | if line:match("^base:") then |
6700d4722be7
readdate: Print any text unused by the time calculation
Matthew Wild <mwild1@gmail.com>
parents:
4
diff
changeset
|
8 | -- Set the unixtime to calculate relative to, eg. base:0 |
0
44416491923e
Initial commit of ndp, the natural date processing library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
9 | base = tonumber(line:match("^base:(%d+)$")); |
44416491923e
Initial commit of ndp, the natural date processing library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
10 | else |
10
6700d4722be7
readdate: Print any text unused by the time calculation
Matthew Wild <mwild1@gmail.com>
parents:
4
diff
changeset
|
11 | local ret, start, finish = ndp.when(line, base); |
6700d4722be7
readdate: Print any text unused by the time calculation
Matthew Wild <mwild1@gmail.com>
parents:
4
diff
changeset
|
12 | local remaining = ""; |
6700d4722be7
readdate: Print any text unused by the time calculation
Matthew Wild <mwild1@gmail.com>
parents:
4
diff
changeset
|
13 | if start and finish then |
6700d4722be7
readdate: Print any text unused by the time calculation
Matthew Wild <mwild1@gmail.com>
parents:
4
diff
changeset
|
14 | remaining = (line:sub(1, start)..line:sub(finish, -1)):gsub("^[%s%p]+", ""):gsub("[%s%p]+$", ""); |
6700d4722be7
readdate: Print any text unused by the time calculation
Matthew Wild <mwild1@gmail.com>
parents:
4
diff
changeset
|
15 | end |
22
707793a758c4
readdate: Fix traceback when nothing is consumed from the input text
Matthew Wild <mwild1@gmail.com>
parents:
19
diff
changeset
|
16 | print(os.date("%c", ret).." ("..ret..")"..((#remaining>0 and (": "..remaining)) or "").." ["..(start or "?")..","..(finish or "?").."]"); |
0
44416491923e
Initial commit of ndp, the natural date processing library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
17 | end |
44416491923e
Initial commit of ndp, the natural date processing library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
18 | end |
44416491923e
Initial commit of ndp, the natural date processing library
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
19 |