Module:Unsigned
Appearance
| This module is rated as beta. It is considered ready for widespread use, but as it is still relatively new, it should be applied with some caution to ensure results are as expected. |
| This module is currently protected from editing. See the protection policy and protection log for more details. Please discuss any changes on the talk page; you may submit an edit request to ask an administrator to make an edit if it is uncontroversial or supported by consensus. You may also request that this page be unprotected. |
| This module depends on the following other modules: |
This module implements {{unsigned}}. It has a few functions:
maincalled by {{unsigned}}; not intended for broader usegetTimestampfind a timestamp from a string. If only a date is found, it returns the date. If only a time is found, it returns the empty string. If a time and a date are both found, it appends(UTC)
.getUsernamegets the username from a string containing a timestamp. It currently assumes that everything besides a timestamp is part of the username.
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