#

Listato 3

Utility tempo per Turbo Pascal
 
unit timestat;

interface

type system_time = record
     year,month,day,hour,min,sec,sec100 : word;
     end;

var  packed_start_time : longint;
     start_time : system_time;

procedure get_system_time(var t: system_time);
procedure pack_system_time(var t: system_time; var p: longint);
procedure unpack_system_time(p: longint; var t: system_time);
procedure write_date(var t: system_time);
procedure write_time(var t: system_time);
procedure start_job_time;
procedure end_job_time;
procedure elapsed_time(var tstart,tend: system_time);

implementation

uses dos;

procedure get_system_time(var t: system_time);
var dow : word;
begin with t do begin
getdate(year,month,day,dow);
gettime(hour,min,sec,sec100);
end; end;

procedure pack_system_time(var t: system_time; var p: longint);
var tmp : datetime;
begin
tmp.year := t.year;
tmp.month := t.month;
tmp.day := t.day;
tmp.hour := t.hour;
tmp.min := t.min;
tmp.sec := t.sec;
packtime(tmp,p);
p := p * 100 + t.sec100
end;

procedure unpack_system_time(p: longint; var t: system_time);
var tmp : datetime;
begin
t.sec100 := p mod 100;  p := p div 100;
unpacktime(p,tmp);
t.year := tmp.year;
t.month := tmp.month;
t.day := tmp.day;
t.hour := tmp.hour;
t.min := tmp.min;
t.sec := tmp.sec;
end;

procedure write_date(var t: system_time);
begin with t do
write(day,'/',month,'/',year);
end;

procedure write_time(var t: system_time);
begin with t do
write(hour:2,':',min:2,':',sec:2,'.',sec100:2);
end;

procedure start_job_time;
begin
write('Program started ');  write_date(start_time);
write(' at ');  write_time(start_time);
writeln;
end;

procedure end_job_time;
var tmp: system_time;
begin
get_system_time(tmp);
write('Job terminated ');  write_date(tmp);
write(' at  ');  write_time(tmp);
writeln;
end;

procedure elapsed_time(var tstart,tend: system_time);
var ts,te : longint;
    elapsed : system_time;
    tm,x : string[10];
begin
pack_system_time(tstart,ts);
pack_system_time(tend,te);
unpack_system_time(te-ts,elapsed);
tm[0] := #0;
with elapsed do begin
   if (min > 0) or (hour > 0) then begin
     str(min,x);
     tm := x + 'm ';
     end;
   if hour > 0 then begin
     str(hour,x);
     tm := x + 'h ' + tm;
     end;
   write(tm,sec,'.',sec100:2,'sec');
   end;
end;

begin
get_system_time(start_time);
pack_system_time(start_time,packed_start_time);
end.
Inizio pagina
Home page
 
Creative Commons  License BY-NC-SA
Ove non diversamente specificato i contenuti del sito sono rilasciati con licenza Creative Commons BY-NC-SA 4.0 

Copyright © 2007-2020 The Strawberry Field - Roberto Ceccarelli