Skip to content

Instantly share code, notes, and snippets.

@didenko
Last active November 11, 2018 04:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save didenko/d5e3c5f143d9e9eb7b6d37f09bade97e to your computer and use it in GitHub Desktop.
Save didenko/d5e3c5f143d9e9eb7b6d37f09bade97e to your computer and use it in GitHub Desktop.
Cross-timezone calculations
function timein ()
{
[ "${#}" -lt 3 ] && {
echo 'timein <dest loc> [when] <src loc> [is] <src time>' 1>&2
echo -e 'e.g.:\ntimein America/Chicago when Europe/Berlin is tomorrow 14:30' 1>&2
echo -e 'or:\ntimein Asia/Ho_Chi_Minh America/New_York 2019/01/02 08:00' 1>&2
return 1
}
dest=${1}; shift
[ "${1}" == "when" ] && shift
src=${1}; shift
[ "${1}" == "is" ] && shift
on=${*}
TZ=${dest} date --date="TZ=\"${src}\" ${on}"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment