Tizen 2.0 Release
[external/tizen-coreutils.git] / tests / misc / date-sec
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.
5
6 # Copyright (C) 2004, 2006 Free Software Foundation, Inc.
7
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
12
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 # GNU General Public License for more details.
17
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write to the Free Software
20 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 # 02110-1301, USA.
22
23 if test "$VERBOSE" = yes; then
24   set -x
25   date --version
26 fi
27
28 pwd=`pwd`
29 t0=`echo "$0"|sed 's,.*/,,'`.tmp; tmp=$t0/$$
30 trap 'status=$?; cd "$pwd" && chmod -R u+rwx $t0 && rm -rf $t0 && exit $status' 0
31 trap '(exit $?); exit $?' 1 2 13 15
32
33 framework_failure=0
34 mkdir -p $tmp || framework_failure=1
35 cd $tmp || framework_failure=1
36
37 if test $framework_failure = 1; then
38   echo "$0: failure in testing framework" 1>&2
39   (exit 1); exit 1
40 fi
41
42 fail=0
43
44 # It would be easier simply to sleep for two seconds between two runs
45 # of `date --date="21:04 +0100" +%S` and ensure that both outputs
46 # are `00', but I prefer not to sleep unconditionally.  `make check'
47 # takes long enough as it is.
48
49 n=0
50 # See if the current number of seconds is `00' or just before.
51 s=`date +%S`
52 case "$s" in
53   58) n=3;;
54   59) n=2;;
55   00) n=1;;
56 esac
57
58 # If necessary, wait for the system clock to pass the minute mark.
59 test $n = 0 || sleep $n
60
61 s=`date --date="21:04 +0100" +%S`
62 case "$s" in
63   00) ;;
64   *) fail=1;;
65 esac
66
67 (exit $fail); exit $fail