aboutsummaryrefslogtreecommitdiffstats
path: root/test/strftime.awk
blob: a52957f022932abd3ccf6de2688e819e04b0bc15 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# strftime.awk ; test the strftime code
#
# input is the output of `date', see Makefile.in
#
# The mucking about with $0 and $NF is to avoid problems
# on cygwin, where the timezone field is empty and there
# are two consecutive blanks.

BEGIN {
	maxtries = 10
	datecmd = "date"
	fmt = "%a %b %d %H:%M:%S %Z %Y"

	# loop until before equals after, thereby protecting
	# against a race condition where the seconds field might have
	# incremented between running date and strftime
	i = 0
	while (1) {
		if (++i > maxtries) {
			printf "Warning: this system is so slow that after %d attempts, we could never get two sequential invocations of strftime to give the same result!\n", maxtries > "/dev/stderr"
			break
		}
		before = strftime(fmt)
		datecmd | getline sd
		after = strftime(fmt)
		close(datecmd)
		if (before == after) {
			if (i > 1)
				printf "Notice: it took %d loops to get the before and after strftime values to match\n", i > "/dev/stderr"
			break
		}
	}
	print sd > "strftime.ok"
	$0 = after
	$NF = $NF
	print > OUTPUT
}