*** empty log message ***
[coreutils.git] / tests / misc / date-sec
blobb296b7ea64cff5b6614795edecc8d976a9de22bf
1 #!/bin/sh
2 # Ensure that a command like
3 # `date --date="21:04 +0100" +%S' always prints `00'.
4 # Before coreutils-5.2.1, it would print the seconds from the current time.
6 if test "$VERBOSE" = yes; then
7 set -x
8 date --version
9 fi
11 pwd=`pwd`
12 t0=`echo "$0"|sed 's,.*/,,'`.tmp; tmp=$t0/$$
13 trap 'status=$?; cd $pwd; chmod -R u+rwx $t0; rm -rf $t0 && exit $status' 0
14 trap '(exit $?); exit $?' 1 2 13 15
16 framework_failure=0
17 mkdir -p $tmp || framework_failure=1
18 cd $tmp || framework_failure=1
20 if test $framework_failure = 1; then
21 echo "$0: failure in testing framework" 1>&2
22 (exit 1); exit 1
25 fail=0
27 # It would be easier simply to sleep for two seconds between two runs
28 # of `date --date="21:04 +0100" +%S` and ensure that both outputs
29 # are `00', but I prefer not to sleep unconditionally. `make check'
30 # takes long enough as it is.
32 n=0
33 # See if the current number of seconds is `00' or just before.
34 s=`date +%S`
35 case "$s" in
36 58) n=3;;
37 59) n=2;;
38 00) n=1;;
39 esac
41 # If necessary, wait for the system clock to pass the minute mark.
42 test $n = 0 || { echo sleeping for $n seconds...; sleep $n; }
44 s=`date --date="21:04 +0100" +%S`
45 case "$s" in
46 00) ;;
47 *) fail=1;;
48 esac
50 (exit $fail); exit $fail