FileManDateTimeFormat { public static PointInTime parse(String text) { if (text == null) return null; if (text.isEmpty()) return null; Matcher fileManMatcher = FILE_MAN_DATE_PATTERN.matcher(text); if (!fileManMatcher.matches()) { try { PointInTime t = RelativeDateTimeFormat.parse(text); return t; } catch (IllegalArgumentException relativeParseException) { } throw new IllegalArgumentException("'" + text + "' is not a recognized FileMan date/time pattern"); } if (isMidnight(text)) { return convertMidnightToOneMillisecondBefore(text); } PointInTime t = pointInTimeParser().parsePointInTime(text); if (t.getPrecision().greaterThanOrEquals(Precision.HOUR)) t = t.promote().getLow(); return t; } protected  FileManDateTimeFormat(); static DateTimeFormatter date(); static DateTimeFormatter time(); static DateTimeFormatter dateTime(); static PointInTimeFormatter pointInTimeParser(); static PointInTime parse(String text); static PointInTime toPointInTime(String text); static PointInTime parsePointInTime(String text); static LocalDateTime parseLocalDateTime(String text);  }
@Test public void testParsePointInTimeWithNullOrEmptyString() { Assert.assertNull(FileManDateTimeFormat.parse(null)); Assert.assertNull(FileManDateTimeFormat.parse("")); }
@Test public void testParsePointInTimeWithInvalidStrings() { try { FileManDateTimeFormat.parse("275"); Assert.fail("expected " + IllegalArgumentException.class); } catch (IllegalArgumentException e) { } try { FileManDateTimeFormat.parse("2750000."); Assert.fail("expected " + IllegalArgumentException.class); } catch (IllegalArgumentException e) { } }
@Test public void testParseMidnight() { PointInTime t = FileManDateTimeFormat.parse("3060924.24"); Assert.assertEquals(Precision.MILLISECOND, t.getPrecision()); Assert.assertEquals(2006, t.getYear()); Assert.assertEquals(9, t.getMonth()); Assert.assertEquals(24, t.getDate()); Assert.assertEquals(23, t.getHour()); Assert.assertEquals(59, t.getMinute()); Assert.assertEquals(59, t.getSecond()); Assert.assertEquals(999, t.getMillisecond()); }
@Test public void testParseRelativeDateExpressions() { PointInTime t = FileManDateTimeFormat.parse("T"); assertThat(t, is(PointInTime.today())); t = HL7DateTimeFormat.parse("T+3d"); assertThat(t, is(PointInTime.today().addDays(3))); t = FileManDateTimeFormat.parse("TODAY-4M"); assertThat(t, is(PointInTime.today().subtractMonths(4))); }