Module:Unsigned
Appearance
![]() | This module is rated as beta, and is ready for widespread use. It is still new and should be used with some caution to ensure the results are as expected. |
![]() | This module is subject to page protection. It is a highly visible module in use by a very large number of pages, or is substituted very frequently. Because vandalism or mistakes would affect many pages, and even trivial editing might cause substantial load on the servers, it is protected from editing. |
![]() | This module depends on the following other modules: |
This module implements {{unsigned}}. It has a few functions:
main
called by {{unsigned}}; not intended for broader usegetTimestamp
find 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)
.getUsername
gets 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
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
-- We're being called via #invoke. The args are passed through to the module
-- from the template page, so use the args that were passed into the template.
args = frame.args
else
-- We're being called from another module or from the debug console, so assume
-- the args are passed in directly.
args = frame
end
return _main(args)
end
return p