Skip to content

Commit

Permalink
automatically handle date/time/date_time precision
Browse files Browse the repository at this point in the history
  • Loading branch information
mhenke-vg committed Apr 13, 2022
1 parent 7c93007 commit 55b71b1
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 48 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Note: version releases in the 0.x.y range may introduce breaking changes.
### Added
- Maven plugin to generate code from templates ([#347](https://github.com/ehrbase/openEHR_SDK/pull/347))
- Example Generator ([#349](https://github.com/ehrbase/openEHR_SDK/pull/349), [#351](https://github.com/ehrbase/openEHR_SDK/pull/351))
- Flatencoding parsing: automatically handle date/time/date_time precision [#352](https://github.com/ehrbase/openEHR_SDK/pull/352)

### Fixed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
import org.ehrbase.serialisation.walker.Context;
import org.ehrbase.webtemplate.path.flat.FlatPathDto;

import java.time.LocalDate;
import java.time.*;
import java.time.temporal.TemporalAccessor;
import java.util.Map;
import java.util.Set;

Expand All @@ -51,7 +52,22 @@ public void handle(
if ("now".equals(s)) {
rmObject.setValue(LocalDate.now());
} else if (s != null) {
rmObject.setValue(DateTimeParsers.parseDateValue(s));
TemporalAccessor temp = DateTimeParsers.parseDateTimeValue(s);
if (temp instanceof OffsetDateTime) {
OffsetDateTime datetime = ((OffsetDateTime) temp);
rmObject.setValue(datetime.toLocalDate());
} else if (temp instanceof LocalDateTime) {
LocalDateTime datetime = ((LocalDateTime) temp);
rmObject.setValue(datetime.toLocalDate());
} else if (temp instanceof LocalDate) {
rmObject.setValue((LocalDate) temp);
} else if (temp instanceof YearMonth) {
// Partials are stored as is
rmObject.setValue((YearMonth) temp);
} else if (temp instanceof Year) {
// Partials are stored as is
rmObject.setValue((Year) temp);
}
}
},
String.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
import org.ehrbase.serialisation.walker.Context;
import org.ehrbase.webtemplate.path.flat.FlatPathDto;

import java.time.OffsetDateTime;
import java.time.*;
import java.time.temporal.TemporalAccessor;
import java.util.Map;
import java.util.Set;

Expand All @@ -51,7 +52,15 @@ public void handle(
if ("now".equals(s)) {
rmObject.setValue(OffsetDateTime.now());
} else if (s != null) {
rmObject.setValue(DateTimeParsers.parseDateTimeValue(s));
TemporalAccessor temp = DateTimeParsers.parseDateTimeValue(s);
if (temp instanceof LocalDateTime) {
LocalDateTime local = ((LocalDateTime) temp);
OffsetDateTime offset = local.atZone(ZoneId.systemDefault()).toOffsetDateTime();
rmObject.setValue(offset);
} else {
// OffsetDateTime and Partials (LocalDate, YearMonth, Year)
rmObject.setValue(temp);
}
}
},
String.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
import org.ehrbase.serialisation.walker.Context;
import org.ehrbase.webtemplate.path.flat.FlatPathDto;

import java.time.OffsetTime;
import java.time.*;
import java.time.temporal.TemporalAccessor;
import java.util.Map;
import java.util.Set;

Expand All @@ -51,7 +52,26 @@ public void handle(
if ("now".equals(s)) {
rmObject.setValue(OffsetTime.now());
} else if (s != null) {
rmObject.setValue(DateTimeParsers.parseTimeValue(s));
TemporalAccessor temp;
try {
temp = DateTimeParsers.parseTimeValue(s);
} catch (IllegalArgumentException e) {
temp = DateTimeParsers.parseDateTimeValue(s);
}
if (temp instanceof LocalDateTime) {
LocalDateTime dateTime = ((LocalDateTime) temp);
rmObject.setValue(dateTime.toLocalTime());
} else if (temp instanceof OffsetDateTime) {
OffsetDateTime dateTime = ((OffsetDateTime) temp);
rmObject.setValue(dateTime.toOffsetTime());
} else if (temp instanceof LocalDate
|| temp instanceof YearMonth
|| temp instanceof Year) {
rmObject.setValue(LocalTime.MIN);
} else {
// OffsetTime, LocalTime
rmObject.setValue(temp);
}
}
},
String.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,48 +34,6 @@ public void testProportionFailed1() throws Exception {}
*/
public void testProportionFailed2() throws Exception {}

@Override
/*
see https://jira.vitagroup.ag/browse/CDR-143
*/
public void testDate1() throws Exception {}

@Override
/*
see https://jira.vitagroup.ag/browse/CDR-143
*/
public void testDate2() throws Exception {}

@Override
/*
see https://jira.vitagroup.ag/browse/CDR-143
*/
public void testTime1() throws Exception {}

@Override
/*
see https://jira.vitagroup.ag/browse/CDR-143
*/
public void testTime() throws Exception {}

@Override
/*
see https://jira.vitagroup.ag/browse/CDR-143
*/
public void testTime2() throws Exception {}

@Override
/*
see https://jira.vitagroup.ag/browse/CDR-143
*/
public void testDateTime1() throws Exception {}

@Override
/*
see https://jira.vitagroup.ag/browse/CDR-143
*/
public void testDateTime2() throws Exception {}

@Override
/*
Test error behavior which is not path of the spec
Expand Down

0 comments on commit 55b71b1

Please sign in to comment.