[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Processes and time



>Hello there
>
>I'm working with Mac::Processes and I have a bit of problem.  I get the
>return from processLaunchDate() but I need to convert this into an
>actual date.  How do I go about doing that?  A typical number that this
>returns is f.e. 30845649, how do I get a real date from that?
>
>
>Sveinbjorn Thordarson
>Reykjavik, Iceland

Hi Sveinbjorn,

according to Inside Mac Vol. VI, the value returned from processLaunchDate
is the value of the 'Ticks' global variable at the time that the process
was launched. A tick is the sixtieths of a second. The 'Ticks' low-memory
global variable contains the number of ticks since the system last started
up. The Toolbox Event Manager (see Events.pm) provides the routine

    " TICKS = TickCount()
           Returns the current time in 60th of a second since startup  "

which reads out the global variable 'Ticks' (you may also use 'LMGetTicks'
from the modul LowMem.pm).

Now, you need the startup date/time. The current time is stored in the
low-memory global variable 'Time'. This variable contains the seconds since
midnight, Jan 1, 1904 (a longInt value). You will use the routine LMGetTime
(see LowMem.pm) to get the value. In MacPerl, of course, you may also use
the Perl builtin function time().

So, to get the startup time:
____
use Mac::LowMem;

$current_Time = time; # LMGetTime;
$startup_Ticks = LMGetTicks;
$startup_Sec = ($startup_Ticks - ($startup_Ticks % 60)) / 60; # avoid floating
                                                              # point
$startup_Time = $current_Time - $startup_Sec;
$startup_string = localtime($startup_Time);
print "StartUp of Macintosh at $startup_string \n";
____

localtime(...) converts the seconds to a date/time string.

With this information, you should be able to compute the date/time the
process launched (this is left as an exercise to the reader :-) ).

Best regards

--Thomas



# ===== Want to unsubscribe from this list?
# ===== Send mail with body "unsubscribe" to macperl-request@macperl.org