Created
June 29, 2022 08:51
-
-
Save chunkhang/e0958962dcee1b0180e4251b5ec375e1 to your computer and use it in GitHub Desktop.
Revisions
-
chunkhang created this gist
Jun 29, 2022 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,24 @@ #!/usr/bin/env zsh # Usage: # convert_timezone <source timezone> <target timezone> <date string...> # # Examples: # Asia/Singapore (now) -> Europe/Zurich # $ convert_timezone Asia/Singapore Europe/Zurich # # Asia/Singapore (4 pm) -> Europe/Zurich # $ convert_timezone Asia/Singapore Europe/Zurich 4pm # # Asia/Singapore (4 pm tomorrow) -> Europe/Zurich # $ convert_timezone Asia/Singapore Europe/Zurich 4pm tomorrow function convert_timezone() { timezone_from="$1"; shift timezone_to="$1"; shift if [[ "$#" = 0 ]]; then TZ="$timezone_to" date else date_string="TZ=\"${timezone_from}\" ${@}" TZ="$timezone_to" date --date "$date_string" fi }