Skip to content
David Nichols edited this page Jun 17, 2016 · 6 revisions

Did You Know?: (Hopefully) Useful Information about Programming in Qore

You can specify a literal relative date/time value (duration) directly in your code with two different syntax options.

Short Form Example:

# 2 minutes, 30 seconds, and 250 ms
const Delta = 2m + 30s + 250ms;

Extended ISO-8601 Examples:

# 3 days, 21 hours, and 551 microseconds
const Delta1 = P3DT21H551u;
# 1 year, 3 months, and 4 seconds
const Delta2 = P0001-03-00T00:00:04;

See also: HowTo: Generate a relative date/time value from an expression

You can use the timeout type declaration for timeout arguments

"timeout" will give you an integer in milliseconds for use as a timeout argument.

"timeout" handles input values as follows depending on their type:

  • relative date/time values (duration): are converted to an integer value in milliseconds
  • absolute date/time values: (ex: 2016-07-01T15:32:22.357Z) an integer value in milliseconds will be calculated for future dates as the difference between the given date and the current date/time (as with now_ms()). If the date/time value is in the past, then 0 is returned. You may never need this, but it will still work :)
  • integers: are assumed to be literal values already in milliseconds.

For example:

sub wait_for_event(timeout to = 1250ms) {
    if (cond.wait(mutex, to))
        throw "WAIT-TIMEOUT", sprintf("timed out waiting %d ms on event", to);
}