Commit e62065e7 authored by R.W.Majeed's avatar R.W.Majeed

timezone support added to date parsing

parent 380bf45b
package de.sekmi.histream.etl.config;
import java.sql.Timestamp;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
......@@ -26,7 +27,9 @@ public class DateTimeColumn extends Column<DateTimeAccuracy>{
*/
@XmlAttribute
String format;
@XmlAttribute
String zone;
public DateTimeColumn(String name, String format){
super(name);
......@@ -56,9 +59,15 @@ public class DateTimeColumn extends Column<DateTimeAccuracy>{
if( formatter == null ){
throw new ParseException("format must be specified for DateTime fields if strings are parsed");
}
ZoneId zoneId;
if( zone != null ){
zoneId = ZoneId.of(zone);
}else{
zoneId = ZoneId.systemDefault();
}
// parse
try{
return DateTimeAccuracy.parse(formatter,input);
return DateTimeAccuracy.parse(formatter,input, zoneId);
}catch( DateTimeParseException e ){
throw new ParseException("Unable to parse date '"+input+"' in column '"+this.column+"'", e);
}
......
package de.sekmi.histream.etl;
import java.io.IOException;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.util.ArrayList;
import java.util.List;
......@@ -11,13 +13,11 @@ import org.junit.Test;
import de.sekmi.histream.DateTimeAccuracy;
import de.sekmi.histream.Observation;
import de.sekmi.histream.ObservationFactory;
import de.sekmi.histream.ObservationSupplier;
import de.sekmi.histream.ext.ExternalSourceType;
import de.sekmi.histream.ext.Patient;
import de.sekmi.histream.ext.Visit;
import de.sekmi.histream.impl.Meta;
import de.sekmi.histream.impl.ObservationFactoryImpl;
import de.sekmi.histream.io.GroupedXMLWriter;
import de.sekmi.histream.io.Streams;
......@@ -103,8 +103,9 @@ public class TestETLSupplier {
Patient p = fact.getExtension(Patient.class);
Assert.assertNotNull(p);
Assert.assertEquals("p1", p.getId());
Assert.assertEquals(DateTimeAccuracy.parsePartialIso8601("2003-02-01"), p.getBirthDate());
Assert.assertEquals(DateTimeAccuracy.parsePartialIso8601("2003-02-11"), p.getDeathDate());
ZoneId zone = ZoneOffset.UTC.normalized();
Assert.assertEquals(DateTimeAccuracy.parsePartialIso8601("2003-02-01",zone), p.getBirthDate());
Assert.assertEquals(DateTimeAccuracy.parsePartialIso8601("2003-02-11",zone), p.getDeathDate());
// TODO verify other patient information
Assert.assertEquals("v1", p.getGivenName());
......@@ -128,7 +129,7 @@ public class TestETLSupplier {
Assert.assertEquals("v1", v.getId());
// TODO make sure custom partial date format is parsed correctly for missing seconds
//Assert.assertEquals(DateTimeAccuracy.parsePartialIso8601("2013-03-20T09:00"), v.getStartTime());
Assert.assertEquals(DateTimeAccuracy.parsePartialIso8601("2013-03-21T13:00:21"), v.getEndTime());
Assert.assertEquals(DateTimeAccuracy.parsePartialIso8601("2013-03-21T13:00:21", ZoneId.systemDefault()), v.getEndTime());
Assert.assertEquals("v1", v.getId());
Assert.assertEquals(null, v.getLocationId());
......
......@@ -40,8 +40,8 @@
<idat>
<patient-id column="patid"/>
<visit-id column="fallnr"/>
<start column="start" format="d.M.u[ H[:m[:s]]]" na="" truncate-to="year"/>
<end column="end" format="d.M.u[ H[:m[:s]]]" na=""/>
<start column="start" format="d.M.u[ H[:m[:s]]]" na=""/>
<end column="end" format="d.M.u[ H[:m[:s]]]" zone="Europe/Berlin" na=""/>
</idat>
<mdat>
<!-- in/out code -->
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment