Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
Raphael
histream
Commits
e62065e7
Commit
e62065e7
authored
Feb 17, 2018
by
R.W.Majeed
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
timezone support added to date parsing
parent
380bf45b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
19 additions
and
9 deletions
+19
-9
histream-import/src/main/java/de/sekmi/histream/etl/config/DateTimeColumn.java
...ain/java/de/sekmi/histream/etl/config/DateTimeColumn.java
+11
-2
histream-import/src/test/java/de/sekmi/histream/etl/TestETLSupplier.java
.../src/test/java/de/sekmi/histream/etl/TestETLSupplier.java
+6
-5
histream-import/src/test/resources/data/test-1-datasource.xml
...ream-import/src/test/resources/data/test-1-datasource.xml
+2
-2
No files found.
histream-import/src/main/java/de/sekmi/histream/etl/config/DateTimeColumn.java
View file @
e62065e7
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
);
}
...
...
histream-import/src/test/java/de/sekmi/histream/etl/TestETLSupplier.java
View file @
e62065e7
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
());
...
...
histream-import/src/test/resources/data/test-1-datasource.xml
View file @
e62065e7
...
...
@@ -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 -->
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment