Module:Time ago: Difference between revisions

Indent if statements. Blocks inside if statements have lexical scope, so it is a lot clearer which block has which scope if you indent. (Also see Wikipedia:Lua style guide.)
m (and whoops, wrong html tag :P)
(Indent if statements. Blocks inside if statements have lexical scope, so it is a lot clearer which block has which scope if you indent. (Also see Wikipedia:Lua style guide.))
Line 43:
else
-- Calculate the appropriate unit of time if it was not specified as an argument.
if ( math.floor( absTimeDiff / 120 ) > 0 ) then auto_magnitude_num = 60 else auto_magnitude_num = 1 end
if ( math.floor( absTimeDiff / 7200 ) > 0 ) then auto_magnitude_num = 3600 end60
else
if ( math.floor( absTimeDiff / 172800 ) > 0 ) then auto_magnitude_num = 86400 end
if ( math.floor( absTimeDiff / 5356800 ) > 0 ) then auto_magnitude_num = 2678400 end1
end
if ( math.floor( absTimeDiff / 63115200 ) > 0 ) then auto_magnitude_num = 31557600 end
if math.floor( absTimeDiff / 7200 ) > 0 then
if min_magnitude then min_magnitude_num = timeText[min_magnitude] else min_magnitude_num = -1 end
auto_magnitude_num = 3600
end
if ( math.floor( absTimeDiff / 172800 ) > 0 ) then auto_magnitude_num = 86400 end
auto_magnitude_num = 86400
end
if math.floor( absTimeDiff / 5356800 ) > 0 then
auto_magnitude_num = 2678400
end
if ( math.floor( absTimeDiff / 63115200 ) > 0 ) then auto_magnitude_num = 31557600 end
auto_magnitude_num = 31557600
end
if min_magnitude then
if min_magnitude then min_magnitude_num = timeText[min_magnitude] else min_magnitude_num = -1 end
else
min_magnitude_num = -1
end
end
 
if not min_magnitude_num then min_magnitude_num = 1 end -- Default to seconds if an invalid magnitude is entered.
min_magnitude_num = 1
end -- Default to seconds if an invalid magnitude is entered.
 
local magnitude_num = math.max( min_magnitude_num, auto_magnitude_num )
local result_num = math.floor ( absTimeDiff / magnitude_num )
 
if ( timeDiff >= 0 ) then -- Past
if result_num == 1 then result_unit = timeUnits[ magnitude_num ][1] else result_unit = timeUnits[ magnitude_num ][2] end
result_unit = timeUnits[ magnitude_num ][1]
else
result_unit = timeUnits[ magnitude_num ][2]
end
result = result_num .. ' ' .. result_unit .. ' ' .. ago
else -- Future
if result_num == 1 then result_unit = timeUnits[ magnitude_num ][3] else result_unit = timeUnits[ magnitude_num ][4] end
result_unit = timeUnits[ magnitude_num ][3]
else
result_unit = timeUnits[ magnitude_num ][4]
end
result = result_num .. ' ' .. result_unit .. ' time'
end