Skip to content

Instantly share code, notes, and snippets.

@hiiamyes
Last active June 2, 2019 08:13
Show Gist options
  • Save hiiamyes/5b002f70749e904d07e1d52aa94b60a0 to your computer and use it in GitHub Desktop.
Save hiiamyes/5b002f70749e904d07e1d52aa94b60a0 to your computer and use it in GitHub Desktop.
getTimezoneNames.sh
#!/bin/bash
# Install wget and jq if you don't have it.
# Mac: brew install jq wget
# Linux: TBD
mkdir tzdb
cd tzdb
wget https://www.iana.org/time-zones/repository/tzcode-latest.tar.gz
wget https://www.iana.org/time-zones/repository/tzdata-latest.tar.gz
gzip -dc tzcode-latest.tar.gz | tar -xf -
gzip -dc tzdata-latest.tar.gz | tar -xf -
timezone_names=()
while IFS= read -r line; do
if [[ "$line" != \#* ]]; then
IFS=$'\t' read -r country_codes coordinates timezone_name comments <<<"$line"
timezone_names+=($timezone_name)
fi
done <"zone1970.tab"
printf '%s\n' "${timezone_names[@]}" | jq -R . | jq -s . >../timezoneNames.json
cd ..
rm -rf tzdb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment