1
0
mirror of git://git.sv.gnu.org/coreutils.git synced 2026-04-20 18:56:39 +02:00
Files
coreutils/tests/misc/time-style.sh
Paul Eggert df88fce716 date ls pr: fix time zone abbrs on SysV platforms
The problematic code computed a struct tm in one time zone, and
then printed it or converted it to a string in another.  To be
portable the same time zone needs to be used for both operations.
On GNU platforms this is not an issue, but incorrect output can be
generated on System V style platforms like AIX where time zone
abbreviations are available only in the 'tzname' global variable.
Problem reported by Assaf Gordon in: http://bugs.gnu.org/23035
* NEWS: Document the bug.
* src/date.c (show_date):
* src/ls.c (long_time_expected_width, print_long_format):
* src/pr.c (init_header):
* src/stat.c (human_time): Use localtime_rz instead of localtime,
so that the time zone information is consistent for both localtime
and time-formatting functions like fprintftime and nstrftime.  For
'stat' this change is mostly just a code cleanup but it also
causes stat to also print nanoseconds when printing time stamps
that are out of localtime range, as this is more consistent with
what other programs do.  For programs other than 'stat' this fixes
bugs with time zone formats that use %Z.
* src/du.c, src/pr.c (localtz): New static var.
(main): Initialize it.
* src/du.c (show_date): New time zone argument, so that localtime
and fprintftime use the same time zone information.  All callers
changed.
* tests/misc/time-style.sh: New file.
* tests/local.mk (all_tests): Add it.
* tests/misc/date.pl: Test alphabetic time zone abbreviations.
2016-03-17 10:36:33 -07:00

103 lines
3.0 KiB
Bash
Executable File

#!/bin/sh
# Test --time-style in programs like 'ls'.
# Copyright (C) 2016 Free Software Foundation, Inc.
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
print_ver_ du
print_ver_ ls
print_ver_ pr
echo hello >a || framework_failure_
# The tests assume this is an old time stamp in northern hemisphere summer.
TZ=UTC0 touch -d '1970-07-08 09:10:11' a || framework_failure_
for tz in UTC0 PST8 PST8PDT,M3.2.0,M11.1.0 XXXYYY-12:30; do
for style in full-iso long-iso iso locale '+%Y-%m-%d %H:%M:%S %z (%Z)'; do
test "$style" = locale ||
TZ=$tz LC_ALL=C du --time --time-style="$style" a >>duout 2>>err || fail=1
TZ=$tz LC_ALL=C ls -no --time-style="$style" a >>lsout 2>>err || fail=1
case $style in
(+*) TZ=$tz LC_ALL=C pr -D"$style" a >>prout 2>>err || fail=1 ;;
esac
done
done
sed 's/[^ ]* //' duout >dued || framework_failure_
sed 's/[^ ]* *[^ ]* *[^ ]* *[^ ]* *//' lsout >lsed || framework_failure_
sed '/^$/d' prout >pred || framework_failure_
cat <<\EOF > duexp || fail=1
1970-07-08 09:10:11.000000000 +0000 a
1970-07-08 09:10 a
1970-07-08 a
1970-07-08 09:10:11 +0000 (UTC) a
1970-07-08 01:10:11.000000000 -0800 a
1970-07-08 01:10 a
1970-07-08 a
1970-07-08 01:10:11 -0800 (PST) a
1970-07-08 02:10:11.000000000 -0700 a
1970-07-08 02:10 a
1970-07-08 a
1970-07-08 02:10:11 -0700 (PDT) a
1970-07-08 21:40:11.000000000 +1230 a
1970-07-08 21:40 a
1970-07-08 a
1970-07-08 21:40:11 +1230 (XXXYYY) a
EOF
cat <<\EOF > lsexp || fail=1
1970-07-08 09:10:11.000000000 +0000 a
1970-07-08 09:10 a
1970-07-08 a
Jul 8 1970 a
1970-07-08 09:10:11 +0000 (UTC) a
1970-07-08 01:10:11.000000000 -0800 a
1970-07-08 01:10 a
1970-07-08 a
Jul 8 1970 a
1970-07-08 01:10:11 -0800 (PST) a
1970-07-08 02:10:11.000000000 -0700 a
1970-07-08 02:10 a
1970-07-08 a
Jul 8 1970 a
1970-07-08 02:10:11 -0700 (PDT) a
1970-07-08 21:40:11.000000000 +1230 a
1970-07-08 21:40 a
1970-07-08 a
Jul 8 1970 a
1970-07-08 21:40:11 +1230 (XXXYYY) a
EOF
cat <<\EOF > prexp || fail=1
+1970-07-08 09:10:11 +0000 (UTC) a Page 1
hello
+1970-07-08 01:10:11 -0800 (PST) a Page 1
hello
+1970-07-08 02:10:11 -0700 (PDT) a Page 1
hello
+1970-07-08 21:40:11 +1230 (XXXYYY) a Page 1
hello
EOF
compare duexp dued || fail=1
compare lsexp lsed || fail=1
compare prexp pred || fail=1
compare /dev/null err || fail=1
Exit $fail