Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpeningHoursParser: split with splitConditionalTagValue, parse TOKEN_SEASON/TOKEN_WEATHER (draft) #21469

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,8 @@ private void analyze() {
type = HIGHWAY_TYPE;
} else if(t.endsWith(":conditional") && v != null){
conditions = new ArrayList<RouteTypeCondition>();
String[] cts = v.split("\\);");

String[] cts = splitConditionalTagValue(v);
for(String c : cts) {
int ch = c.indexOf('@');
if (ch > 0) {
Expand Down Expand Up @@ -319,6 +320,25 @@ private void analyze() {
}
}
}

private String[] splitConditionalTagValue(String v) {
// 50 @ (Mo-Th 22:00-05:00;Fr 19:00-05:00;Sa,Su); 50 @ winter; 30 @ snow
int parenthesis = 0;
char DELIMITER = '~';
char[] chars = v.toCharArray();
for (int i = 0; i < chars.length; i++) {
if (chars[i] == '(') {
parenthesis++;
}
if (chars[i] == ')') {
parenthesis--;
}
if (chars[i] == ';' && parenthesis == 0) {
chars[i] = DELIMITER;
}
}
return String.valueOf(chars).split(String.valueOf(DELIMITER));
}
}

public static class RouteRegion extends BinaryIndexPart {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1715,7 +1715,9 @@ private enum TokenType {
TOKEN_DAY_WEEK(7),
TOKEN_HOUR_MINUTES (8),
TOKEN_OFF_ON(9),
TOKEN_COMMENT(10);
TOKEN_COMMENT(10),
TOKEN_SEASON(11),
TOKEN_WEATHER(12);

public final int ord;

Expand Down Expand Up @@ -1764,6 +1766,8 @@ public static void parseRuleV2(String r, int sequenceIndex, List<OpeningHoursRul
final String[] daysStr = new String[]{"mo", "tu", "we", "th", "fr", "sa", "su"};
final String[] monthsStr = new String[]{"jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec"};
final String[] holidayStr = new String[]{"ph", "sh", "easter"};
final String[] seasonStr = new String[]{"winter", "summer"};
final String[] weatherStr = new String[]{"wet", "snow", "ice"};
String sunrise = "07:00";
String sunset = "21:00";
String endOfDay = "24:00";
Expand Down Expand Up @@ -1840,6 +1844,12 @@ public static void parseRuleV2(String r, int sequenceIndex, List<OpeningHoursRul
if (t.type == TokenType.TOKEN_UNKNOWN) {
findInArray(t, holidayStr, TokenType.TOKEN_HOLIDAY);
}
if (t.type == TokenType.TOKEN_UNKNOWN) {
findInArray(t, seasonStr, TokenType.TOKEN_SEASON);
}
if (t.type == TokenType.TOKEN_UNKNOWN) {
findInArray(t, weatherStr, TokenType.TOKEN_WEATHER);
}
if (t.type == TokenType.TOKEN_UNKNOWN && ("off".equals(t.text) || "closed".equals(t.text))) {
t.type = TokenType.TOKEN_OFF_ON;
t.mainNumber = 0;
Expand Down Expand Up @@ -1905,6 +1915,22 @@ private static void buildRule(BasicOpeningHourRule basic, List<Token> tokens, Li
// skip rule if the first token unknown
return;
}
if (t != null && t.type == TokenType.TOKEN_SEASON) {
// TODO convert @ winter @ summer into months?
if (i == 0) {
return;
} else {
continue;
}
}
if (t != null && t.type == TokenType.TOKEN_WEATHER) {
// currently unsupported
if (i == 0) {
return;
} else {
continue;
}
}
if (t == null || t.type.ord() > currentParse.ord()) {
presentTokens.add(currentParse);
if (currentParse == TokenType.TOKEN_MONTH || currentParse == TokenType.TOKEN_DAY_MONTH
Expand Down
Loading