17.7.11 Extension Time Functions

The time extension adds three functions, named gettimeofday() sleep(), and strptime(), as follows:

@load "time"

This is how you load the extension.

the_time = gettimeofday()

Return the time in seconds that has elapsed since 1970-01-01 UTC as a floating-point value. If the time is unavailable on this platform, return −1 and set ERRNO. The returned time should have sub-second precision, but the actual precision may vary based on the platform. If the standard C gettimeofday() system call is available on this platform, then it simply returns the value. Otherwise, if on MS-Windows, it tries to use GetSystemTimeAsFileTime().

result = sleep(seconds)

Attempt to sleep for seconds seconds. If seconds is negative, or the attempt to sleep fails, return −1 and set ERRNO. Otherwise, return zero after sleeping for the indicated amount of time. Note that seconds may be a floating-point (nonintegral) value. Implementation details: depending on platform availability, this function tries to use nanosleep() or select() to implement the delay.

timeval = strptime(string, format)

This function takes two arguments, a string representing a date and time, and a format string describing the data in the string. It calls the C library strptime() function with the given values. If the parsing succeeds, the results are passed to the C library mktime() function, and its result is returned, expressing the time in seconds since the epoch in the current local timezone, regardless of any timezone specified in the string arguments. (This is the same as gawk’s built-in systime() function.) Otherwise it returns −1 upon error. In the latter case,

Note that the underlying strptime() C library routine apparently ignores any time zone indication in the date string, producing values relative to the current time zone.