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

added millisecond precision to timestamp parsing

parent bb3ff3a3
......@@ -51,7 +51,7 @@ import de.sekmi.histream.xml.DateTimeAccuracyAdapter;
*/
@XmlJavaTypeAdapter(DateTimeAccuracyAdapter.class)
public class DateTimeAccuracy implements Comparable<DateTimeAccuracy> {
static final String PARTIAL_FORMATTER_PATTERN = "u[-M[-d['T'H[:m[:s[.S]]][X]]]]";
static final String PARTIAL_FORMATTER_PATTERN = "u[-M[-d['T'H[:m[:s[.SSS]]][X]]]]";
static final DateTimeFormatter PARTIAL_FORMATTER = DateTimeFormatter.ofPattern(PARTIAL_FORMATTER_PATTERN);
// TODO why not use instant, since we always calculate UTC? or Offset/ZonedDateTime?
......@@ -282,11 +282,12 @@ public class DateTimeAccuracy implements Comparable<DateTimeAccuracy> {
// now check for accuracy
ChronoUnit accuracy;
LocalDateTime dateTime;
if( a.isSupported(ChronoField.NANO_OF_SECOND) ){
if( a.isSupported(ChronoField.MILLI_OF_SECOND) ){
// maximum accuracy of nanoseconds
// not supported yet, truncate to seconds
accuracy = ChronoUnit.NANOS;
dateTime = LocalDateTime.from(a);
accuracy = ChronoUnit.MILLIS;
// dateTime = LocalDateTime.from(a);
dateTime = LocalDateTime.of(a.get(ChronoField.YEAR), a.get(ChronoField.MONTH_OF_YEAR), a.get(ChronoField.DAY_OF_MONTH), a.get(ChronoField.HOUR_OF_DAY), a.get(ChronoField.MINUTE_OF_HOUR), a.get(ChronoField.SECOND_OF_MINUTE), a.get(ChronoField.NANO_OF_SECOND));
}else if( a.isSupported(ChronoField.SECOND_OF_MINUTE) ){
accuracy = ChronoUnit.SECONDS;
dateTime = LocalDateTime.of(a.get(ChronoField.YEAR), a.get(ChronoField.MONTH_OF_YEAR), a.get(ChronoField.DAY_OF_MONTH), a.get(ChronoField.HOUR_OF_DAY), a.get(ChronoField.MINUTE_OF_HOUR), a.get(ChronoField.SECOND_OF_MINUTE));
......
......@@ -82,6 +82,8 @@ public class TestDateTimeAccuracy {
assertEquals(ChronoUnit.MINUTES, a.getAccuracy());
a = DateTimeAccuracy.parsePartialIso8601("2001-02-03T04:05:06");
assertEquals(ChronoUnit.SECONDS, a.getAccuracy());
a = DateTimeAccuracy.parsePartialIso8601("2001-02-03T04:05:06.789");
assertEquals(ChronoUnit.SECONDS, a.getAccuracy());
// verify zone offset
// for second accuracy
a = DateTimeAccuracy.parsePartialIso8601("2001-02-03T04:05:06+0800");
......
......@@ -111,6 +111,12 @@ public class FileObservationProviderTest {
ExternalSourceType s = o.getSource();
Assert.assertNotNull(s);
},
(Observation o) -> {
Assert.assertEquals("T:date:msec", o.getConceptId());
// TODO store and calculate time in nanos
Assert.assertEquals(ChronoUnit.SECONDS, o.getStartTime().getAccuracy());
Assert.assertEquals(30, o.getStartTime().toInstantMin().atOffset(ZoneOffset.UTC).getLong(ChronoField.MINUTE_OF_HOUR));
},
(Observation o) -> {
Assert.assertEquals("T:date:mins", o.getConceptId());
Assert.assertEquals(ChronoUnit.MINUTES, o.getStartTime().getAccuracy());
......
......@@ -40,13 +40,14 @@
<source timestamp="2015-09-28T09:41:10Z"/>
<encounter id="XXE12345">
<start>2014-01-01T10:30:00</start>
<end>2014-01-05T10:30:00</end>
<end>2014-01-05T10:30:00.123</end>
<location>Zuhause</location>
<!-- TODO inpatient/outpatient
<provider>xxxa</provider>-->
<source timestamp="2015-09-28T08:41:10Z"/>
<!-- no more <facts> group -->
<fact concept="T:date:secs" start="2014-09-07T10:40:03"/>
<fact concept="T:date:msec" start="2014-09-07T10:40:03.123"/>
<fact concept="T:date:mins" start="2014-09-07T10:40"/>
<fact concept="T:date:hours" start="2014-09-07T10"/>
<fact concept="T:date:day" start="2014-09-07"/>
......
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