This commit is contained in:
PavelRatushny 2017-12-08 14:41:49 +02:00
parent 8e5a232d21
commit e37be4771c

View file

@ -195,75 +195,47 @@ public class OpeningHoursParser {
} }
public String getNearToOpeningTime(Calendar cal) { public String getNearToOpeningTime(Calendar cal) {
return getOpeningTime(cal, false); return getTime(cal, true, true);
} }
public String getOpeningTime(Calendar cal) { public String getOpeningTime(Calendar cal) {
return getOpeningTime(cal, true); return getTime(cal, false, true);
}
private String getOpeningTime(Calendar cal, boolean nearToOpening) {
String openingAt = getOpeningTimeDay(cal, nearToOpening);
if (Algorithms.isEmpty(openingAt)) {
openingAt = getOpeningTimePrevious(cal, nearToOpening);
}
return openingAt;
}
private String getOpeningTimeDay(Calendar cal, boolean nearToOpening) {
String openingAt = "";
for (OpeningHoursRule r : rules) {
if (r.containsDay(cal) && r.containsMonth(cal)) {
openingAt = r.getTime(cal, false, nearToOpening, true);
}
}
return openingAt;
}
private String getOpeningTimePrevious(Calendar cal, boolean nearToOpening) {
String openingAt = "";
for (OpeningHoursRule r : rules) {
if (r.containsPreviousDay(cal) && r.containsMonth(cal)) {
openingAt = r.getTime(cal, true, nearToOpening, true);
}
}
return openingAt;
} }
public String getNearToClosingTime(Calendar cal) { public String getNearToClosingTime(Calendar cal) {
return getClosingTime(cal, true); return getTime(cal, true, false);
} }
public String getClosingTime(Calendar cal) { public String getClosingTime(Calendar cal) {
return getClosingTime(cal, false); return getTime(cal, false, false);
} }
private String getClosingTime(Calendar cal, boolean nearToClosing) { private String getTime(Calendar cal, boolean nearToEvent, boolean opening) {
String closingAt = getClosingTimeDay(cal, nearToClosing); String time = getTimeDay(cal, nearToEvent, opening);
if (Algorithms.isEmpty(closingAt)) { if (Algorithms.isEmpty(time)) {
closingAt = getClosingTimeNext(cal, nearToClosing); time = getTimeAnotherDay(cal, nearToEvent, opening);
} }
return closingAt; return time;
} }
private String getClosingTimeDay(Calendar cal, boolean nearToClosing) { private String getTimeDay(Calendar cal, boolean nearToEvent, boolean opening) {
String closingAt = ""; String atTime = "";
for (OpeningHoursRule r : rules) { for (OpeningHoursRule r : rules) {
if (r.containsDay(cal) && r.containsMonth(cal)) { if (r.containsDay(cal) && r.containsMonth(cal)) {
closingAt = r.getTime(cal, false, nearToClosing, false); atTime = r.getTime(cal, false, nearToEvent, opening);
} }
} }
return closingAt; return atTime;
} }
private String getClosingTimeNext(Calendar cal, boolean nearToClosing) { private String getTimeAnotherDay(Calendar cal, boolean nearToEvent, boolean opening) {
String closingAt = ""; String atTime = "";
for (OpeningHoursRule r : rules) { for (OpeningHoursRule r : rules) {
if (r.containsNextDay(cal) && r.containsMonth(cal)) { if (((opening && r.containsPreviousDay(cal)) || (!opening && r.containsNextDay(cal))) && r.containsMonth(cal)) {
closingAt = r.getTime(cal, true, nearToClosing, false); atTime = r.getTime(cal, true, nearToEvent, opening);
} }
} }
return closingAt; return atTime;
} }
public String getCurrentRuleTime(Calendar cal) { public String getCurrentRuleTime(Calendar cal) {