What does Dates.hour(now(Dates.UTC)) return? Time in UTC?

Can I use it to get an estimate of the Time Zone (less the day light saving shift)?
My intention is to get an approximate longitude of users location.

It gives you whatever is set as the system time, which doesn’t necessarily correspond to physical location. Some servers are exclusively configured with UTC+0 as their local time, regardless of physical location. It’s not really a good proxy variable for getting the longitude of a user.

using Dates, TimeZones

function approx_longitude()
   # 15 degrees per hour
    (((now(localzone())).zone.offset.std.value) / (60*60)) * 15 
end

Thank, I know about TimeZones but I don’t want to add a package dependency for this.

Short of querying that though, your only other semi-reliable option is to ask the user (or use an explicit location API of the OS) :person_shrugging: There’s a reason web browsers abstracted that away - most proxy variables for this aren’t reliable at all, not even checking the IP address.

Here’s what TimeZones.jl does

Guys, thanks for suggestions but I only wanted that the following map showing the the daylight terminators would center the map on user ~longitude. Not really important so that’s why I don’t want to add a dependency for it.

using GMT
solar(proj=:ortho, coast=true, terminators=:d, fill="navy@75", show=1)

FWIW, this SO solution prints the user IP lat-lon:

str = read(`curl ipinfo.io/loc`, String)

lon = last(split(chomp(str), ","))
1 Like

Thanks, and very fast.

1 Like

@joa-quim, would it be possible to show the full GMT example that centers the Earth map by longitude (and the daylight limits by local time) at the user’s location?

I think that in current version
“solar()”
plots a map like I showed. For more examples see the solar man page and examples. To see the manual type
@? solar

(Sorry, I’m in travel)

1 Like

While I don’t integrate this into a more automatic way, you can do

split(readlines(`curl -s ipinfo.io/loc`)[1], ",")
2-element Vector{SubString{String}}:
 "38.7167"
 "-9.1333"

solar(proj=(name=:ortho, center=(-9.1, 38.7)), terminators=:d, fill="navy@75", coast=true, show=1)

And ofc you can use other projections and even add more terminators (twilights)

1 Like

FWIW some people might not want a library making web requests unexpectedly.

As is it is not unexpectedly. And when implemented it will be a documented option. So, a volunteer usage.