Skip to content

Commit

Permalink
Correct dateHandler format issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Pluiexo authored and Pluiexo committed Feb 22, 2024
1 parent fce9300 commit a16b2c1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/main/java/plato/parser/DateHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ public static Optional<LocalDate> checkDate(String testDate) throws PlatoExcepti
* @return An Optional that contains LocalTime if it exists.
*/
public static Optional<LocalTime> checkTime(String testTime) throws PlatoException {
//Remove the date so that it is easier to check for the time, and prevent conflicts
Matcher removeDate = PATTERN_DATE.matcher(testTime);
if (removeDate.find()) {
testTime = testTime.replaceAll(removeDate.group(), "");
}

Matcher match = TIME_PATTERN.matcher(testTime);
Matcher am = Pattern.compile("(?i)[ap]m").matcher(testTime);
Expand Down
5 changes: 5 additions & 0 deletions src/test/java/plato/parser/DateHandlerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,9 @@ public void check_date_success() throws PlatoException {
public void checkTime_success() throws PlatoException {
assertEquals(LocalTime.of(18, 0), DateHandler.checkTime("1800 12-04-23").orElse(LocalTime.of(0, 0)));
}

@Test
public void checkTime_dateyearfull_success() throws PlatoException {
assertEquals(LocalTime.of(23, 59), DateHandler.checkTime("2359 15/02/2024").orElse(LocalTime.of(0, 0)));
}
}

0 comments on commit a16b2c1

Please sign in to comment.