There is a forum topic on Xojo forums about “How to get TimeZone from an IP?”. Using the IP-to-country database from my previous 8th programming sample, and a little bit more 8th code:
needs date/daylight
"geoip.db" constant db-name
var q1
\ open db as read-only
: open-db \ -- db
db-name f:slurp "No database" thrownull
db:open ;
: close-db \ db --
db:close ;
: create-query \ db -- db
"SELECT cc FROM ips WHERE ip1 <= ? and ip2 >= ?" db:prepare q1 ! ;
: ip2num \ s -- n
"." s:/
( >n swap 256 n:* n:+ )
0 a:reduce ;
: query \ s -- s|null
q1 @ swap ip2num dup 2 a:close db:bind-exec[] 0 a:_@ null? !if
0 a:_@
then ;
: app:main
open-db
create-query
"65.21.154.250" query swap db:close null? !if
d:dstinfo a:open "name" m:_@ null? !if
d:new d:dst-ofs "Time zone offset is %d minutes." s:strfmt
else
drop "TZ information not found!"
then
else
drop "Country code for IP not found."
then
. cr ;
Test run gives:
Time zone offset is 180 minutes.