public Optional < MeteoExtrasForecast > findNearestForecast ( ZonedDateTime dateTime ) { ZonedDateTime dt = toZeroMSN ( dateTime . withZoneSameInstant ( METZONE ) ) ; PointForecast chosenForecast = null ; for ( Forecast forecast : getLocationForecast ( ) . getForecasts ( ) ) { if ( forecast instanceof PointForecast ) { PointForecast pointForecast = ( PointForecast ) forecast ; if ( isDateMatch ( dt , cloneZonedDateTime ( pointForecast . getFrom ( ) ) ) ) { chosenForecast = pointForecast ; break ; } else if ( chosenForecast == null ) { chosenForecast = pointForecast ; } else if ( isNearerDate ( pointForecast . getFrom ( ) , dt , chosenForecast . getFrom ( ) ) ) { chosenForecast = pointForecast ; } } } if ( chosenForecast == null ) { return Optional . empty ( ) ; } return Optional . of ( new MeteoExtrasForecast ( chosenForecast , getIndexer ( ) . getWidestFitPeriodForecast ( chosenForecast . getFrom ( ) ) . orElse ( null ) ) ) ; }
Get the most accurate forecast for the given date .