Module:Time ago: Difference between revisions
Jump to navigation
Jump to search
Content added Content deleted
(add ability to spell out numbers with new parameters "spellout" and "spelloutmax") |
(allow args.ago to suppress "time" in future dates, and do some refactoring) |
||
Line 1: | Line 1: | ||
-- Replacement for [[Template:Time ago]] |
-- Replacement for [[Template:Time ago]] |
||
⚫ | |||
local numberSpell = require('Module:NumberSpell')._main |
local numberSpell = require('Module:NumberSpell')._main |
||
local yesno = require('Module:Yesno') |
local yesno = require('Module:Yesno') |
||
Line 6: | Line 5: | ||
local p = {} |
local p = {} |
||
⚫ | |||
⚫ | |||
⚫ | |||
local args = getArgs( frame, { |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
function p._main( args ) |
function p._main( args ) |
||
-- Initialize variables |
-- Initialize variables |
||
local lang = mw.language.getContentLanguage() |
local lang = mw.language.getContentLanguage() |
||
local ago |
|||
local auto_magnitude_num |
local auto_magnitude_num |
||
local min_magnitude_num |
local min_magnitude_num |
||
Line 35: | Line 40: | ||
local spell_out_max = args.spelloutmax |
local spell_out_max = args.spelloutmax |
||
-- 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." |
|||
ago = args.ago |
|||
if ago and ago ~= '' then |
|||
ago = ' ' .. ago |
|||
elseif not ago then |
|||
ago = ' ago' |
|||
⚫ | |||
-- Add a purge link if something (usually "yes") is entered into the purge parameter |
-- Add a purge link if something (usually "yes") is entered into the purge parameter |
||
if purge then |
if purge then |
||
Line 102: | Line 98: | ||
punctuation_key = 2 |
punctuation_key = 2 |
||
end |
end |
||
if args.ago == '' then |
|||
⚫ | |||
else |
|||
suffix = ' ' .. (args.ago or 'ago') |
|||
⚫ | |||
else -- Future |
else -- Future |
||
if |
if args.ago == '' then |
||
suffix = '' |
|||
if result_num == 1 then |
|||
punctuation_key = 1 |
|||
else |
|||
punctuation_key = 2 |
|||
⚫ | |||
else |
else |
||
suffix = ' time' |
|||
if result_num == 1 then |
|||
punctuation_key = 3 |
|||
else |
|||
punctuation_key = 4 |
|||
⚫ | |||
end |
end |
||
⚫ | |||
end |
end |
||
result_unit = timeUnits[ magnitude_num ][ punctuation_key ] |
result_unit = timeUnits[ magnitude_num ][ punctuation_key ] |
||
Line 128: | Line 137: | ||
end |
end |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
end |
|||
⚫ | |||
⚫ | |||
⚫ | |||
end, |
|||
wrappers = 'Template:Time ago' |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
return p |
return p |