]> git.ipfire.org Git - thirdparty/bash.git/blob - tests/printf3.sub
Bash-4.3 patch 7
[thirdparty/bash.git] / tests / printf3.sub
1 LC_ALL=C
2 LANG=C
3
4 SHELLSTART=$(date +%s)
5 SECS=1275250155
6 export TZ=EST5EDT
7
8 case $SHELLSTART in
9 *s*) SHELLSTART=$(perl -e 'print time') ; DATESECS=false ;; # take a shot
10 *) DATESECS=true ;;
11 esac
12
13 printf "%()T\n" $SECS
14 printf "%(abde)Z\n" -1
15
16 printf "%(%e-%b-%Y %T)T\n" $SECS
17
18 printf -v v1 "%(%e-%b-%Y %T)T\n" $( $DATESECS && date +%s || perl -e 'print time')
19 printf -v v2 "%(%e-%b-%Y %T)T\n" -1
20
21 case $v1 in
22 $v2) ;;
23 *) echo "current time and -1 possible mismatch|$v1|$v2|" >&2 ;;
24 esac
25 unset v1 v2
26
27 v1=$(date +%s)
28 printf -v v2 "%(%s)T" -1
29
30 case $v1 in
31 $v2) ;;
32 *) echo "current time mismatch:$v1|$v2|" >&2 ;;
33 esac
34 unset v1 v2
35
36 printf "%(%x %X)T\n" $(( $SECS - 3600 ))
37
38 printf -v v1 "%(%F %r)T\n" $SHELLSTART
39 printf -v v2 "%(%F %r)T\n" -2
40
41 case $v1 in
42 $v2) ;;
43 *) echo "shell start time and -2 possible mismatch|$v1|$v2|" >&2 ;;
44 esac
45 unset v1 v2
46
47 printf "current time: %(%F %r)T\n" $SECS
48
49 printf "epoch time: %(%F %r %z)T\n" 0
50 printf "random time: %(%F %r %z)T\n" $SECS
51
52 printf "local time: %(%a %b %e %H:%M:%S %Z %Y)T\n" $SECS
53
54 # test fieldwidth, justification, precision
55 printf "%-40.50(%a %b %e %H:%M:%S %Z %Y)T date-style time\n" $SECS
56
57 # test fieldwidth, justification, precision, embedded parens
58 printf "%-40.50(%x (foo) %X)T date-style time\n" $SECS
59
60 # problem introduced in bash-4.2 patch 5
61 unset TZ
62 printf '%(%Y-%m-%d %H:%M:%S %Z)T\n' >/dev/null