Create dayMonth array if needed

This commit is contained in:
crimean 2018-10-11 21:44:53 +03:00
parent 77eb9e128c
commit 5c3985d1fb

View file

@ -647,8 +647,7 @@ public class OpeningHoursParser {
/** /**
* represents the list on which day it is open. * represents the list on which day it is open.
*/ */
private boolean[][] dayMonths = new boolean[12][31]; private boolean[][] dayMonths = null;
private boolean hasDayMonths = false;
/** /**
* lists of equal size representing the start and end times * lists of equal size representing the start and end times
@ -696,13 +695,15 @@ public class OpeningHoursParser {
/** /**
* @return the day months of the rule * @return the day months of the rule
*/ */
public boolean[][] getDayMonths() {
return dayMonths;
}
public boolean[] getDayMonths(int month) { public boolean[] getDayMonths(int month) {
if (dayMonths == null) {
dayMonths = new boolean[12][31];
}
return dayMonths[month]; return dayMonths[month];
} }
public boolean hasDayMonths() {
return dayMonths != null;
}
/** /**
* return an array representing the months of the rule * return an array representing the months of the rule
@ -988,7 +989,7 @@ public class OpeningHoursParser {
break; break;
} }
} }
boolean allDays = !hasDayMonths; boolean allDays = !hasDayMonths();
if (!allDays) { if (!allDays) {
boolean dash = false; boolean dash = false;
boolean first = true; boolean first = true;
@ -1406,16 +1407,16 @@ public class OpeningHoursParser {
int i = cal.get(Calendar.DAY_OF_WEEK); int i = cal.get(Calendar.DAY_OF_WEEK);
int day = (i + 5) % 7; int day = (i + 5) % 7;
int previous = (day + 6) % 7; int previous = (day + 6) % 7;
boolean thisDay = hasDays || hasDayMonths; boolean thisDay = hasDays || hasDayMonths();
if (thisDay && hasDayMonths) { if (thisDay && hasDayMonths()) {
thisDay = dayMonths[month][dmonth]; thisDay = dayMonths[month][dmonth];
} }
if (thisDay && hasDays) { if (thisDay && hasDays) {
thisDay = days[day]; thisDay = days[day];
} }
// potential error for Dec 31 12:00-01:00 // potential error for Dec 31 12:00-01:00
boolean previousDay = hasDays || hasDayMonths; boolean previousDay = hasDays || hasDayMonths();
if (previousDay && hasDayMonths && dmonth > 0) { if (previousDay && hasDayMonths() && dmonth > 0) {
previousDay = dayMonths[month][dmonth - 1]; previousDay = dayMonths[month][dmonth - 1];
} }
if (previousDay && hasDays) { if (previousDay && hasDays) {
@ -1848,10 +1849,6 @@ public class OpeningHoursParser {
} }
if (!presentTokens.contains(TokenType.TOKEN_MONTH)) { if (!presentTokens.contains(TokenType.TOKEN_MONTH)) {
Arrays.fill(basic.getMonths(), true); Arrays.fill(basic.getMonths(), true);
} else {
if (presentTokens.contains(TokenType.TOKEN_DAY_MONTH)) {
basic.hasDayMonths = true;
}
} }
if (!presentTokens.contains(TokenType.TOKEN_DAY_WEEK) && !presentTokens.contains(TokenType.TOKEN_HOLIDAY) && if (!presentTokens.contains(TokenType.TOKEN_DAY_WEEK) && !presentTokens.contains(TokenType.TOKEN_HOLIDAY) &&
!presentTokens.contains(TokenType.TOKEN_DAY_MONTH)) { !presentTokens.contains(TokenType.TOKEN_DAY_MONTH)) {