So I wrote a Ruby script such that given a city,state such as New York, NY you can get a time zone string such as “America/New York” returned. I used the geocoder and timezone gems. But is there an easy way (i.e., built-in function or library) to map “America/New York” to “EST”? Mapping the city,state to EST/PST/etc is the real result I’m after.
Share
I am not a Ruby programmer, but I do know that the abbreviation information you are looking for is included in the tzdb database. I browsed through the source for the TimeZone ruby gem, but did not find anything on abbreviations, so my guess is that the author of that library did not think it was valuable so did not include it in the parser. (This is just an assumption.)
I did find another Ruby implementation of the tzdb database called TZInfo, and it does appear to expose the abbreviation property for each zone. You may want to investigate using that library instead. I cannot offer specific advice as to which is better in general though.
As others warned in comments, be sure you are only using the abbreviation for display purposes. It is only meaningful to humans, and only when they have some other context such as their location. Worldwide, timezone abbreviations are not unique. There is much ambiguity between them. You can see a full list here.