ascobol

Asco Utility Api

Feb 28th, 2014
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.91 KB | None | 0 0
  1. -- Utility Api "ascoUtilityApi"
  2.  
  3. --Seconds to formatted string
  4. function formatSeconds(sec)
  5.     local base = sec
  6.     local seconds = 0
  7.     local minutes = 0
  8.     local hours = 0
  9.        
  10.     if(base >= 3600) then
  11.         hours = math.floor(base / 3600)
  12.         base = base % 3600
  13.     end
  14.    
  15.     if(base >= 60) then
  16.         minutes = math.floor(base / 60)
  17.         base = base % 60
  18.     end
  19.    
  20.     seconds = base
  21.        
  22.     local s = ""
  23.     if (hours > 0) then
  24.         s = s .. hours .. " hour"
  25.         if(hours ~= 1) then
  26.             s = s .. "s"
  27.         end
  28.         s = s .. " "
  29.     end
  30.     if (minutes > 0) then
  31.         s = s .. minutes .. " minute"
  32.         if(minutes ~= 1) then
  33.             s = s .. "s"
  34.         end
  35.         s = s .. " "
  36.     end
  37.     if (seconds > 0 or (hours == 0 and minutes == 0 and seconds == 0)) then
  38.         s = s .. seconds .. " second"
  39.         if(seconds ~= 1) then
  40.             s = s .. "s"
  41.         end
  42.         s = s .. " "
  43.     end
  44.     return s
  45. end
  46.  
  47. --Checks if a number is even
  48. function isEvenNumber(number)
  49.     return (tonumber(number) % 2 == 0)
  50. end
Advertisement
Add Comment
Please, Sign In to add comment