Skip to content

getForecastToday() causes fatal error during last hour of day #7

@astratagem

Description

@astratagem

I have only seen this today, but I believe it must happen every day.

I'm using this code to calculate the temperature change:

// Get hourly conditions
$hourly = $forecast->getForecastToday($latitude, $longitude);

...

// Hourly conditions variables
$hour_now           = $hourly[0];
$hour_next          = $hourly[1];
$hour_now_temp      = round($hour_now->getTemperature());
$hour_next_temp     = round($hour_next->getTemperature());
// Temperature change direction
$temp_dir           = $hour_now_temp < $hour_next_temp ? 'rising' : 'falling';

This assumes that there actually is a next hour in the JSON API response. But if it's the last hour of the day (23:00 to 23:59 UTC or 18:00 to 18:59 EST), there is no next hour, so there is nothing in the $hourly array at [1], only [0]. This causes a fatal PHP error, thus breaking everything and ruining everyone's evenings.

The reason that it stops there and doesn't keep going is because getForecastToday() does what it says – it only gets today, so anything in the last hour of the day will theoretically break.

This would of course be slightly less of an issue if I corrected the timezone difference, so that instead of breaking in the evening, it breaks between 23:00 and 23:59 EST.

I'll be working on a workaround, but I think this issue probably goes back to the way things are handled in /lib/forecast.io.php here, not just in my project.

So I will take a look at your code here and see if I can come with a solution and if I do, I'll send a pull request.

templesmc/tuupdate#53

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions