Skip to content

Commit

Permalink
Fixed Forecast Temperature when using OpenWeatherMap
Browse files Browse the repository at this point in the history
Prior to this code change, forecast temperatures using OpenWeatherMap failed to load correctly. It does now.
  • Loading branch information
shawnline committed Dec 23, 2020
1 parent cd5c464 commit 5445dbc
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 8 deletions.
Binary file added .DS_Store
Binary file not shown.
80 changes: 80 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@
"SettingWidget2ID",
"SettingWidget3ID"
],

"resources": {
"media": [
{
Expand Down
Binary file added src/.DS_Store
Binary file not shown.
16 changes: 9 additions & 7 deletions src/pkjs/weather_owm.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,17 +164,19 @@ function getIconForConditionCode(conditionCode, isNight) {
function extractFakeDailyForecast(json) {
var todaysForecast = {};

// find the max and min of those temperatures
todaysForecast.highTemp = -Number.MAX_SAFE_INTEGER;
todaysForecast.lowTemp = Number.MAX_SAFE_INTEGER;
// Set the high and low temp to the first interval's values. Avoids returning an invalid number as the temperature.
todaysForecast.highTemp = json.list[0].main.temp_max;
todaysForecast.lowTemp = json.list[0].main.temp_min;

for(var i = 0; i < json.list.length; i++) {
if(todaysForecast.highTemp < json.list[i].main.temp_max) {
//Iterates from 1 instead of 0 because we already stored those values
for(var i = 1; i < json.list.length; i++) {
if(json.list[i].main.temp_max < todaysForecast.highTemp) {
todaysForecast.highTemp = json.list[i].main.temp_max;
//console.log('High temp updated to: ' + todaysForecast.highTemp);
}

if(todaysForecast.lowTemp > json.list[i].main.temp_min) {
if(json.list[i].main.temp_min < todaysForecast.lowTemp) {
todaysForecast.lowTemp = json.list[i].main.temp_min;
//console.log('Low temp updated to: ' + todaysForecast.lowTemp);
}
}

Expand Down

0 comments on commit 5445dbc

Please sign in to comment.