readdate.lua

Mon, 19 Mar 2012 22:26:07 +0000

author
Matthew Wild <mwild1@gmail.com>
date
Mon, 19 Mar 2012 22:26:07 +0000
changeset 28
3ddc836b7845
parent 22
707793a758c4
permissions
-rwxr-xr-x

Add MIT/X11 licence

#!/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 "").." ["..(start or "?")..","..(finish or "?").."]");
	end
end

mercurial