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

Changed date format for startDateAscosporeMaturity (to avoid timezone issues)

parent e9c85352
No related branches found
No related tags found
No related merge requests found
package no.bioforsk.vips.model.applescabmodel;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.ArrayList;
import java.util.Calendar;
......@@ -198,7 +200,7 @@ public class AppleScabModel extends I18nImpl implements Model{
"\t\"modelId\":\"" + MODEL_ID.toString() + "\",\n" +
"\t\"configParameters\":{\n" +
"\t\t\"timeZone\":\"Europe/Oslo\",\n" +
"\t\t\"startDateAscosporeMaturity\":\"2012-03-25T00:00:00+01:00\",\n" +
"\t\t\"startDateAscosporeMaturity\":\"2012-03-25\",\n" +
"\t\t\"observations\":[\n" +
"\t\t{\n" +
"\t\t\t\t\"timeMeasured\": \"2012-03-25T00:00:00+02:00\",\n" +
......@@ -238,9 +240,40 @@ public class AppleScabModel extends I18nImpl implements Model{
initCollections();
ObjectMapper mapper = new ObjectMapper();
this.startDateAscosporeMaturity = mapper.convertValue(config.getConfigParameter("startDateAscosporeMaturity"), new TypeReference<java.util.Date>(){});
// Setting timezone
this.timeZone = TimeZone.getTimeZone((String) config.getConfigParameter("timeZone"));
//mapper.convertValue(config.getConfigParameter("timeZone"), new TypeReference<java.util.TimeZone>(){});
//this.startDateAscosporeMaturity = mapper.convertValue(config.getConfigParameter("startDateAscosporeMaturity"), new TypeReference<java.util.Date>(){});
String[] dateparts;
try
{
dateparts = config.getConfigParameter("startDateAscosporeMaturity").toString().split("-");
}
catch (NullPointerException ex){
throw new ConfigValidationException("startDateAscosporeMaturity not set");
}
try
{
Integer year = Integer.valueOf(dateparts[0]);
Integer month = Integer.valueOf(dateparts[1]);
Integer date = Integer.valueOf(dateparts[2]);
Calendar cal = Calendar.getInstance(timeZone);
cal.set(year, month-1, date, 0, 0, 0);
cal.set(Calendar.MILLISECOND, 0);
this.startDateAscosporeMaturity = cal.getTime();
}
catch(NumberFormatException | ArrayIndexOutOfBoundsException ex)
{
throw new ConfigValidationException("Illegal date format for startDateAscosporeMaturity: " + config.getConfigParameter("startDateAscosporeMaturity"));
}
//mapper.convertValue(config.getConfigParameter("timeZone"), new TypeReference<java.util.TimeZone>(){});
this.calculations = new AppleScabCalculations();
List<WeatherObservation> observations = mapper.convertValue(config.getConfigParameter("observations"), new TypeReference<List<WeatherObservation>>(){});
for(WeatherObservation o:observations)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment