commit bdbdf781fafd15e8ee39f408a583f2cf5b282d25 parent 5c68301970584c1b57895d94e48ab206cd22096c Author: hhvn <dev@hhvn.uk> Date: Wed, 13 Oct 2021 15:44:04 +0100 b/date: map common timezones to ones in /usr/share/zoneinfo Diffstat:
M | bin/date | | | 34 | +++++++++++++++++++++++++++++++--- |
1 file changed, 31 insertions(+), 3 deletions(-)
diff --git a/bin/date b/bin/date @@ -1,8 +1,36 @@ #!/bin/sh -# force +format -[ "$3" = "to" ] && { - dateconv --from-zone "$2" --zone "$4" "$1" +zoneinfo=/usr/share/zoneinfo +zonemap=" +CEST CET +GMT GB +BST GB" + +getzone(){ + zone=$(echo "$1" | tr '[:lower:]' '[:upper:]') + zone=$(printf '%s\n' "$zonemap" | awk -F"\t" -v "zone=$zone" ' + $1 == zone { + print $2 + p=1 + exit 0 + } + END {if (!p) print zone}') + echo "$zone" +} + +[ "$3" = "to" ] || [ "$4" = "to" ] && { + [ "$4" = "to" ] && { + date="$1 $2" + shift + } || date="$1" + echo "$4" | grep -i '^unix$' >/dev/null && + unix=y || + unix=n + echo "$1" | grep -v '-' >/dev/null && [ "$unix" = "y" ] && + date="$(date +%Y-%m-%d) $date" + [ "$unix" = "y" ] && + dateconv --from-zone "$(getzone $2)" --zone "$(getzone UTC)" -f %s "$date" 2>&1 || + dateconv --from-zone "$(getzone $2)" --zone "$(getzone $4)" "$date" 2>&1 exit }