Skip to content
Snippets Groups Projects
Commit 62f915f8 authored by Tor-Einar Skog's avatar Tor-Einar Skog
Browse files

Adding timezone awareness to avoid trouble with daily temperature timestamps

parent 04651731
No related branches found
No related tags found
No related merge requests found
...@@ -680,11 +680,11 @@ public class WeatherUtil { ...@@ -680,11 +680,11 @@ public class WeatherUtil {
* @param logInterval @see WeatherObservation * @param logInterval @see WeatherObservation
* @return * @return
*/ */
public Date findFirstHoleInObservationSeries(List<WeatherObservation> observations, Integer logInterval) public Date findFirstHoleInObservationSeries(List<WeatherObservation> observations, Integer logInterval, TimeZone timeZone)
{ {
Collections.sort(observations); Collections.sort(observations);
Date currentTime = observations.get(0).getTimeMeasured(); Date currentTime = observations.get(0).getTimeMeasured();
Calendar cal = Calendar.getInstance(); Calendar cal = Calendar.getInstance(timeZone);
for(WeatherObservation obs:observations) for(WeatherObservation obs:observations)
{ {
if(obs.getTimeMeasured().compareTo(currentTime) != 0) if(obs.getTimeMeasured().compareTo(currentTime) != 0)
......
...@@ -307,25 +307,26 @@ public class WeatherUtilTest extends TestCase { ...@@ -307,25 +307,26 @@ public class WeatherUtilTest extends TestCase {
public void testFindFirstHoleInObservationSeries() public void testFindFirstHoleInObservationSeries()
{ {
TimeZone tz = TimeZone.getTimeZone("Europe/Oslo");
System.out.println("testFindFirstHoleInObservationSeries"); System.out.println("testFindFirstHoleInObservationSeries");
List<WeatherObservation> TM = this.getObservations("/JSONWeatherDataTMDailyComplete.json"); List<WeatherObservation> TM = this.getObservations("/JSONWeatherDataTMDailyComplete.json");
WeatherUtil instance = new WeatherUtil(); WeatherUtil instance = new WeatherUtil();
assertNull(instance.findFirstHoleInObservationSeries(TM, WeatherObservation.LOG_INTERVAL_ID_1D)); assertNull(instance.findFirstHoleInObservationSeries(TM, WeatherObservation.LOG_INTERVAL_ID_1D,tz));
TM = this.getObservations("/JSONWeatherDataTMDailyFaulty.json"); TM = this.getObservations("/JSONWeatherDataTMDailyFaulty.json");
Date result = instance.findFirstHoleInObservationSeries(TM, WeatherObservation.LOG_INTERVAL_ID_1D); Date result = instance.findFirstHoleInObservationSeries(TM, WeatherObservation.LOG_INTERVAL_ID_1D,tz);
System.out.println("Found hole here: " + result); System.out.println("Found hole here: " + result);
assertNotNull(result); assertNotNull(result);
// TEST hourly data // TEST hourly data
TM = this.getObservations("/weatherDataWithoutHolesRR.json"); TM = this.getObservations("/weatherDataWithoutHolesRR.json");
result = instance.findFirstHoleInObservationSeries(TM, WeatherObservation.LOG_INTERVAL_ID_1H); result = instance.findFirstHoleInObservationSeries(TM, WeatherObservation.LOG_INTERVAL_ID_1H,tz);
if(result != null) if(result != null)
System.out.println("Found hole here: " + result); System.out.println("Found hole here: " + result);
assertNull(result); assertNull(result);
TM = this.getObservations("/weatherDataWithHolesRR.json"); TM = this.getObservations("/weatherDataWithHolesRR.json");
result = instance.findFirstHoleInObservationSeries(TM, WeatherObservation.LOG_INTERVAL_ID_1H); result = instance.findFirstHoleInObservationSeries(TM, WeatherObservation.LOG_INTERVAL_ID_1H,tz);
System.out.println("Found hole here: " + result); System.out.println("Found hole here: " + result);
assertNotNull(result); assertNotNull(result);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment