Unable to specify timezone from forecast request
chendaniely opened this issue · 3 comments
Hi. Thanks for your package. I discovered it after looking to create my own home weather display.
I'm having trouble specifying the timezone when using the get_forecast
method from a DarkSky
object.
# nyc lat lon
lat = 40.7128
lon = 74.0060
darksky = DarkSky(API_KEY)
forecast = darksky.get_forecast(
lat, lon,
lang=languages.ENGLISH
)
I'm located in time zone US/Eastern (-5), but i'm getting Asia/Bishkek (+6).
Your GH profile says Ukraine which is +2, so also really confused where it's getting this particular timezone from. And according to darksky, they're located in Cambridge, MA (i.e., US/Eastern)...
>>> currently.time
datetime.datetime(2019, 12, 11, 5, 54, 58, tzinfo=<DstTzInfo 'Asia/Bishkek' +06+6:00:00 STD>)
I'm able to manually convert it
>>> forecast_time = currently.time.astimezone()
>>>
>>> fmt = "%Y-%m-%d %H:%M:%S %Z%z"
>>> print(forecast_time.strftime(fmt))
2019-12-10 18:54:58 Eastern Standard Time-0500
But that would require me to do this manual conversion for each forecast item, e.g.,
>>> forecast.hourly.data[0]
<darksky.forecast.HourlyForecastItem object at 0x0000029A24C7CAC0>
>>> hourly.data[0].time
datetime.datetime(2019, 12, 11, 5, 0, tzinfo=<DstTzInfo 'Asia/Bishkek' +06+6:00:00 STD>)
But ideally, we can specify the timezone during the API request.
I looked into the __ini__
functions for BaseDarkSky
and DarkSky
but they do not provide any way to input a timezone. The get_forecast
method returns a Forecast
object, but am I missing something about not being able to pass in a timezone: str
value? Or would I have to manually call the *Forecast
objects manually?
edit: On further investigation, it seems that it's capturing the correct lat/lon for the weather, but because the timezone is off, it's giving me weather values from around that time in the future.
For example it is not this cold (temp in F) at the moment (it's closer to 52F), and even if the units were in 27C, that would be around 80F....
>>> hourly.data[0].time
datetime.datetime(2019, 12, 11, 5, 0, tzinfo=<DstTzInfo 'Asia/Bishkek' +06+6:00:00 STD>)
>>> hourly.data[0].temperature
27.11
Hi @chendaniely !
Thanks for your investigation. I will fix it today
Version 1.6.0 now
Now we can pass timezone into get_forecast and get_time_machine_forecast
Thanks for the quick fix! seems to be working just great now. 🎉