AHHH TIME FORMAT!!!

OK, I need to convert a number, which is the number of seconds remaining for my timer, into a time format like hr:min:sec. The number of seconds is derived from one date subtracted from another ie:


set time_remain to the return_time - (current date)

so if i have 7200 seconds it should display 02:00:00

any input?

There are faster ways of doing this but this is the basic method:

Jon


[This script was automatically tagged for color coded syntax by Convert Script to Markup Code]

Just rambling:

You know, I’ve never cared for the “hours” and “minutes” constants. Whenever I see them in a script, my mind does a double-take. “hours” is a plural word, you would think it would have something to do with 2 or more hours, while in fact it is the number of seconds in a single hour. 60 * 60 is so much more immediatedly understood in my brain’s cognitive processing center.

Rambling over. :wink:

ok cool this will work, but it wont return for me… damn my newbness.

bah, nvm i figured it out thanks alot

damn
another error

ok here is the entire code for what I am working on, so you can get jist of the problem.



set the_time to (current date)

display dialog "Enter the number of hours you will be gone." default answer "" buttons {"Cancel", "OK"} default button 2
copy the result as list to {button_pressed, text_returned}

set away_time to the text_returned * 3600
set return_time to the_time + away_time

set blah to return_time as string
--display dialog blah



tell application "iChat"
	repeat with x from 1 to away_time * 60
		set time_remain to the return_time - (current date)
		my format_seconds(time_remain)
		set da_time to the format_seconds(time_remain)
		set status message to da_time & " hours till I return." as string
		delay 60
	end repeat
	
end tell


on format_seconds(time_remain)
	set the_hours to time_remain div (1 * hours)
	set the_minutes to (time_remain mod (1 * hours)) div (1 * minutes)
	set time_remain to time_remain mod (1 * minutes)
	if the_hours < 10 then set the_hours to "0" & the_hours
	if the_minutes < 10 then set the_minutes to "0" & the_minutes
	if time_remain < 10 then set time_remain to "0" & time_remain
	return "" & {the_hours, ":", the_minutes, ":", time_remain}
end format_seconds

the error i get is :
“iChat got an error: Can’t continue format_seconds.”

i dunno why it doesnt work

Your main problem was that you were calling a routine that you defined in your script from inside a tell block for iChat and it didn’t know how to handle that call. To get around that, prefix the call with “my” to let the script know you want to use your code, not the application’s. This is a bit cleaner code:

Jon


[This script was automatically tagged for color coded syntax by Convert Script to Markup Code]

ok, thanks urs is neat lookin :stuck_out_tongue:

I did change it to update every second otherwise u dont get the true timer effect, know wut i mean?

Maybe the s stands for seconds :slight_smile:

hours = hour seconds

I’m not a mod or anything, but was there a reason that you didn’t just continue this in iChat status based on a timer?

Wow, guardian34…that last post of yours was a big help to us all. The people around here who are actually helping fellow members don’t seem to care where someone posts their problems. Lighten up and try to hold your tongue until you can say something meaningful.

:rolleyes:

j

I have helped people here (and elsewhere). However, I will consider what you have said.

This does what you want