-
-
Save anjannath/f2267212566faa343ff8d79aeeaa8b4a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# needs bash v4 | |
# you can do things like this : | |
# % tz | |
# % tz 10h30 | |
# % tz 10h30 next week | |
# % tz 11:00 next thursday | |
# | |
# and so on! | |
set -eo pipefail | |
declare -A tzone | |
## Change this | |
tzone=( | |
["Bengalore"]="Asia/Calcutta" | |
["Brisbane"]="Australia/Brisbane" | |
["Paris"]="Europe/Paris" | |
) | |
currenttz=$(/bin/ls -l /etc/localtime|awk -F/ '{print $(NF-1)"/"$NF}') | |
date=date | |
type -p gdate >/dev/null 2>/dev/null && date=gdate | |
athour= | |
args=($@) | |
if [[ -n ${1} ]];then | |
[[ $1 != [0-9]*(:|h)[0-9]* ]] && { echo "Invalid date format: $1"; exit 1; } | |
athour="${1/h/:} ${args[@]:1}" | |
fi | |
for i in ${!tzone[@]};do | |
echo -n "$i: " | |
# bug in gnu date? 'now' doesn't take in consideration TZ :( | |
[[ -n ${athour} ]] && TZ="${tzone[$i]}" ${date} --date="TZ=\"$currenttz\" ${athour}" || \ | |
TZ=${tzone[$i]} ${date} | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment