date (948B)
1 #!/bin/sh 2 3 zoneinfo=/usr/share/zoneinfo 4 zonemap=" 5 CEST CET 6 GMT GB 7 BST GB" 8 9 getzone(){ 10 zone=$(echo "$1" | tr '[:lower:]' '[:upper:]') 11 zone=$(printf '%s\n' "$zonemap" | awk -F"\t" -v "zone=$zone" ' 12 $1 == zone { 13 print $2 14 p=1 15 exit 0 16 } 17 END {if (!p) print zone}') 18 echo "$zone" 19 } 20 21 [ "$3" = "to" ] || [ "$4" = "to" ] && { 22 [ "$4" = "to" ] && { 23 date="$1 $2" 24 shift 25 } || date="$1" 26 zonein=$2 27 zoneout=$2 28 echo "$zonein" | grep -i '^unix$' >/dev/null && { 29 zonein=UTC 30 formatin='-i %s' 31 } 32 echo "$4" | grep -i '^unix$' >/dev/null && { 33 zoneout=UTC 34 formatout='-f %s' 35 } 36 echo "$1" | grep -v '-' >/dev/null && [ "$unix" = "y" ] && 37 date="$(date +%Y-%m-%d) $date" 38 dateconv --from-zone "$(getzone $zonein)" --zone "$(getzone $zoneout)" $formatin $formatout "$date" 2>&1 39 exit 40 } 41 42 [ "$1" = "at" ] || [ "$1" = "in" ] || [ "$1" = "as" ] || [ "$1" = "for" ] && { 43 dateconv --zone "$2" now 44 exit 45 } 46 47 [ -z "$@" ] && 48 date || 49 date +"${*#+}"