1TIME(3am) GNU Awk Extension Modules TIME(3am)
2
3
4
6 time - time functions for gawk
7
9 @load "time"
10
11 time = gettimeofday()
12 ret = sleep(amount)
13 timeval = strptime(string, format)
14
16 The time extension adds three functions named gettimeofday() sleep(),
17 and stptrime(), as follows.
18
19 gettimeofday()
20 This function returns the number of seconds since the Epoch as a
21 floating-point value. It should have subsecond precision. It
22 returns -1 upon error and sets ERRNO to indicate the problem.
23
24 sleep(seconds)
25 This function attempts to sleep for the given amount of seconds,
26 which may include a fractional portion. If seconds is negative,
27 or the attempt to sleep fails, then it returns -1 and sets ER‐
28 RNO. Otherwise, the function should return 0 after sleeping for
29 the indicated amount of time.
30
31 strptime()
32 This function takes two arguments, a string representing a date
33 and time, and a format string describing the data in the string.
34 It calls the C library strptime(3) function with the given val‐
35 ues. If the parsing succeeds, the results are passed to the C
36 library mktime(3) function, and its result is returned, express‐
37 ing the time in seconds since the epoch in the current local
38 timezone, regardless of any timezone specified in the string ar‐
39 guments. (This is the same as gawk's built-in systime() func‐
40 tion.) Otherwise it returns -1 upon error. In the latter case,
41 ERRNO indicates the problem.
42
44 The underlying strptime(3) C library routine apparently ignores any
45 time zone indication in the date string, producing values relative to
46 the current time zone. It might be better to have this routine return
47 a string similar to what gawk's mktime() function expects, but we ran
48 out of energy.
49
51 @load "time"
52 ...
53 printf "It is now %g seconds since the Epoch\n", gettimeofday()
54 ...
55 printf "Pausing for a while... " ; sleep(2.5) ; print "done"
56 ...
57 format = "%b %d %H:%M:%S %Z %Y"
58 now = systime()
59 print now, "<" (result = strftime(format, now)) ">",
60 then = strptime(result, format)
61 print strftime(format, then)
62
64 GAWK: Effective AWK Programming, filefuncs(3am), fnmatch(3am),
65 fork(3am), inplace(3am), ordchr(3am), readdir(3am), readfile(3am),
66 revoutput(3am), rwarray(3am).
67
68 gettimeofday(2), nanosleep(2), select(2), and strptime(3).
69
71 Arnold Robbins, arnold@skeeve.com.
72
74 Copyright © 2012, 2013, 2018, 2022, 2023, Free Software Foundation,
75 Inc.
76 Copyright © 2019, Arnold David Robbins.
77
78 Permission is granted to make and distribute verbatim copies of this
79 manual page provided the copyright notice and this permission notice
80 are preserved on all copies.
81
82 Permission is granted to copy and distribute modified versions of this
83 manual page under the conditions for verbatim copying, provided that
84 the entire resulting derived work is distributed under the terms of a
85 permission notice identical to this one.
86
87 Permission is granted to copy and distribute translations of this man‐
88 ual page into another language, under the above conditions for modified
89 versions, except that this permission notice may be stated in a trans‐
90 lation approved by the Foundation.
91
92
93
94Free Software Foundation Jan 16 2023 TIME(3am)