I'm writing an integration with Yammer and it returns a time zone string that looks like this:
Pacific Time (US & Canada)
How does one parse this into a TimeZone or DateTimeZone on the JVM? I've tried TimeZone.getTimeZone and DateTimeZone.forID but to no avail.
It would appear that Yammer returns a
timezone
field as part of theuser
object in its REST API. An example can be seen as part of the authorization docs in the response body in the section labeled "C. App Authentication", and looks like:This is also returned from any of the
GET /users/...
APIs. From experimenting, I can see that the value returned by the API corresponds to the keys of the drop-down list that appears in the user account settings screen (found athttps://yammer.com/<your domain>/account/display_options
) :When you view the source of this web page, you can see the drop-down list with all of the keys and values:
The question was about how to translate these? Well, I don't have any hard proof, but it would appear that these time zone keys are all partial bits of Windows time zone display names. They're not distinct identifiers in Windows, or any Microsoft technology. I am puzzled why Yammer would choose these as time zone ids. But the way you would go about it is as follows:
Look at the CLDR Windows Zone mapping file. You'll see entries such as:
Search for the Yammer time zone key in the comment lines, as a partial substring match. For example, if the Yammer time zone is
"La Paz"
, it would match to the entry with the comment<!-- (UTC-07:00) Chihuahua, La Paz, Mazatlan -->
Take the IANA time zone ID from the very next line following the comment. It will be the one with marked with
territory="001"
. You want thetype
field. For the previous example, this would be"America/Chihuahua"
.You can use that ID in Java with any of the standard Java 7 or Java 8 APIs (or with Joda Time).
One last point. I checked (via the users API) the
timezone
setting of many people in my own Yammer network that I know to be in other time zones, and only a few had ever changed their time zone from the"Pacific Time (US & Canada)"
default setting. Therefore, I would be suspicious to trust these values to be accurate. As far as I can tell, there's nothing that would force a Yammer user to change this setting from the default, and they have to go out of their way to do it.