The built-in capacity Time
provides tools for obtaining the current time from the run-time platform.
Time definition is application-dependent and platform-dependent. In other words, the time values replied by this capacity depends on the run-time environment: it may be the operating system time, or a simulator time.
For obtaining the current time, the getTime
function is provides by the Time
capacity:
def getTime(timeUnit : TimeUnit = null) : double
The timeUnit parameter will enable you to specify the unit of the replied value (hours, seconds, milliseconds, etc.). If it is not provided, the values will be expressed in seconds.
agent A {
uses Time
def myaction {
var ct = getTime
var ct2 = getTime(null)
var ct3 = getTime(TimeUnit::HOURS)
}
}
At least, there is two different time scales:
Time
capacity.The function getOSTimeFactor
provides the multiplication factor between these two time scales.
The functions toOSTime
and fromOSTime
do the convertion of a time between these two scales.
The functions toOSDuration
and fromOSDuration
do the convertion of a duration between these two scales.
For the time replied by the getTime
function may be not the operating-system time, e.g. a simulation time.
In order to map the time replied by the getTime
function and the operating-system time, the
getOSTimeFactor
function replies a factor that could be applied so that:
operatingSystemTime = getOSTimeFactor * getTime
The provided function is:
def getOSTimeFactor : double
For converting a time, you have access to two functions:
toOSTime
: converts a OS time to its equivalent time into the SARL run-time environment.fromOSTime
converts a SARL run-time time to its equivalent into the OS.// Convertion from OS to SRE
sreTime = fromOSTime(operatingSystemTime)
// Convertion from SRE to OS
operatingSystemTime = toOSTime(sreTime)
For converting a duration, you have access to two functions:
toOSDuration
: converts a OS duration to its equivalent time into the SARL run-time environment.fromOSDuration
converts a SARL run-time duration to its equivalent into the OS.// Convertion from OS to SRE
sreTime = fromOSDuration(operatingSystemTime)
// Convertion from SRE to OS
operatingSystemTime = toOSDuration(sreTime)
Copyright © 2014-2024 SARL.io, the Original Authors and Main Authors.
Documentation text and medias are licensed under the Creative Common CC-BY-SA-4.0; you may not use this file except in compliance with CC-BY-SA-4.0. You may obtain a copy of CC-BY-4.0.
Examples of SARL code are licensed under the Apache License, Version 2.0; you may not use this file except in compliance with the Apache License. You may obtain a copy of the Apache License.
You are free to reproduce the content of this page on copyleft websites such as Wikipedia.
Generated with the translator docs.generator 0.14.0.