"मोड्युल:TimeAgo" को बिचमी भिन्नता

Content deleted Content added
imported>Mr. Stradivarius
allow blank values of |ago=
imported>Mr. Stradivarius
add ability to spell out numbers with new parameters "spellout" and "spelloutmax"
पंक्ति १:
-- Replacement for [[Template:Time ago]]
local getArgs = require('Module:Arguments').getArgs
local numberSpell = require('Module:NumberSpell')._main
local yesno = require('Module:Yesno')
 
local p = {}
Line ३० ⟶ ३२:
local min_magnitude = args.min_magnitude
local purge = args.purge
local spell_out = args.spellout
local spell_out_max = args.spelloutmax
-- Generate the "ago" string. If ago is the blank string, do nothing - this allows overriding of args.ago
Line ४८ ⟶ ५२:
 
-- Check that the entered timestamp is valid. If it isn't, then give an error message.
local noError, inputTime = pcall( lang.formatDate, lang, 'U', args[1], true )
if not noError then
return '<strong class="error">Error: first parameter cannot be parsed as a date or time.</strong>'
Line ५४ ⟶ ५८:
 
-- Store the difference between the current time and the inputted time, as well as its absolute value.
local timeDiff = lang:formatDate( 'U', nil, true ) - inputTime
local absTimeDiff = math.abs( timeDiff )
 
Line ६३ ⟶ ६७:
-- Calculate the appropriate unit of time if it was not specified as an argument.
local autoMagnitudeData = {
{ denom = 63115200, amn = 31557600 },
{ denom = 5356800, amn = 2678400 },
{ denom = 172800, amn = 86400 },
{ denom = 7200, amn = 3600 },
{ denom = 120, amn = 60 }
}
for i, t in ipairs( autoMagnitudeData ) do
if absTimeDiff / t.denom >= 1 then
auto_magnitude_num = t.amn
Line ९१ ⟶ ९५:
local result_num = math.floor ( absTimeDiff / magnitude_num )
 
local punctuation_key, suffix
if timeDiff >= 0 then -- Past
if result_num == 1 then
punctuation_key = 1
result_unit = timeUnits[ magnitude_num ][1]
else
punctuation_key = 2
result_unit = timeUnits[ magnitude_num ][2]
end
suffix = ago
result = result_num .. ' ' .. result_unit .. ago -- Spaces for "ago" are added earlier.
else -- Future
if result_num == 1 then
punctuation_key = 3
result_unit = timeUnits[ magnitude_num ][3]
else
punctuation_key = 4
result_unit = timeUnits[ magnitude_num ][4]
end
resultsuffix = result_num .. ' ' .. result_unit .. ' time'
end
result_unit = timeUnits[ magnitude_num ][1 punctuation_key ]
 
-- Convert numerals to words if appropriate.
spell_out_max = tonumber( spell_out_max ) -- Would cause script errors if not a number.
local result_num_text
if ( spell_out == 'auto' and 1 <= result_num and result_num <= 9 and result_num <= ( spell_out_max or 9 ) )
or ( yesno( spell_out ) and 1 <= result_num and result_num <= 100 and result_num <= ( spell_out_max or 100 ) )
then
result_num_text = numberSpell( result_num )
else
result_num_text = tostring( result_num )
end
 
result = result_numresult_num_text .. ' ' .. result_unit .. agosuffix -- Spaces for "ago"suffix arehave been added in earlier.
return result .. purge
end
"https://dty.wikipedia.org/wiki/मोड्युल:TimeAgo" बठे निकालियाऽ