zh-wang / YWeatherGetter4a

An Yahoo Weather API wrapper for android
99 stars 45 forks source link

Retrieving time zone information with the weather? #23

Open brisingre opened 8 years ago

brisingre commented 8 years ago

This isn't an issue per se, just a question:

Is there a way to get time zone information with yWeatherGetter4a? I can't find one. There's a few places where it's abbreviated as part of a time stamp, but those abbreviations can correspond to more than one time zone, so that's no good. I know it exists in Yahoo's database, so at worse I can probably modify the library, but before I do that I thought I'd ask:

Is there a way already, that I'm missing? If not, do you have any advice on where to start modifying the library?

zh-wang commented 8 years ago

Sample Weather API Response - Shanghai You can find several timezone related tag in this link.

  1. Wed, 14 Sep 2016 11:14 AM CST
  2. Conditions for Shanghai, Shanghai, CN at 10:00 AM CST
  3. Wed, 14 Sep 2016 10:00 AM CST

I think Yahoo always use CST as default timezone? You can get title or lastBuildDate with get methods of WeatherInfo Object.

brisingre commented 8 years ago

Thanks for the quick response! Those are the abbreviated versions I was talking about -- unfortunately, they're not as useful as they might be. They're not always CST (which is good, I need the local timezone in the place I'm querying about). [(https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20weather.forecast%20where%20woeid%20in%20(select%20woeid%20from%20geo.places(1)%20where%20text%3D%22philadelphia%22))]

Unfortunately, those 3 letter codes sometimes correspond to more than one time zone. CST can be China Standard Time (UTC + 8), Cuba Standard Time (UTC - 5) or Central Standard Time (UTC - 6). If it were just that one I'd try to find a workaround, but it's super common, about half of the abbreviations on this list are used more than once. [https://www.timeanddate.com/time/zones/]

I can get the full timezone from a slightly different Yahoo api request: [https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20geo.places(1)%20where%20text=%22shanghai%22] Right now I'm thinking about adding a second call to the Yahoo API, to get this geo.places info directly. Do you think that's necessary?

zh-wang commented 8 years ago

[https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20geo.places(1)%20where%20text=%22shanghai%22] Yes, this is the call for Yahoo Geo Api, so it will return correct information including timezone. Yahoo's Weather Api, and YWeatherGetter does not have such method to do this. So it is necessary to call Yahoo Geo Api separately.

BTW, It seems that timezone abbreviation in Weather Api's response is depend on the place you searched. (Well, very reasonable)

brisingre commented 8 years ago

I got it working by calling the Geo API seperately. Wasn't nearly as much work as I thought it would be, your code's very readable. Thank you for your help!