This module processes the timestamp argument for {{Unsigned}} and {{UnsignedIP}}.


local p = {}

local function endswith(String,End)
	return End == '' or string.sub(String,-string.len(End)) == End
end

local function trim(s)
	return s:gsub("^%s+", ""):gsub("%s+$", ""):gsub("\226\128\142", "")
end

local function addUtcToStringIfItDoesNotEndWithUtc(s)
	if s == "" or endswith(s, "~~~~") then return s end
	if not endswith(s, "(UTC)") then
		return s .. " (UTC)"
	end
	return s
end

local function _main(args)
	local hopefullyTimestamp = args[1] or os.date('%H:%M, %d %B %Y (%Z)')
	return addUtcToStringIfItDoesNotEndWithUtc(trim(hopefullyTimestamp))
end

function p.main(frame)
	local args
	if type(frame.args) == 'table' then
		args = frame.args
	else
		args = frame
	end
	return _main(args)
end

return p