marvvin

IRC bot
Log | Files | Refs | README | LICENSE

commit 4bd790f376a0165450515eeaabd4bb6c8f20007a
parent e1fcb5188b7f62878d0d1c6cac92347ced022049
Author: hhvn <dev@hhvn.uk>
Date:   Sun, 15 May 2022 20:54:55 +0100

Better timezone handling for date command

Diffstat:
Mbin/date | 22++++++++++++++++------
1 file changed, 16 insertions(+), 6 deletions(-)

diff --git a/bin/date b/bin/date @@ -23,14 +23,24 @@ getzone(){ date="$1 $2" shift } || date="$1" - echo "$4" | grep -i '^unix$' >/dev/null && - unix=y || - unix=n + zonein=$2 + zoneout=$2 + echo "$zonein" | grep -i '^unix$' >/dev/null && { + zonein=UTC + formatin='-i %s' + } + echo "$4" | grep -i '^unix$' >/dev/null && { + zoneout=UTC + formatout='-f %s' + } 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 + dateconv --from-zone "$(getzone $zonein)" --zone "$(getzone $zoneout)" $formatin $formatout "$date" 2>&1 + exit +} + +[ "$1" = "at" ] || [ "$1" = "in" ] || [ "$1" = "as" ] || [ "$1" = "for" ] && { + dateconv --zone "$2" now exit }