TOF IP to Timezone

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.

mmm… what about countries with multiple timezones? And a lot other factors like proxies, VPNs, corporate website with gateways in distant HQ etc.

I would recommend to use client side Javascript Date-Object transfered to the server if we are talking about a website

it might just give you multiple TZ’s back
Dunno but you can give some stuff a whirl

my specific IP address identifies me as being in Alberta, Canada
and Canada definitely has several TZ’s

No idea how to test @jalih code for my IP