broader location searches
the tzdata database is pretty awesome: it provides us with lots of cities and places around the world, and allows us to (generally) reliably tell what time it is over there.
but it's far from an exhaustive list of places. if i ask, for example, about the time in Bruges, undertime
gets confused quickly:
anarcat@angela:~$ undertime --timezone Bruges
WARNING: unknown zone, skipping: Bruges
ERROR: No valid time zone found.
anarcat@angela:~[1]$
I mean at least it fails fast (well, relatively: 200ms, see also #25) and doesn't give a garbage answer. but it's not very satisfying for people that live in Bruges.
(Interestingly, I have no frigging clue what the timeone is in Bruges. Belgium, is that aligned with Paris? Or Berlin? Or Amsterdam? Why do I need to know all of this? I just want to know what time it is in Bruges damnit.)
(Of course the answer is "yes", to all questions, and time is UTC+1 except in the summer (which needs to be defined here) where it is UTC+2, except it Europe unblocks a proposal to abolish daylight savings. This is hard folks.)
Anyway. There Must Be A Better Way...
Turns out: there is! I found this thing called Geonames that has a plethora of Names of Places, whatever that means. It's a gigantic (361MB) database of places, built as basically a TSV (tab-separated value, which some people mysteriously call a CSV). It's almost usable:
anarcat@angela:Downloads$ grep Bruges BE.txt | head -1
2783074 Kanaal Brugge-Oostende Kanaal Brugge-Oostende Canal d'Ostende a Bruges,Canal d'Ostende à Bruges,Kanaal Brugge-Oostende,Oostende-Brugge 51.23333 2.93333 H CNL BE VLG VWV 04 Europe/Brussels 2019-12-03
that, of course, is not Bruges, it's a canal in Bruges. But, maybe, good enough?
Turns out there's a lot of shit in that database. The above is, indeed a canal (CNL
is the code), and not the city. For that, you need to restrict your search to a "populated place" (PPL
):
anarcat@angela:Downloads$ grep Bruges BE.txt | grep PPL
2786581 Sint-Michiels Sint-Michiels Saint-Michel,Saint-Michel-lez-Bruges,Sint-Michiels 51.18806 3.21142 P PPL BE VLG VWV 31 31005 12297 7 Europe/Brussels 2020-05-25
2800931 Brugge Brugge Brige,Briuge,Briugė,Briz,Brizh,Briž,Brjuge,Brjugge,Broegge,Brudje,Bruegge,Brugae,Brugeh,Bruges,Brugge,Bruggy,Brugia,Brugo,Bruhhe,Brujas,Bruxas,Bruza,Bruĝo,Brycg,Brygge,Bryugge,Bryz,Brögge,Brügge,beulwiheo,briuge,bruch,bruja,brwj,brwkhh,brwyz,brwz,bu lu he,bu lu ri li shi zhong xin,buruhhe,Μπρυζ,Бриж,Бругэ,Брюгге,Брюге,Բրյուգգե,ברוז,بروج,بروخه,برویز,ब्रूज,บรูช,ბრიუგე,ブルッヘ,布吕赫,布鲁日历史中心,브뤼허 51.208923.22424 P PPL BE VLG VWV 31 31005 118509 13 Europe/Brussels 2023-02-19
... but even that doesn't give us the right answer at first! See, only the second entry here is the actual city of Bruges...
Obviously, all of those results actually give us the right answer anyways (Europe/Brussels
is, as it turns out, the IANA zone, which undertime does know about). But that's kind of a coincidence: in the above we're grepping the BE.txt
dataset... if we'd look around the world, we'd find there's also a Bruges in France (because of course there fucking is).
It might be easier to have undertime just talk to their web service instead. This, for example, gives us the right answer if we just take the first hit:
https://www.geonames.org/search.html?q=bruges&country=
but this is where the rubber meets the proverbial road, so to speak: then you get into their API thingie and it's unclear if you can just use that for free... at the very least you need to register.
So anyway, that's my research into this... if anyone else knows of a good (free?) way to get name -> TZ information that's broader than just tzdata, i'm all ears!