# converting short time to seconds

Sarah Reichelt sarah.reichelt at gmail.com
Sat Sep 17 02:35:34 EDT 2011

> This code rather than my prose probably explains better what I'm after:
>
> on mouseUp
>   set the twelveHourTime to false
>   put the short time into tSomeClockTimeTodayInSeconds
>   convert tSomeClockTimeTodayInSeconds to seconds
>   put tSomeClockTimeTodayInSeconds into tSameClockTimeTomorrowInSeconds
>   put 86400 into tNumberOfSecondsInOneDay
>   add tNumberOfSecondsInOneDay to tSameClockTimeTomorrowInSeconds
>   send "StartSomeLoopingCycleThatEventuallyTriggersAChimeSound" to me
> in 0 milliseconds
> end mouseUp
>
>
> Here's the why. I have a stack that takes a list of clock-times and
> plays a chime-sound at each clock-time. When the last clock-time has
> played, the list of clock-times is reloaded for the stack to replay
> the chimes the next day and the next ad infinitum. However, to avoid
> working with dates, I figured that adding the number of seconds in one
> day to each of the clock-times would do the trick.
>
> Is there a problem with my logic?

I see a couple of issues with your time calculations, but the main
thing is that once you calculate the time tomorrow, you don't actually
use that time. You call
StartSomeLoopingCycleThatEventuallyTriggersAChimeSound in 0
milliseconds and unless  tSameClockTimeTomorrowInSeconds is a global,
it will never be used.

When getting the starting time, I presume the reason you get the short
time and convert to seconds instead of just getting the seconds is so
that you get the time exactly on a minute. However your addition of
86400 will fail twice a year if you live in a part of the world that
has daylight savings, as the change-over days are longer or shorter
than this.

For time calculations, you are better using the dateItems which
accounts for this sort of stuff automatically.

Try something like this:

put the seconds in to tDateTime
convert tDateTime to dateItems
put 0 into item 6 of tDateTime    -- set seconds to 0
add 1 to item 3 of tDateTime      -- increment the day
convert tDateTime to seconds
put tDateTime - the seconds into tSameClockTimeTomorrowInSeconds
send "doSomething" to me in tSameClockTimeTomorrowInSeconds seconds

Cheers,
Sarah