Results 1 to 1 of 1

Thread: Convert number of seconds to a TTS friendly format

  1. #1
    Join Date
    Apr 2005
    Posts
    46

    Default Convert number of seconds to a TTS friendly format

    I use the code below to announce the values of my Elk M1 counters, which are used as timers.

    Code:
    local function FormatForTTS(sSeconds)
    	local nSeconds = tonumber(sSeconds)
    	local sTTS = ""
    	if nSeconds < 60 then
    		return "timer has expired"
    	else
    		nHours = math.floor(nSeconds/3600)
    
    		if nHours > 1 then
    		  wHours = nHours.." hours"
    		end
    		if nHours == 1 then
    		  wHours = "1 hour"
    		end
    		if nHours == 0 then
    		  wHours = ""
    		end
    		
    		nMins = math.floor(nSeconds/60 - (nHours*60));
    
    		if nMins > 1 then
    		  wMins = nMins.." minutes"
    		end
    		if nMins == 1 then
    		  wMins = "1 minute"
    		end
    		if nMins == 0 then
    		  wMins = ""
    		end
    		
    		nSecs = math.floor(nSeconds - nHours*3600 - nMins *60);
    		
    		if nSecs > 1 then
    		  wSecs = nSecs.." seconds"
    		end
    		if nSecs == 1 then
    		  wSecs = "1 second"
    		end
    		if nSecs == 0 then
    		  wSecs = ""
    		end
    
    		-- putting it all together now
    		if nHours > 0 then
    		  sTTS = sTTS .. wHours
    		  if nMins  > 0 then
    		    sTTS = sTTS .. " and "
    		  end
    		end
    		
    		if nMins > 0 then
    		  sTTS = sTTS .. wMins
    		  if nSecs > 0 then
    		    sTTS = sTTS .. " and "
    		  end
    		end
    		
    		if nSecs > 0 then
    		  sTTS = sTTS .. wSecs
    		end
    		
    		return "Time remaining: " .. sTTS
    	end
    end
    Last edited by etron; November 7th, 2008 at 12:47 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •