3 ms·
> The naive way to do so would be via a static mapping of state to time zone but there are a few edge cases that preclude doing this More than a few, state is
by hocuspocus 2y ago
> The naive way to do so would be via a static mapping of state to time zone but there are a few edge cases that preclude doing this
More than a few, state is really the wrong resolution here, US timezones follow counties and native reservations borders.
ZIP codes should probably be good enough but I'd be careful too. If your volume of addresses isn't too crazy, the robust way is to reverse geocode them and use a library that gets you the IANA identifier from timezone shapes.
https://github.com/RomanIakovlev/timeshape https://github.com/RomanIakovlev/timeshape is maintained by a former coworker who could open source some of the work we did internally.
- apelapan 2y agoThere used to be at least one airport in a tribal area in the US, that had the timezone of the reservation (not same as state) but the DST of the surrounding state (not same as reservation). Can't remember the code for it now, had a lot of interesting timezone issues in a previous job.
- kstrauser 2y agoIIRC you crossed 6 time borders in 30 miles if you flew the right straight line across it.
- foobarchu 2y agoMy favorite is the hopi reservation, which does not observe DST and exists entirely inside of the Navajo reservation, which does observe it, and which exists entirely within Arizona, which again does not observe DST, and exists entirely within the United States which does observe DST in the general case.
- 1-more 2y agoI'm guessing that the airport was this one maybe? ttps://en.wikipedia.org/wiki/Window_Rock_Airport Also IIRC (cum grano salis) the federal buildings in the Hopi reservation do observe DST and the state buildings in the Navajo reservation don't. But don't quote me on any of those actually existing. A fun fact circa 2012 was I was writing a PHP server that needed to talk to a Windows server to schedule things. Windows server used Microsoft's own timezone system, not IANA or anything like that. I went looking for an implementation of IANA <-> MS conversion. I ended up finding all these forum posts by Windows Phone (RIP) users in Arizona who had the wrong time on their phones. So it was nice to know that 1) there was no fixing it and 2) they eat their own dogfood.
- deleted 2y ago[deleted]
- ComputerGuru 2y ago> state is really the wrong resolution here, US timezones follow counties County is the smallest resolution one can reasonably use, but in terms of what timezones themselves follow, that would be metro areas. I.E. the Chicago metro area has its timezone and cities (or counties, if you will) that are part of that metro region, even when belonging to other states that largely follow a different time zone, follow the metropolis’ tz instead. (Not arguing with you but clarifying the meaning of “follow” here.)
- NobodyNada 2y ago> US timezones follow counties and native reservations borders. It's worse than that; Malheur County on the eastern border of Oregon is split between Pacific and Mountain time based on whether cities are more economically connected to Idaho or Nevada: https://en.wikipedia.org/wiki/Malheur_County,_Oregon#Time_zones https://en.wikipedia.org/wiki/Malheur_County,_Oregon#Time_zo...