-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.sh
executable file
·43 lines (37 loc) · 880 Bytes
/
test.sh
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
38
39
40
41
42
43
#!/usr/bin/env bash
#
#set -x
. ${0%/*}/function
random_date () {
local rd
local _rY _rM _rD _rH _rm _rs _rd
until [[ -n "$rd" ]]; do
_rY=$(gshuf -i 1970-2100 -n1)
_rM=$(( (RANDOM%12) + 1 ))
_rD=$(( (RANDOM%31) + 1 ))
_rH=$(( (RANDOM%23) + 1 ))
_rm=$(( (RANDOM%59) + 1 ))
_rs=$(( (RANDOM%59) + 1 ))
_rd="${_rY}-${_rM}-${_rD} ${_rH}:${_rm}:${_rs}"
rd=$(gdate -d "$_rd" '+%F %T' 2>/dev/null)
done
awk '{print $1 "T" $2 "Z"}' <<<"$rd"
}
f=0
n=1000
for ((i=1;i<=n;i++)); do
printf '%s' "${i}/${n}..."
_d=$(random_date)
epoch_calc=$(get_epoch "$_d")
gnu_date=$(gdate -d "$_d" '+%s') || echo "I got $_d"
if [[ "$gnu_date" -ne "$epoch_calc" ]]; then
((f++))
printf '\r%s\n%10s\n%10s\n' \
"Fail! Epoch times did not match" \
"GNU Time: $gnu_date" \
"get_epoch Time: $epoch_calc"
else
printf '%s\r' 'Pass'
fi
done
echo "Number of failures: $f"