Time¶

Usage

use Time;


This module provides support for querying wall time in the local timezone and implements a record Timer that provides basic stopwatch behavior. The stopwatch has the potential for microsecond resolution and is intended to be useful for performance testing.

enum TimeUnits { microseconds, milliseconds, seconds, minutes, hours }

Specifies the units to be used when certain functions return a time

enum Day { sunday = 0, monday, tuesday, wednesday, thursday, friday, saturday }

Specifies the day of the week

proc getCurrentTime(unit: TimeUnits = TimeUnits.seconds): real(64)
Arguments: unit : TimeUnits -- The units for the returned value The elapsed time since midnight, local time, in the units specified real(64)
proc getCurrentDate()
Returns: (year, month, day) as a tuple of 3 ints

The month is in the range 1 to 12. The day is in the range 1 to 31

proc getCurrentDayOfWeek(): Day
Returns: The current day of the week Day
proc sleep(t: real, unit: TimeUnits = TimeUnits.seconds): void

Delay a task for a duration in the units specified. This function will return without sleeping and emit a warning if the duration is negative.

Arguments: t : real -- The duration for the time to sleep unit : TimeUnits -- The units for the duration
record Timer

Implements basic stopwatch behavior with a potential resolution of microseconds if supported by the runtime platform.

The Timer can be started, stopped, and cleared. A Timer is either running or stopped.

proc clear(): void

Clears the elapsed time. If the timer is running then it is restarted otherwise it remains in the stopped state.

proc start(): void

Starts the timer. A warning is emitted if the timer is already running.

proc stop(): void

Stops the timer. A warning is emitted if the timer is not running.

proc elapsed(unit: TimeUnits = TimeUnits.seconds): real

Returns the cumulative elapsed time, in the units specified, between all pairs of calls to start and stop since the timer was created or the last call to clear. If the timer is running, the elapsed time since the last call to start is added to the return value.

Arguments: unit : TimeUnits -- The units for the returned value The elapsed time in the units specified real(64)