readdate.lua

Sun, 21 Jun 2009 19:13:16 +0100

author
Matthew Wild <mwild1@gmail.com>
date
Sun, 21 Jun 2009 19:13:16 +0100
changeset 10
6700d4722be7
parent 4
305e9dd7fc34
child 19
0cdb35f96cb6
permissions
-rwxr-xr-x

readdate: Print any text unused by the time calculation

#!/usr/bin/env lua

local ndp = require "ndp";

local base;
for line in io.lines() do
	if line:match("^base:") then
		-- Set the unixtime to calculate relative to, eg. base:0
		base = tonumber(line:match("^base:(%d+)$"));
	else
		local ret, start, finish = ndp.when(line, base);
		local remaining = "";
		if start and finish then
			remaining = (line:sub(1, start)..line:sub(finish, -1)):gsub("^[%s%p]+", ""):gsub("[%s%p]+$", "");
		end
		print(os.date("%c", ret).." ("..ret..")"..((#remaining>0 and (": "..remaining)) or ""));
	end
end

mercurial