๐ time
โก time::getDate
Get the current date in the given format.
Inputs:
${format}
as string:(optional) the format (see printf) of the date to return
(defaults to “%(%F_%Hh%Mm%Ss)T”)
Returns:
${REPLY}
: the current date in the given format.
Example usage:
time::getDate
local date="${REPLY}"
time::getDate format="'%(%Hh%Mm%Ss)T'"
This function avoid to call $(date) in a subshell (date is a an external executable).
โก time::getMicrosecondsToHuman
Convert microseconds to human readable format.
Inputs:
$1
: microseconds as int:the microseconds to convert
${format}
as string:(optional) the format to use
Usable formats:
- %HH: hours
- %MM: minutes
- %SS: seconds
- %LL: milliseconds
- %h: hours without leading zero
- %m: minutes without leading zero
- %s: seconds without leading zero
- %l: milliseconds without leading zero
- %u: microseconds without leading zero
- %M: total minutes
- %S: total seconds
- %L: total milliseconds
- %U: total microseconds
(defaults to “%HH:%MM:%SS”)
Returns:
${REPLY}
: the human readable format
Example usage:
time::getMicrosecondsToHuman 123456789
time::getMicrosecondsToHuman 123456789 format="%HH:%MM:%SS"
echo "${REPLY}"
โก time::getMicrosecondsToSeconds
Convert a microseconds integer to seconds float. e.g. 1234567 โ 1.234567
Inputs:
$1
: microseconds as int:the microseconds to convert
${precision}
as string:(optional) The precision to get (number of digits after the dot).
(defaults to 6)
Returns:
${REPLY}
: The seconds (float number).
Example usage:
time::getMicrosecondsToSeconds 1234567
time::getMicrosecondsToSeconds 1234567 precision=3
echo "${REPLY}"
โก time::getProgramElapsedMicroseconds
Get the elapsed time in ยตs since the program started.
Returns:
${REPLY}
: the elapsed time in ยตs since the program started.
Example usage:
time::getProgramElapsedMicroseconds
echo "${REPLY}"
time::getMicrosecondsToHuman "${REPLY}"
echo "Human time: ${REPLY}"
We split the computation in seconds and milliseconds to avoid overflow on 32-bit systems. The 10# forces the base 10 conversion to avoid issues with leading zeros. Fun fact: this function will fail in 2038 on 32-bit systems because the number of seconds will overflow.
โก time::getTimerMicroseconds
Get the time elapsed since the call of time::startTimer
.
Inputs:
${logElapsedTime}
as bool:(optional) Wether or not to log the elapsed time.
(defaults to false)
${format}
as string:(optional) The format to use if we log the elapsed time. See
time::getMicrosecondsToHuman
for the format.(defaults to “%S.%LLs”).
Returns:
${REPLY}
: the elapsed time in microseconds.
Example usage:
time::startTimer
time::getTimerMicroseconds logElapsedTime=true
echo "Total microseconds: ${REPLY}"
โก time::startTimer
Start a timer. You can then call time::getTimerMicroseconds
to get the elapsed time.
Example usage:
time::startTimer
time::getTimerMicroseconds
Important
Documentation generated for the version 0.33.0 (2025-08-31).