| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
local io = { lines = io.lines } |
| 23 |
local os = { time = os.time, date = os.date } |
| 24 |
local helpers = require"vicious.helpers" |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
return helpers.setcall(function (format, warg) |
| 29 |
if not warg then return end |
| 30 |
|
| 31 |
|
| 32 |
local today = os.time{ year = os.date("%Y"), month = os.date("%m"), |
| 33 |
day = os.date("%d") } |
| 34 |
local soon = today + 24*3600*3 |
| 35 |
local future = today + 24*3600*7 |
| 36 |
|
| 37 |
|
| 38 |
local count = { past = 0, today = 0, soon = 0, future = 0 } |
| 39 |
|
| 40 |
|
| 41 |
for i = 1,#warg do |
| 42 |
for line in io.lines(warg[i]) do |
| 43 |
local scheduled = line:find"SCHEDULED:" |
| 44 |
local deadline = line:find"DEADLINE:" |
| 45 |
local closed = line:find"CLOSED:" |
| 46 |
local b, _, y, m, d = line:find"(%d%d%d%d)-(%d%d)-(%d%d)" |
| 47 |
|
| 48 |
if (scheduled or deadline) and not closed and b then |
| 49 |
local t = os.time{ year = y, month = m, day = d } |
| 50 |
if t < today then |
| 51 |
count.past = count.past + 1 |
| 52 |
elseif t == today then |
| 53 |
count.today = count.today + 1 |
| 54 |
elseif t <= soon then |
| 55 |
count.soon = count.soon + 1 |
| 56 |
elseif t <= future then |
| 57 |
count.future = count.future + 1 |
| 58 |
end |
| 59 |
end |
| 60 |
end |
| 61 |
end |
| 62 |
|
| 63 |
return { count.past, count.today, count.soon, count.future } |
| 64 |
end) |
| 65 |
|