@@ -21,7 +21,7 @@ import { AppService } from './app.service';
2121import { CurrentTemperatureHumidity } from './current-temp-manager' ;
2222import * as $ from 'jquery' ;
2323import { KsDateTime , KsTimeZone } from 'ks-date-time-zone' ;
24- import { doesCharacterGlyphExist , getTextWidth , isEdge , isIE } from 'ks-util' ;
24+ import { doesCharacterGlyphExist , getTextWidth , isEdge , isIE , last } from 'ks-util' ;
2525import { reflow } from './svg-flow' ;
2626import { convertTemp , formatHour , htmlEncode , setSvgHref } from './util' ;
2727import { ForecastData , HourlyConditions } from '../server/src/weather-types' ;
@@ -288,21 +288,19 @@ export class Forecast {
288288
289289 private updateHourlyCache ( forecastData : ForecastData ) : void {
290290 const now = this . appService . getCurrentTime ( ) / 1000 ;
291- let earliestNew = forecastData . hourly [ 0 ] ?. time ?? 0 ;
291+ let earliestNew = forecastData . hourly [ 0 ] ?. time ?? Number . MAX_SAFE_INTEGER ;
292292 let inserted = 0 ;
293293
294- this . cachedHourly = this . cachedHourly . filter ( hour => hour . time > now - 7200 && hour . time < now ) ;
294+ this . cachedHourly = this . cachedHourly . filter ( hour => hour . time >= now - 7200 && hour . time <= now ) ;
295295
296296 if ( now < earliestNew ) {
297297 this . cachedHourly . forEach ( hour => {
298- if ( hour . time < earliestNew ) {
299- forecastData . hourly . splice ( 0 , 0 , hour ) ;
300- ++ inserted ;
301- }
298+ if ( hour . time < earliestNew )
299+ forecastData . hourly . splice ( inserted ++ , 0 , hour ) ;
302300 } ) ;
303301 }
304302
305- earliestNew = forecastData . hourly [ 0 ] ?. time ?? 0 ;
303+ earliestNew = forecastData . hourly [ 0 ] ?. time ?? Number . MAX_SAFE_INTEGER ;
306304
307305 // Still nothing to cover the current hour? Fake it from current conditions.
308306 if ( now < earliestNew && forecastData ?. currently )
@@ -314,7 +312,9 @@ export class Forecast {
314312 } ) ;
315313
316314 for ( let i = inserted ; i < forecastData . hourly . length ; ++ i ) {
317- if ( forecastData . hourly [ i ] . time < now + 7200 )
315+ const t = forecastData . hourly [ i ] . time ;
316+
317+ if ( t <= now + 7200 && ( this . cachedHourly . length === 0 || t > last ( this . cachedHourly ) . time ) )
318318 this . cachedHourly . push ( forecastData . hourly [ i ] ) ;
319319 else
320320 break ;
0 commit comments