I have a string variable that I have to round up to 5 min interval but to keep it as string, example: 12:23am should be 12:25am 12:58pm should be 01:00pm 11:59am should be 12:00pm. I have tried this in lua, but it is not good and I am sure there is a better way to to this. Maybe someone can guide me or possibly help. Here is what I have done:
startRoundH=string.sub(var,1,2)
startRoundM1=string.sub(var,4,4)
startRoundM2=string.sub(var,5,5)
startAMPM=string.lower(string.sub(var,6,7))
if(tonumber(startRoundM2))<=2 then startRoundM2="0"
elseif(tonumber(startRoundM2)>2 and tonumber(startRoundM2)<=7) then startRoundM2="5"
elseif (tonumber(startRoundM2)==8 or tonumber(startRoundM2)==9) then
startRoundM2="0"
if(tonumber(startRoundM1)~=5) then startRoundM1=tonumber(startRoundM1)+1
else
startRoundM1="0"
if(tonumber(startRoundH)<9) then startRoundH=tonumber(startRoundH)+1 startRoundH="0"..startRoundH
elseif(tonumber(startRoundH)==10 or tonumber(startRoundH)==9) then startRoundH=tonumber(startRoundH)+1
elseif (tonumber(startRoundH)==11) then
startRoundH="12"
if(startAMPM=="am") then startAMPM="pm" else startAMPM="am" end
elseif (tonumber(startRoundH)==12) then startRoundH="01" end
end
end
Thank you!