-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtimezones
executable file
·57 lines (42 loc) · 1013 Bytes
/
timezones
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/bin/sh
set -eu
conf_file="$HOME/.config/timezones"
usage() {
basename="$(basename "$0")"
cat >&2 <<EOM
usage: $basename [Options]
Display the time in several time zones. The zones will be taken from \$ZONES,
if set, or from ~/.config/timezones.
Options will be passed through to date(1). See tzselect(1) or
/usr/share/zoneinfo for lists of timezones.
Examples:
ZONES='UTC Japan/Tokyo' $basename
$basename +%c
$basename -d '+3 hours' '+%F %R'
EOM
}
if [ $# -ge 1 ] && [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
usage
exit
fi
ZONES="${ZONES:-}"
if [ -z "$ZONES" ]; then
if [ -e "$conf_file" ]; then
ZONES="$(cat "$conf_file")"
else
usage
exit 1
fi
fi
if which gdate >/dev/null; then
date=gdate
else
date=date
fi
for tz in $ZONES; do
if [ ! -e "/usr/share/zoneinfo/$tz" ]; then
echo >&2 "Warning: not sure whether $tz is a valid timezone"
fi
output="$(TZ="$tz" "$date" "$@")"
echo "$output $tz"
done