diff --git a/lib/determine-basal/determine-basal.js b/lib/determine-basal/determine-basal.js index 5e3ee78b8..9ada05bbf 100644 --- a/lib/determine-basal/determine-basal.js +++ b/lib/determine-basal/determine-basal.js @@ -184,7 +184,12 @@ var determine_basal = function determine_basal(glucose_status, currenttemp, iob_ } } - if (minAgo > 12 || minAgo < -5) { // Dexcom data is too old, or way in the future + var lastTempAge = 0; + if (typeof iob_data.lastTemp !== 'undefined' ) { + lastTempAge = round(( new Date(systemTime).getTime() - iob_data.lastTemp.date ) / 60000); // in minutes + } + + if ((minAgo > 12 || minAgo < -5) && lastTempAge >= 10) { // Dexcom data is too old, or way in the future rT.reason = "If current system time "+systemTime+" is correct, then BG data is too old. The last BG data was read "+minAgo+"m ago at "+bgTime; // if BG is too old/noisy, or is changing less than 1 mg/dL/5m for 45m, cancel any high temps and shorten any long zero temps } else if ( tooflat ) { @@ -195,7 +200,7 @@ var determine_basal = function determine_basal(glucose_status, currenttemp, iob_ } } // Then, for all such error conditions, cancel any running high temp or shorten any long zero temp, and return. - if (bg <= 10 || bg === 38 || noise >= 3 || minAgo > 12 || minAgo < -5 || tooflat ) { + if (bg <= 10 || bg === 38 || noise >= 3 || ((minAgo > 12 || minAgo < -5) && lastTempAge >= 10) || tooflat ) { if (currenttemp.rate > basal) { // high temp is running rT.reason += ". Replacing high temp basal of "+currenttemp.rate+" with neutral temp of "+basal; rT.deliverAt = deliverAt;