Jump to content

Module:Unsigned: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
m Remove U+200e
m Should be exposed
Line 3: Line 3:
-- There's probably a way to use strptime or some other more sophisticated way, but you're not supposed to be using a non-timestamp as input anyway.
-- There's probably a way to use strptime or some other more sophisticated way, but you're not supposed to be using a non-timestamp as input anyway.


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


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


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

Revision as of 22:59, 31 July 2016

local p = {}

-- There's probably a way to use strptime or some other more sophisticated way, but you're not supposed to be using a non-timestamp as input anyway.

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

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

return p