Convert Lua UINT to hh:mm:ss I have found the convert_to function in the lua-user wiki, and I created the convert_to_time function which does what I want it to do. Which is, basically: Having a number, return its value in a Time format.

The values range is:  [0..863999] as we want the data in 0..24 hours format by step of 0.1 second. 

The code from the lua-user-wiki, had a step of 1 second so I had to change the base to fit my specifications, but because of that I've had to create too many conditions to be able to always print out the value I want. I had issues with printing 01:00:00 for example.

If someone of you can give it a view and suggest me a simpler way to achieve what I want in ALL situations I would appreciate it.

intervals={
 {"seconds",1}, --the "1" should never really get used but
 {"minutes",60},
 {"hours",60},
 {"days",24},
}

positions={}
for i=1,4 do
 positions[intervals[i][1]]=i
end

function convert_to(value, sourceunits, targetunits)

local sourcei, targeti = positions[sourceunits], positions[targetunits]
assert(sourcei and targeti)

if sourcei&lt;targeti then

  local base=10
  for i=sourcei+1,targeti do
    base=base*intervals[i][2]
  end

  return value/base

elseif sourcei&gt;targeti then

  local base=10
  for i=targeti+1,sourcei do
    base=base*intervals[i][2]
  end

  return value*base
else return value end
end


function convert_to_time(value)
  local returnString = "", horas, minutos, segundos

  horas = tostring(convert_to(value,"seconds","hours")) -- return : 12.888888889
  if(tonumber(string.match(horas, "%.(%w+)"))==nil) then return (horas ..":00:00") end
  minutos = tostring(convert_to("0."..string.match(horas, "%.(%w+)"),"hours","minutes")/10) -- returns : 53.33333334
  if(tonumber(string.match(minutos, "%.(%w+)"))==nil) then return (string.match(horas, "(%w+)%.") .. minutos ..":00") end
  segundos = tostring(convert_to("0."..string.match(minutos, "%.(%w+)"),"minutes","seconds")/10) -- returns : 20.0000000004

  horasStr = string.match(horas, "(%w+)%.")
  minutosStr = string.match(minutos, "(%w+)%.")
  if string.match(segundos, "%.") then
    segundosStr = string.match(segundos, "(%w+)%.")
  else
  segundosStr = segundos
  end

  -- Ñapa para que los numeros se vean en formato hh:mm:ss
  if (tonumber(horasStr) &lt; 10) then if (tonumber(horasStr)==nil) then horasStr = "00" end horasStr = "0"..horasStr end 
  if (tonumber(minutosStr) &lt; 10) then if (tonumber(minutosStr)==nil) then minutosStr = "00" end minutosStr = "0"..minutosStr end 
  if (tonumber(segundosStr) &lt; 10) then if (tonumber(segundosStr)==nil) then segundosStr = "00" end segundosStr = "0"..segundosStr end 

  returnString = horasStr .. ":" .. minutosStr .. ":" .. segundosStr

  return returnString

 end


You can test the code for this example:     


print(convert_to_time(36000))
A much simpler way is:

function convert_to_time(tenths)
  local hh = (tenths // (60 * 60 * 10)) % 24
  local mm = (tenths // (60 * 10)) % 60
  local ss = (tenths // 10) % 60
  local t = tenths % 10

  return string.format("%02d:%02d:%02d.%01d", hh, mm, ss, t)
end