Skip to content

Instantly share code, notes, and snippets.

@tkuchiki
Last active March 22, 2022 11:05
Show Gist options
  • Save tkuchiki/59e2676b8d17cc29586f516e4948853b to your computer and use it in GitHub Desktop.
Save tkuchiki/59e2676b8d17cc29586f516e4948853b to your computer and use it in GitHub Desktop.

Prerequiresite

  • macOS: brew install coreutils
  • Linux: GNU date

Usage

# timelist.txt
3/16 17:26 ~ 17:29 JST
3/18 18:10 ~ 18:52 JST
# JST to PDT
$ cat timelist.txt | bash convert_date.sh America/Los_Angeles
3/16 17:26 ~ 17:29 JST (03/16 01:26 ~ 03/16 01:29 PDT)
3/18 18:10 ~ 18:52 JST (03/18 02:10 ~ 03/18 02:52 PDT)
#!/bin/bash
to_tz="${1}"
shopt -s expand_aliases
if type gdate > /dev/null; then
alias date='gdate'
fi
cat - | while read line; do
set ${line}
__date=${1}
start=${2}
end=${4}
__tz=${5}
pdt_start=$(TZ="${to_tz}" date -d "${__date} ${start} ${__tz}" +'%m/%d %H:%M')
pdt_end=$(TZ="${to_tz}" date -d "${__date} ${end} ${__tz}" +'%m/%d %H:%M')
to_tz_abbr=$(TZ="${to_tz}" date -d "${pdt_end}" "+%Z")
echo "${__date} ${start} ~ ${end} ${__tz} (${pdt_start} ~ ${pdt_end} ${to_tz_abbr})"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment