comp.lang.ada
 help / color / mirror / Atom feed
From: "Frank J. Lhota" <NOSPAM.lhota.adarose@verizon.net>
Subject: Re: milliseconds and delay until
Date: Wed, 11 Jun 2003 19:59:14 GMT
Date: 2003-06-11T19:59:14+00:00	[thread overview]
Message-ID: <mSLFa.3820$er5.1796@nwrdny02.gnilink.net> (raw)
In-Reply-To: bc7smt$357$04$1@news.t-online.com

"Thomas Bruns" <newsgroup@donbruno.de> wrote in message
news:bc7smt$357$04$1@news.t-online.com...
> Hello
>
> how can I handle the until delay statement, too do this: ????

Let us take one step back, and take a look at what the delay statement is
supposed to accomplish. There are two different types of time measurements:

- There are relative time values that specify the length of a span  of time,
e.g. "1 hour, 38 minutes, and 5.385 seconds", and
- There are absolute time values that specify a particular point in time,
e.g. "24 June 1987 06:58:05".

In Ada, the Standard type Duration is used to represent relative time
values. Duration is a real type representing the length of time in seconds.
The range of Duration must be large enough to represent plus or minus one
day.

The Time type defined in Ada.Calendar represents an absolute time value,
i.e. "24 June 1987 06:58:05". The Ada.Calendar package provides utilities
for handling Time values, including the Clock function that returns the
current time, and the various arithmentic operations between relative and
absolute time.

There are two forms of the delay statement. The relative delay statement
takes the form

    delay Number_Of_Seconds;

This form of the delay statement is used to delay for a certain time span,
For example, to delay for one minute, you could use the relative delay
statement

    delay 60.0;

The other form of the delay statement is the "delay until" statement. This
form delays until an absolute time is reached. It takes the

    delay until Time_Expression;

Where Time_Expression is an Ada type (such as Ada.Calendar.Time) that
represents an absolute time. For example, to delay until 12 June 2003, 6:30
in the morning, you could use the following "delay until" statement:

    procedure ...

       Secs_Per_Min  : constant := 60.0;
       Secs_Per_Hour : constant := 60 * Secs_Per_Min;

    begin

       delay until Time_Of(
          Year    => 2003,
          Month   => 06
          Day     => 12
          Seconds => 6 * Secs_Per_Hour + 30 * Secs_Per_Min );

    end;

Now on to your problem. If you wish to delay for a certain time span, e.g.
delay for a tenth of a second; you should use the relative delay statement:

    delay 0.1;

To delay until some absolute time, use the "delay until" statement. The
Ada.Calendar package has the utilities you need to compute that absolute
time. For example

    procedure ...

       The_Cows_Come_Home : Ada.Calendar.Time;

    begin

       -- Compute absolute time for "Delay Until" to be a tenth of a second
from now.
       The_Cows_Come_Home := Ada.Calendar.Clock  + 0.1;
       ...
       delay until The_Cows_Come_Home;

    end;






  parent reply	other threads:[~2003-06-11 19:59 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-06-11 18:31 milliseconds and delay until Thomas Bruns
2003-06-11 18:46 ` Jano
2003-06-11 18:58   ` Thomas Bruns
2003-06-11 19:29     ` Jano
2003-06-11 19:49 ` Simon Wright
2003-06-11 20:29   ` tmoran
2003-06-12  6:20   ` Dmitry A. Kazakov
2003-06-11 19:59 ` Frank J. Lhota [this message]
2003-06-12  3:06 ` Steve
2003-06-12 20:26   ` Simon Wright
2003-06-12 21:41     ` Martin Dowie
2003-06-14  6:04       ` Simon Wright
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox