The execution of a delay statement evaluates the simple expression, and suspends further execution of the task that executes the delay statement, for at least the duration specified by the resulting value.

delay_statement ::= delay simple_expression;

The simple expression must be of the predefined fixed point type DURATION; its value is expressed in seconds; a delay statement with a negative value is equivalent to a delay statement with a zero value.

Any implementation of the type DURATION must allow representation of durations (both positive and negative) up to at least 86400 seconds (one day); the smallest representable duration, DURATION'SMALL must not be greater than twenty milliseconds (whenever possible, a value not greater than fifty microseconds should be chosen). Note that DURATION'SMALL need not correspond to the basic clock cycle, the named number SYSTEM.TICK (see 13.7).

The definition of the type TIME is provided in the predefined library package CALENDAR. The function CLOCK returns the current value of TIME at the time it is called. The functions YEAR, MONTH, DAY and SECONDS return the corresponding values for a given value of the type TIME; the procedure SPLIT returns all four corresponding values. Conversely, the function TIME_OF combines a year number, a month number, a day number, and a duration, into a value of type TIME. The operators "+" and "-" for addition and subtraction of times and durations, and the relational operators for times, have the conventional meaning.

The exception TIME_ERROR is raised by the function TIME_OF if the actual parameters do not form a proper date. This exception is also raised by the operators "+" and "-" if, for the given operands, these operators cannot return a date whose year number is in the range of the corresponding subtype, or if the operator "-" cannot return a result that is in the range of the type DURATION.

package CALENDAR is type TIME is private;

subtype YEAR_NUMBER is INTEGER range 1901 .. 2099; subtype MONTH_NUMBER is INTEGER range 1 .. 12; subtype DAY_NUMBER is INTEGER range 1 .. 31; subtype DAY_DURATION is DURATION range 0.0 .. 86_400.0;

function CLOCK return TIME;

function YEAR (DATE : TIME) return YEAR_NUMBER; function MONTH (DATE : TIME) return MONTH_NUMBER; function DAY (DATE : TIME) return DAY_NUMBER; function SECONDS(DATE : TIME) return DAY_DURATION;

procedure SPLIT (DATE : in TIME; YEAR : out YEAR_NUMBER; MONTH : out MONTH_NUMBER; DAY : out DAY_NUMBER; SECONDS : out DAY_DURATION);

function TIME_OF(YEAR : YEAR_NUMBER; MONTH : MONTH_NUMBER; DAY : DAY_NUMBER; SECONDS : DAY_DURATION := 0.0) return TIME;

function "+" (LEFT : TIME; RIGHT : DURATION) return TIME; function "+" (LEFT : DURATION; RIGHT : TIME) return TIME; function "-" (LEFT : TIME; RIGHT : DURATION) return TIME; function "-" (LEFT : TIME; RIGHT : TIME) return DURATION;

function "<" (LEFT, RIGHT : TIME) return BOOLEAN; function "<=" (LEFT, RIGHT : TIME) return BOOLEAN; function ">" (LEFT, RIGHT : TIME) return BOOLEAN; function ">=" (LEFT, RIGHT : TIME) return BOOLEAN;

TIME_ERROR : exception; -- can be raised by TIME_OF, "+", and "-"

private -- implementation-dependent end;

Examples:

delay 3.0; -- delay 3.0 seconds

declare use CALENDAR; -- INTERVAL is a global constant of type DURATION NEXT_TIME : TIME := CLOCK + INTERVAL; begin loop delay NEXT_TIME - CLOCK; -- some actions NEXT_TIME := NEXT_TIME + INTERVAL; end loop; end;

Notes:

The second example causes the loop to be repeated every INTERVAL seconds on average. This interval between two successive iterations is only approximate. However, there will be no cumulative drift as long as the duration of each iteration is (sufficiently) less than INTERVAL.

References: duration, fixed point type, function call, library unit, operator, package, private type, relational operator, simple expression, statement, task, type.