survivingwithandroid / WeatherLib

Android Weather Library: android weather lib to develop weather based app fast and easily
http://survivingwithandroid.github.io/WeatherLib/
640 stars 170 forks source link

Fix parsing time in Yahoo provider if default locale is not english #33

Closed m-rm closed 9 years ago

m-rm commented 9 years ago

There seems to be a bug in android which causes this problem. Try to run these 2 lines with the system language set to German:

SimpleDateFormat sdf = new SimpleDateFormat("h:mm a"); Date d = sdf.parse("7:18 am");

It will fail with ParseException because it doesn't recognize "am" because it expects "vorm". (Short for "Vormittag")

Since Yahoo only supports english anyway (and has no intent to change that https://developer.yahoo.com/forum/General-Discussion-at-YDN/Can-Yahoo-Weather-API-show-by/1275022713000-d78748d9-0247-313b-ad9e-3503b8ea3d07/) we can set the locale to English when parsing to avoid this issue.

As a side note: Samsung seems to have patched this android bug because its working fine on different kinds of Samsung tablets.

I reproduced this bug on Android 4.2.2, and 5.1.1.

survivingwithandroid commented 9 years ago

Thx for your support!