Skip to main content

Time

Objects of type Timeval represent time points. Time points are internally represented using Coordinated Universal Time (UTC) making them location independent. The time points are internally represented as number of microseconds since January 1st, 1970, which is called the epoch. A time string is a time point expressed as a string in UTC format.

Get current time according to UTC by calling:

utc_time()

The time format is year-month-dateThour:minute:second:millisecondZ. The ending Z indicates UTC time, also called Greenwich Mean Time (GMT).

Get the local time string by calling:

local_time()

Notice that the local time string depends on where your SA Engine server is located. As an alternative you can get a location independent local time string by calling:

local_utc_time()

The ending hh:ss indicates the time shift in hours and minutes needed to get UTC time.

Get the current time point by calling:

now()

Constants of type Timeval are written as |UTC-time|.

You can create new time points by adding or subtracting seconds from time points using + or -, respectively:

set :t0=now()

Add a second to :t0:

:t0 + 1

Subract a second from :t0:

:t0 - 1

You can get the time in seconds between two time points by using -, e.g.:

set :t1 = now()
:t1 - :t0

The function call sleep(x) makes the system sleep for x seconds. Try:

set :t0 = now();
sleep(0.2);
now() - :t0

Time stamped objects

The function ts(Object o)->Timeval returns a time stamped object, which associates the current wall time point with o. The type Timeval is used to represents both time stamped objects and time stamps. The object associated with a time stamped object tv is accessed by the function value(Timeval tv)->Object.

Example: Make a time stamped number one and assign to :ts.

set :ts = ts(1)

For a time stamped object tv you can retrieve the object being time stamped with the function value(Timeval tv)->Object'.

Example:

value(:ts)

The function timestamp(Timeval tv)->Timeval returns the time stamp of a time stamped object.

Example:

timestamp(:ts)

Functions

The system library of temporal functions is documented in Time functions.