]>
Commit | Line | Data |
---|---|---|
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 |
14 | LC_ALL=C |
15 | LANG=C | |
16 | ||
17 | SHELLSTART=$(date +%s) | |
18 | SECS=1275250155 | |
19 | export TZ=EST5EDT | |
20 | ||
ac50fbac | 21 | case $SHELLSTART in |
d233b485 | 22 | *s*) SHELLSTART=$EPOCHSECONDS ; DATESECS=false ;; # take a shot |
ac50fbac CR |
23 | *) DATESECS=true ;; |
24 | esac | |
25 | ||
495aee44 CR |
26 | printf "%()T\n" $SECS |
27 | printf "%(abde)Z\n" -1 | |
28 | ||
29 | printf "%(%e-%b-%Y %T)T\n" $SECS | |
30 | ||
d233b485 | 31 | printf -v v1 "%(%e-%b-%Y %T)T\n" $( $DATESECS && date +%s || echo $EPOCHSECONDS ) |
495aee44 CR |
32 | printf -v v2 "%(%e-%b-%Y %T)T\n" -1 |
33 | ||
34 | case $v1 in | |
35 | $v2) ;; | |
36 | *) echo "current time and -1 possible mismatch|$v1|$v2|" >&2 ;; | |
37 | esac | |
38 | unset v1 v2 | |
39 | ||
40 | v1=$(date +%s) | |
41 | printf -v v2 "%(%s)T" -1 | |
42 | ||
43 | case $v1 in | |
44 | $v2) ;; | |
45 | *) echo "current time mismatch:$v1|$v2|" >&2 ;; | |
46 | esac | |
47 | unset v1 v2 | |
48 | ||
49 | printf "%(%x %X)T\n" $(( $SECS - 3600 )) | |
50 | ||
51 | printf -v v1 "%(%F %r)T\n" $SHELLSTART | |
52 | printf -v v2 "%(%F %r)T\n" -2 | |
53 | ||
54 | case $v1 in | |
55 | $v2) ;; | |
56 | *) echo "shell start time and -2 possible mismatch|$v1|$v2|" >&2 ;; | |
57 | esac | |
58 | unset v1 v2 | |
59 | ||
60 | printf "current time: %(%F %r)T\n" $SECS | |
61 | ||
62 | printf "epoch time: %(%F %r %z)T\n" 0 | |
63 | printf "random time: %(%F %r %z)T\n" $SECS | |
64 | ||
65 | printf "local time: %(%a %b %e %H:%M:%S %Z %Y)T\n" $SECS | |
66 | ||
67 | # test fieldwidth, justification, precision | |
68 | printf "%-40.50(%a %b %e %H:%M:%S %Z %Y)T date-style time\n" $SECS | |
69 | ||
70 | # test fieldwidth, justification, precision, embedded parens | |
71 | printf "%-40.50(%x (foo) %X)T date-style time\n" $SECS | |
ac50fbac CR |
72 | |
73 | # problem introduced in bash-4.2 patch 5 | |
74 | unset TZ | |
75 | printf '%(%Y-%m-%d %H:%M:%S %Z)T\n' >/dev/null |