formatSaveTime

  getting the time (hours:minutes:seconds) regardless of the format
time seconds




  formatSaveTime
At 14:56 26/06/99 -0500, you wrote:
>hello list,
>I'm trying to make an analog clock that matches the seconds hand with the
>system clock 

<snip>

>I thought to check the 6 and seventh integers to see what numbers they are,
>but the problem is that in the hours of 11 and 12, the seconds are displayed
>in the 7th and 8th integers.
>
>Is there a simple and efficient way to get my seconds hand working properly?
>thanks,
>

Hi Juan,

this looks like a job for the itemdelimiter. The position of the seconds part 
of the time string varies but it wil always be the third item of that string. 
On most systems that delimiter will be ":". So a first solution would be 
something similar to this:

on getSeconds  
  -- returns the seconds if the delimiter is ":"
  oldDelim = the itemDelimiter
  the itemDelimiter = ":"
  t = the long time
  s = integer(t.item[3])
  the itemDelimiter = oldDelim
  return s
end


But unfortunately, any user can easily change that via the control panel. So 
if you suspect a user might format the time like "23/59/59 " etc. you would 
have to test for possible delimiter. 
(This actually is just a clumsy workaround. Whatever a user might change in 
that control panel, the OS knows it and has a function to report it. But with 
director there still is no easy access of API functions like you would have 
with vb or toolbook or delphi or vc or... 
You could use an xtra like gluedll32 at updatestage to go that way. Or use an 
xtra to obtain the time directly.)

However, assuming that hardly anyone will choose a cipher to delimit hours, 
minutes and seconds you could defend your code against wrongly formatted input
by the handler below which returns the long time in a list:

from the MessWin:

set seconds = getLTime()[3]

put seconds
-- "02"


--- movieScript

on getLTime 
  -- returns the long time as a list [#hours,#minutes,#seconds]

  dL = []
  dS = ""
  
  t = the long time
  tn = t.count(#char)
  
  repeat with dPos = 1 to tn
    dChar = t.char[dPos]
    if (dChar = integer(dChar)) then
      dS = dS & dChar
    else
      append dL,dS
      dS = ""
    end if
  end repeat
  if dS <> "" then append dL,dS
  
  return dL
end


This second function takes about three times longer then the first solution, 
on an old Cyrix with 133 Mhz this means 1.8  vs. 0.6 milliseconds. This 
shouldn't affect the speed of your animation when called from an exitFrame.

Hmm. With date and time I always wonder which is the bit I didn't regard. 


Home shock + cgi Bits 'n pieces Director Lingo Shocklets Contact










pageID=l_formatSaveTime