"मोड्युल:TimeAgo" को बिचमी भिन्नता
Content deleted Content added
imported>Mr. Stradivarius add ability to spell out numbers with new parameters "spellout" and "spelloutmax" |
imported>Mr. Stradivarius allow args.ago to suppress "time" in future dates, and do some refactoring |
||
पंक्ति १:
-- Replacement for [[Template:Time ago]]
local getArgs = require('Module:Arguments').getArgs▼
local numberSpell = require('Module:NumberSpell')._main
local yesno = require('Module:Yesno')
Line ६ ⟶ ५:
local p = {}
-- Table to convert entered text values to numeric values.▼
function p.main( frame )▼
timeText = {▼
['seconds'] = 1,▼
valueFunc = function( k, v )▼
['minutes'] = 60,▼
if v then▼
['hours'] = 3600,▼
v = v:match( '^%s*(.-)%s*$' ) -- Trim whitespace.▼
['days'] = 86400,▼
if k == 'ago' or v ~= '' then▼
['weeks'] = 604800,▼
return v▼
['months'] = 2678400,▼
end▼
['years'] = 31557600▼
end▼
}▼
return nil▼
end▼
-- Table containing tables of possible units to use in output.▼
})▼
timeUnits = {▼
return p._main( args )▼
[1] = { 'second', 'seconds', "second's", "seconds'" },▼
end▼
[60] = { 'minute', 'minutes', "minutes'", "minutes'" },▼
[3600] = { 'hour', 'hours', "hour's", "hours'" },▼
[86400] = { 'day', 'days', "day's", "days'" },▼
[604800] = { 'week', 'weeks', "week's", "weeks'" },▼
[2678400] = { 'month', 'months', "month's", "months'" },▼
[31557600] = { 'year', 'years', "year's", "years'" }▼
}▼
function p._main( args )
-- Initialize variables
local lang = mw.language.getContentLanguage()
local auto_magnitude_num
local min_magnitude_num
Line ३५ ⟶ ४०:
local spell_out_max = args.spelloutmax
end▼
-- Add a purge link if something (usually "yes") is entered into the purge parameter
if purge then
Line १०२ ⟶ ९८:
punctuation_key = 2
end
else
suffix = ' ' .. (args.ago or 'ago')
▲ end
else -- Future
if
if result_num == 1 then
punctuation_key = 1
else
punctuation_key = 2
▲ end
else
if result_num == 1 then
punctuation_key = 3
else
punctuation_key = 4
end
▲ suffix = ' time'
end
result_unit = timeUnits[ magnitude_num ][ punctuation_key ]
Line १२८ ⟶ १३७:
end
▲function p.main( frame )
▲-- Table to convert entered text values to numeric values.
▲timeText = {
▲ valueFunc = function( k, v )
▲ ['seconds'] = 1,
▲ if v then
▲ ['minutes'] = 60,
▲ v = v:match( '^%s*(.-)%s*$' ) -- Trim whitespace.
▲ ['hours'] = 3600,
▲ if k == 'ago' or v ~= '' then
▲ ['days'] = 86400,
▲ return v
▲ ['weeks'] = 604800,
▲ end
▲ ['months'] = 2678400,
end
▲ ['years'] = 31557600
▲ return nil
▲}
end,
wrappers = 'Template:Time ago'
▲-- Table containing tables of possible units to use in output.
▲ })
▲timeUnits = {
▲ return p._main( args )
▲ [1] = { 'second', 'seconds', "second's", "seconds'" },
▲end
▲ [60] = { 'minute', 'minutes', "minutes'", "minutes'" },
▲ [3600] = { 'hour', 'hours', "hour's", "hours'" },
▲ [86400] = { 'day', 'days', "day's", "days'" },
▲ [604800] = { 'week', 'weeks', "week's", "weeks'" },
▲ [2678400] = { 'month', 'months', "month's", "months'" },
▲ [31557600] = { 'year', 'years', "year's", "years'" }
▲}
return p
|