Module:Infobox Tools: Difference between revisions

Adding a function to convert setup_time to just a number
No edit summary
(Adding a function to convert setup_time to just a number)
 
Line 346:
return clean_str;
end
 
--Take the free-form setup_time field and convert it to a single numeric value
function str.setup_time_to_minutes(frame)
local str = tostring(frame.args[1]);
--Prepend "9999" to the string in case they didn't enter any digits
--This will make it easy to identify games with no digits in the setup_time field
--Appending "zzz" to the end to prevent errors when looking past a digit at the end
str = 9999 .. " " .. str .. "zzz"
num = 0;
--Find the last set of numeric digits in the string
for w in string.gmatch(str, "%d+") do
num = w;
end
--Find the position of the digits we found above
a, b = string.find(str, num)
--Get all of the text after the digits we found
text = string.sub(str, b+1, -1);
--Get the first 3 letters in the text above
units = string.sub(text, string.find(text, "%a%a%a"))
--Check if they likely entered seconds instead of minutes
if string.lower(units) == 'sec' then
--Divide the seconds by 60 and round up
num = math.ceil(num/60)
end
--Return the number of minutes without anything else
return num;
end