Module:Time ago: Difference between revisions

Most of the output should be right now...still needs a lot of improvement.
m (Messed up capitalization of error class.)
(Most of the output should be right now...still needs a lot of improvement.)
Line 37:
local min_magnitude_num
local result
if frame.args.ago then ago = frame.args.ago else ago = 'ago' end
if magnitude then
Line 51 ⟶ 52:
if ( math.floor( math.abs( timeDiff ) / 5356800 ) > 0 ) then auto_magnitude_num = 5 end
if ( math.floor( math.abs( timeDiff ) / 63115200 ) > 0 ) then auto_magnitude_num = 6 end
if min_magnitude then min_magnitude_num = timeText[min_magnitude] else min_magnitude_num = 0-1 end
end
local magnitude_num = math.max( min_magnitude_num - 1, auto_magnitude_num )
if ( timeDiff >= 0 ) then
if ( magnitude_num == 0 ) then result = math.floor ( math.abs( timeDiff ) ) .. ' ' .. lang:plural( math.floor ( math.abs( timeDiff ) ), { 'second', 'seconds' } )
elseif ( magnitude_num == 1 ) then result = math.floor ( math.abs( timeDiff ) / 60 ) .. ' ' .. lang:plural( math.floor ( math.abs( timeDiff ) / 60 ), { 'minute', 'minutes' } )
elseif ( magnitude_num == 2 ) then result = math.floor ( math.abs( timeDiff ) / 3600 ) .. ' ' .. lang:plural( math.floor ( math.abs( timeDiff ) / 3600 ), { 'hour', 'hours' } )
elseif ( magnitude_num == 3 ) then result = math.floor ( math.abs( timeDiff ) / 86400 ) .. ' ' .. lang:plural( math.floor ( math.abs( timeDiff ) / 86400 ), { 'day', 'days' } )
elseif ( magnitude_num == 4 ) then result = math.floor ( math.abs( timeDiff ) / 604800 ) .. ' ' .. lang:plural( math.floor ( math.abs( timeDiff ) / 604800 ), { 'week', 'weeks' } )
elseif ( magnitude_num == 5 ) then result = math.floor ( math.abs( timeDiff ) / 2678400 ) .. ' ' .. lang:plural( math.floor ( math.abs( timeDiff ) / 2678400 ), { 'month', 'months' } )
elseif ( magnitude_num == 6 ) then result = math.floor ( math.abs( timeDiff ) / 31557600 ) .. ' ' .. lang:plural( math.floor ( math.abs( timeDiff ) / 31557600 ), { 'year', 'years' } ) end
result = result .. ' ' .. ago
else
if ( magnitude_num == 0 ) then result = math.floor ( math.abs( timeDiff ) ) .. ' ' .. lang:plural( math.floor ( math.abs( timeDiff ) ), { 'second\'s', 'seconds\'' } )
elseif ( magnitude_num == 1 ) then result = math.floor ( math.abs( timeDiff ) / 60 ) .. ' ' .. lang:plural( math.floor ( math.abs( timeDiff ) / 60 ), { 'minute\'s', 'minutes\'' } )
elseif ( magnitude_num == 2 ) then result = math.floor ( math.abs( timeDiff ) / 3600 ) .. ' ' .. lang:plural( math.floor ( math.abs( timeDiff ) / 3600 ), { 'hour\'s', 'hours\'' } )
elseif ( magnitude_num == 3 ) then result = math.floor ( math.abs( timeDiff ) / 86400 ) .. ' ' .. lang:plural( math.floor ( math.abs( timeDiff ) / 86400 ), { 'day\'s', 'days\'' } )
elseif ( magnitude_num == 4 ) then result = math.floor ( math.abs( timeDiff ) / 604800 ) .. ' ' .. lang:plural( math.floor ( math.abs( timeDiff ) / 604800 ), { 'week\'s', 'weeks\'' } )
elseif ( magnitude_num == 5 ) then result = math.floor ( math.abs( timeDiff ) / 2678400 ) .. ' ' .. lang:plural( math.floor ( math.abs( timeDiff ) / 2678400 ), { 'month\'s', 'months\'' } )
elseif ( magnitude_num == 6 ) then result = math.floor ( math.abs( timeDiff ) / 31557600 ) .. ' ' .. lang:plural( math.floor ( math.abs( timeDiff ) / 31557600 ), { 'year\'s', 'years\'' } ) end
result = result .. ' time'
end
return result .. purge
Anonymous user