Skip to content

Commit

Permalink
Merge remote-tracking branch 'github/fix_open_ended_date_parsing'
Browse files Browse the repository at this point in the history
  • Loading branch information
simonpoole committed May 14, 2022
2 parents 9068267 + a1d28e2 commit 695ce9a
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 7 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ apply plugin: 'maven-publish'
apply plugin: 'signing'
apply plugin: "jacoco"

version = '0.26.0'
version = '0.27.0'

java {
sourceCompatibility = JavaVersion.VERSION_1_8
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1064,6 +1064,8 @@ DateWithOffset datewithoffset(boolean mo) :
)
)
(
// This tries to, as lax as possible, differentiate between Jan 31+ Mo and Jan 31+Mo, that is an open ended date vs date with an offset
LOOKAHEAD(5, ( < HYPHEN > | < PLUS > ) < WEEKDAY >, { getToken(1).kind == HYPHEN || !precedingWs(getToken(2)) || getToken(5).kind == DAYS })
(
minus = < HYPHEN >
| < PLUS >
Expand Down
15 changes: 9 additions & 6 deletions src/test/java/ch/poole/openinghoursparser/IndividualTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,30 @@
import java.util.Scanner;

/**
* Individual testing for the OpeningHoursParser, receiving
* inputs from System.in
* Individual testing for the OpeningHoursParser, receiving inputs from System.in
*
*
* @author Vuong Ho
*
*/

public class IndividualTest {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
Scanner sc = new Scanner(System.in);
Boolean isStrict = args[0].equals("true");
while(true) {
System.out.println("Parse strings in opening-hours format, empty input will terminate");
while (true) {
System.out.print("Please enter your input: ");
String input = sc.nextLine();
if ("".equals(input)) {
break;
}
try {
OpeningHoursParser parser = new OpeningHoursParser(new ByteArrayInputStream(input.getBytes()));
List<ch.poole.openinghoursparser.Rule> rules = parser.rules(isStrict);
System.out.println("Legal input string");
System.out.println("Detected rules in input string listed below");
for(ch.poole.openinghoursparser.Rule rule : rules) {
System.out.println("\n------------------------------\n");
for (ch.poole.openinghoursparser.Rule rule : rules) {
System.out.println(rule.toDebugString());
}
System.out.println("\n------------------------------\n");
Expand Down
14 changes: 14 additions & 0 deletions src/test/java/ch/poole/openinghoursparser/UnitTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,20 @@ public void dateWithOffset() {

}

@Test
public void openEndedDateRange() {
OpeningHoursParser parser = new OpeningHoursParser(new ByteArrayInputStream("Jan 31+ Mo".getBytes()));
try {
List<Rule> rules = parser.rules(false);
assertEquals(1, rules.size());
List<DateRange> dateRanges = rules.get(0).getDates();
assertEquals(1, dateRanges.size());
assertTrue(dateRanges.get(0).getStartDate().isOpenEnded());
} catch (ParseException pex) {
fail(pex.getMessage());
}
}

@Test
/**
* This doesn't seem to turn up in our test data
Expand Down

0 comments on commit 695ce9a

Please sign in to comment.