@Test public void testParseRelativeDateExpressionsFromAnHL7Date() { PointInTime t = HL7DateTimeFormat.parse("2012+1Y"); assertThat(t, is(new PointInTime(2012).addYears(1))); t = HL7DateTimeFormat.parse("201205+1Y"); assertThat(t, is(new PointInTime(2012, 5).addYears(1))); t = HL7DateTimeFormat.parse("20120524+1Y"); assertThat(t, is(new PointInTime(2012, 5, 24).addYears(1))); t = HL7DateTimeFormat.parse("2012052412+1Y"); assertThat(t, is(new PointInTime(2012, 5, 24, 12).addYears(1))); t = HL7DateTimeFormat.parse("20120524120000+1Y"); assertThat(t, is(new PointInTime(2012, 5, 24, 12, 0, 0).addYears(1))); }
public static PointInTime parse(String text) { if (text == null) return null; if (text.isEmpty()) return null; Matcher hl7Matcher = HL7_PATTERN.matcher(text); if (!hl7Matcher.matches()) { try { PointInTime t = RelativeDateTimeFormat.parse(text); return t; } catch (IllegalArgumentException relativeParseException) { } Matcher hl7AndPeriodMatcher = HL7_AND_PERIOD_PATTERN.matcher(text); if (hl7AndPeriodMatcher.matches()) { String hl7DateStr = hl7AndPeriodMatcher.group(1); String operator = hl7AndPeriodMatcher.group(3); String periodStr = hl7AndPeriodMatcher.group(4); PointInTime t = HL7DateTimeFormat.parse(hl7DateStr); Period p = RelativeDateTimeFormat.getPeriodFormatter().parsePeriod(periodStr); if (operator.equals(RelativeDateTimeFormat.MINUS)) { t = t.subtract(p); } else if (operator.equals(RelativeDateTimeFormat.PLUS)) { t = t.add(p); } return t; } throw new IllegalArgumentException("'" + text + "' is not a recognized HL7 date time pattern"); } return pointInTimeParser().parsePointInTime(text); }
HL7DateTimeFormat { public static PointInTime parse(String text) { if (text == null) return null; if (text.isEmpty()) return null; Matcher hl7Matcher = HL7_PATTERN.matcher(text); if (!hl7Matcher.matches()) { try { PointInTime t = RelativeDateTimeFormat.parse(text); return t; } catch (IllegalArgumentException relativeParseException) { } Matcher hl7AndPeriodMatcher = HL7_AND_PERIOD_PATTERN.matcher(text); if (hl7AndPeriodMatcher.matches()) { String hl7DateStr = hl7AndPeriodMatcher.group(1); String operator = hl7AndPeriodMatcher.group(3); String periodStr = hl7AndPeriodMatcher.group(4); PointInTime t = HL7DateTimeFormat.parse(hl7DateStr); Period p = RelativeDateTimeFormat.getPeriodFormatter().parsePeriod(periodStr); if (operator.equals(RelativeDateTimeFormat.MINUS)) { t = t.subtract(p); } else if (operator.equals(RelativeDateTimeFormat.PLUS)) { t = t.add(p); } return t; } throw new IllegalArgumentException("'" + text + "' is not a recognized HL7 date time pattern"); } return pointInTimeParser().parsePointInTime(text); } }
HL7DateTimeFormat { public static PointInTime parse(String text) { if (text == null) return null; if (text.isEmpty()) return null; Matcher hl7Matcher = HL7_PATTERN.matcher(text); if (!hl7Matcher.matches()) { try { PointInTime t = RelativeDateTimeFormat.parse(text); return t; } catch (IllegalArgumentException relativeParseException) { } Matcher hl7AndPeriodMatcher = HL7_AND_PERIOD_PATTERN.matcher(text); if (hl7AndPeriodMatcher.matches()) { String hl7DateStr = hl7AndPeriodMatcher.group(1); String operator = hl7AndPeriodMatcher.group(3); String periodStr = hl7AndPeriodMatcher.group(4); PointInTime t = HL7DateTimeFormat.parse(hl7DateStr); Period p = RelativeDateTimeFormat.getPeriodFormatter().parsePeriod(periodStr); if (operator.equals(RelativeDateTimeFormat.MINUS)) { t = t.subtract(p); } else if (operator.equals(RelativeDateTimeFormat.PLUS)) { t = t.add(p); } return t; } throw new IllegalArgumentException("'" + text + "' is not a recognized HL7 date time pattern"); } return pointInTimeParser().parsePointInTime(text); } protected  HL7DateTimeFormat(); }
HL7DateTimeFormat { public static PointInTime parse(String text) { if (text == null) return null; if (text.isEmpty()) return null; Matcher hl7Matcher = HL7_PATTERN.matcher(text); if (!hl7Matcher.matches()) { try { PointInTime t = RelativeDateTimeFormat.parse(text); return t; } catch (IllegalArgumentException relativeParseException) { } Matcher hl7AndPeriodMatcher = HL7_AND_PERIOD_PATTERN.matcher(text); if (hl7AndPeriodMatcher.matches()) { String hl7DateStr = hl7AndPeriodMatcher.group(1); String operator = hl7AndPeriodMatcher.group(3); String periodStr = hl7AndPeriodMatcher.group(4); PointInTime t = HL7DateTimeFormat.parse(hl7DateStr); Period p = RelativeDateTimeFormat.getPeriodFormatter().parsePeriod(periodStr); if (operator.equals(RelativeDateTimeFormat.MINUS)) { t = t.subtract(p); } else if (operator.equals(RelativeDateTimeFormat.PLUS)) { t = t.add(p); } return t; } throw new IllegalArgumentException("'" + text + "' is not a recognized HL7 date time pattern"); } return pointInTimeParser().parsePointInTime(text); } protected  HL7DateTimeFormat(); static DateTimeFormatter dateTime(); static DateTimeFormatter forPointInTime(PointInTime t); static DateTimeFormatter forPrecision(Precision p); static PointInTimeFormatter pointInTimeParser(); static PointInTime parse(String text); static PointInTime toPointInTime(String text); static LocalDateTime toLocalDateTime(String text); }
HL7DateTimeFormat { public static PointInTime parse(String text) { if (text == null) return null; if (text.isEmpty()) return null; Matcher hl7Matcher = HL7_PATTERN.matcher(text); if (!hl7Matcher.matches()) { try { PointInTime t = RelativeDateTimeFormat.parse(text); return t; } catch (IllegalArgumentException relativeParseException) { } Matcher hl7AndPeriodMatcher = HL7_AND_PERIOD_PATTERN.matcher(text); if (hl7AndPeriodMatcher.matches()) { String hl7DateStr = hl7AndPeriodMatcher.group(1); String operator = hl7AndPeriodMatcher.group(3); String periodStr = hl7AndPeriodMatcher.group(4); PointInTime t = HL7DateTimeFormat.parse(hl7DateStr); Period p = RelativeDateTimeFormat.getPeriodFormatter().parsePeriod(periodStr); if (operator.equals(RelativeDateTimeFormat.MINUS)) { t = t.subtract(p); } else if (operator.equals(RelativeDateTimeFormat.PLUS)) { t = t.add(p); } return t; } throw new IllegalArgumentException("'" + text + "' is not a recognized HL7 date time pattern"); } return pointInTimeParser().parsePointInTime(text); } protected  HL7DateTimeFormat(); static DateTimeFormatter dateTime(); static DateTimeFormatter forPointInTime(PointInTime t); static DateTimeFormatter forPrecision(Precision p); static PointInTimeFormatter pointInTimeParser(); static PointInTime parse(String text); static PointInTime toPointInTime(String text); static LocalDateTime toLocalDateTime(String text);  }