Clocks PreviousNext

A clock is an object which knows about a particular point on the time axis known as now. All times before that point are considered in the past and times beyond it are in the future.

Abstract Clocks

DT_CLOCK is a deferred class offering features such as time_now, date_now and date_time_now which can provide today's date and the current time according to the clock's criterion. Three other features, set_time_to_now, set_date_to_now and set_date_time_to_now, allow times, dates and date/times to be reset to the clock's current time.

System Clocks

Typically programs need to access the current time of the computer they are running on. That's what class DT_SYSTEM_CLOCK is for. This class is an heir of class DT_CLOCK and implements its deferred features so that the current local time of the system is returned. The typical way to invoke the system clock is to inherit from DT_SHARED_SYSTEM_CLOCK and call the once function system_clock.

DT_SYSTEM_CLOCK is implemented using the time facilities provided by each supported Eiffel compiler. With SmallEiffel it uses class BASIC_TIME which is in the lib_std cluster. This cluster also contains the kernel classes so it should already be included in your loadpath file. With Visual Eiffel it uses class TIMESTAMP from $VE_LIB/TimeDate. This cluster has been added to $GOBO/library/cluster.es, therefore having a line as follows in the ESD file should be enough:

    -- Gobo Eiffel Library
[Gobo    "$GOBO/library"] end

With Halstenbach it uses external C functions used in class SYSTEM_CLOCK and already included in the Eiffel runtime. There is therefore no other addition needed to the Ace file. Finally with ISE Eiffel it uses C functions which are available in $GOBO/library/time/include. So the following lines should be added to the external clause of the Ace file:

external
    include_path: "$GOBO/library/time/include" 

There is an example using system clock in $GOBO/example/time/clock. You can have a look at it to see the various Ace files, ESD files and loadpath files and possibly use them as a starting point.

Customizable Clocks

With the design of the clock classes, it is quite easy to write user-customized clocks by inheriting from DT_CLOCK and giving an implementation to the deferred features set_time_to_now, set_date_to_now and set_date_time_to_now. An example of a possible customizable clock is a clock which could run twice faster than the regular system clock for instance. This kind of clock can be useful in order to run simulation tests driven by time events. If the clock runs much faster than the system clock then tests which may normally last several hours or days will finish in a reasonable amount of time. Another application of customizable clocks is a clock which runs at the same speed as the system clock, but returns dates and times in the past or in the future. This could have been used for example to check that a program was Y2K compliant just by readjusting the clock to just before midnight on 31 December 1999. There are certainly many other examples where customizable clocks can be useful.


Copyright © 2001, Eric Bezault
mailto:
ericb@gobosoft.com
http:
//www.gobosoft.com
Last Updated: 10 April 2001

HomeTocPreviousNext