Module:Time ago: Difference between revisions

allow blank values of |ago=
m (Protected Module:TimeAgo: High-risk Lua module ([Edit=Allow only template editors and admins] (indefinite) [Move=Allow only template editors and admins] (indefinite)))
(allow blank values of |ago=)
Line 5:
 
function p.main( frame )
local args = getArgs( frame, ){
valueFunc = function( k, v )
if v then
v = v:match( '^%s*(.-)%s*$' ) -- Trim whitespace.
if k == 'ago' or v ~= '' then
return v
end
end
return nil
end
})
return p._main( args )
end
Line 12 ⟶ 22:
-- Initialize variables
local lang = mw.language.getContentLanguage()
local ago
local auto_magnitude_num
local min_magnitude_num
Line 18 ⟶ 29:
local magnitude = args.magnitude
local min_magnitude = args.min_magnitude
local ago = args.ago or 'ago'
local purge = args.purge
-- Generate the "ago" string. If ago is the blank string, do nothing - this allows overriding of args.ago
-- in cases where the module is used to generate something like "where he has worked for the past 20 years."
local ago = args.ago or 'ago'
if ago and ago ~= '' then
ago = ' ' .. ago
elseif not ago then
ago = ' ago'
end
 
-- Add a purge link if something (usually "yes") is entered into the purge parameter
Line 78 ⟶ 97:
result_unit = timeUnits[ magnitude_num ][2]
end
result = result_num .. ' ' .. result_unit .. 'ago '-- ..Spaces for "ago" are added earlier.
else -- Future
if result_num == 1 then