]> git.ipfire.org Git - thirdparty/bash.git/blame - tests/printf3.sub
bash-5.1 distribution sources and documentation
[thirdparty/bash.git] / tests / printf3.sub
CommitLineData
8868edaf
CR
1# This program is free software: you can redistribute it and/or modify
2# it under the terms of the GNU General Public License as published by
3# the Free Software Foundation, either version 3 of the License, or
4# (at your option) any later version.
5#
6# This program is distributed in the hope that it will be useful,
7# but WITHOUT ANY WARRANTY; without even the implied warranty of
8# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9# GNU General Public License for more details.
10#
11# You should have received a copy of the GNU General Public License
12# along with this program. If not, see <http://www.gnu.org/licenses/>.
13#
495aee44
CR
14LC_ALL=C
15LANG=C
16
17SHELLSTART=$(date +%s)
18SECS=1275250155
19export TZ=EST5EDT
20
ac50fbac 21case $SHELLSTART in
d233b485 22*s*) SHELLSTART=$EPOCHSECONDS ; DATESECS=false ;; # take a shot
ac50fbac
CR
23*) DATESECS=true ;;
24esac
25
495aee44
CR
26printf "%()T\n" $SECS
27printf "%(abde)Z\n" -1
28
29printf "%(%e-%b-%Y %T)T\n" $SECS
30
d233b485 31printf -v v1 "%(%e-%b-%Y %T)T\n" $( $DATESECS && date +%s || echo $EPOCHSECONDS )
495aee44
CR
32printf -v v2 "%(%e-%b-%Y %T)T\n" -1
33
34case $v1 in
35$v2) ;;
36*) echo "current time and -1 possible mismatch|$v1|$v2|" >&2 ;;
37esac
38unset v1 v2
39
40v1=$(date +%s)
41printf -v v2 "%(%s)T" -1
42
43case $v1 in
44$v2) ;;
45*) echo "current time mismatch:$v1|$v2|" >&2 ;;
46esac
47unset v1 v2
48
49printf "%(%x %X)T\n" $(( $SECS - 3600 ))
50
51printf -v v1 "%(%F %r)T\n" $SHELLSTART
52printf -v v2 "%(%F %r)T\n" -2
53
54case $v1 in
55$v2) ;;
56*) echo "shell start time and -2 possible mismatch|$v1|$v2|" >&2 ;;
57esac
58unset v1 v2
59
60printf "current time: %(%F %r)T\n" $SECS
61
62printf "epoch time: %(%F %r %z)T\n" 0
63printf "random time: %(%F %r %z)T\n" $SECS
64
65printf "local time: %(%a %b %e %H:%M:%S %Z %Y)T\n" $SECS
66
67# test fieldwidth, justification, precision
68printf "%-40.50(%a %b %e %H:%M:%S %Z %Y)T date-style time\n" $SECS
69
70# test fieldwidth, justification, precision, embedded parens
71printf "%-40.50(%x (foo) %X)T date-style time\n" $SECS
ac50fbac
CR
72
73# problem introduced in bash-4.2 patch 5
74unset TZ
75printf '%(%Y-%m-%d %H:%M:%S %Z)T\n' >/dev/null