Created
September 17, 2021 00:28
-
-
Save rawiriblundell/10ef4183cf3590f2ff549f1fe3ffaaa6 to your computer and use it in GitHub Desktop.
Lookup a timezone based on lat/long coords
This file contains 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
tzlookup() { | |
local err cmd lat long | |
err=0 | |
for cmd in curl jq; do | |
command -v "${cmd}" >/dev/null 2>&1 || (( ++err )) | |
done | |
(( err > 0 )) && { printf -- '%s\n' "Requires 'curl' and 'jq'" >&2; return 1; } | |
lat="${1:?No latitude value supplied}" | |
long="${2:?No longitude value supplied}" | |
case "${lat}" in | |
(*[sS]) lat="-${lat/[sS]/}" ;; | |
(*[nN]) lat="${lat/[nN]/}" ;; | |
esac | |
case "${long}" in | |
(*[wW]) long="-${long/[wW]/}" ;; | |
(*[eE]) long="${long/[eE]/}" ;; | |
esac | |
curl -s "https://timezone.bertold.org/timezone?lat=${lat}&lon=${long}&s=1" | | |
jq -r '.Result' | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment