use of io.jawg.osmcontributor.model.utils.OpeningMonth in project osm-contributor by jawg.
the class OpeningMonthValueParser method fromValue.
@Override
public OpeningMonth fromValue(String value) {
if (value.trim().isEmpty()) {
return null;
}
OpeningMonth openingMonth = new OpeningMonth();
String[] split = value.split(MONTH_SEP);
if (isMonthPresent(value)) {
// Get the left part of the expression
String monthsValue = split[0];
String[] periods = monthsValue.split(RULE_SEP);
for (String period : periods) {
if (isPeriod(period)) {
OpeningMonth.Month[] months = OpeningMonth.Month.fromDatas(period.split(RANGE_SEP));
for (int i = months[0].ordinal(); i <= months[1].ordinal(); i++) {
openingMonth.setMonthActivated(i, true);
}
} else {
openingMonth.setMonthActivated(OpeningMonth.Month.fromData(period).ordinal(), true);
}
}
} else {
List<OpeningHours> openingHours = openingHoursValueParser.fromValue(value);
if (openingHours != null) {
openingMonth.addOpeningHours(openingHours);
}
}
if (split.length == 2) {
String openingHoursValue = split[1];
if (openingHoursValue != null && !openingHoursValue.trim().isEmpty()) {
List<OpeningHours> openingHours = openingHoursValueParser.fromValue(openingHoursValue);
if (openingHours != null) {
openingMonth.addOpeningHours(openingHours);
}
}
}
return openingMonth;
}
use of io.jawg.osmcontributor.model.utils.OpeningMonth in project osm-contributor by jawg.
the class OpeningTimeValueParserTest method parseAllFields1.
@Test
public void parseAllFields1() {
OpeningTime openingTime = new OpeningTime();
OpeningMonth openingMonth1 = new OpeningMonth();
OpeningHours openingHours1 = new OpeningHours();
OpeningHours openingHours2 = new OpeningHours();
openingMonth1.addOpeningHours(openingHours1);
openingMonth1.addOpeningHours(openingHours2);
openingMonth1.setMonthActivated(1, true);
openingMonth1.setMonthActivated(2, true);
openingHours1.setAllDaysActivated(false);
openingHours1.setDayActivated(2, true);
openingHours2.setAllDaysActivated(false);
openingHours2.setDayActivated(5, true);
openingHours2.setFromTime(new LocalTime(5, 30));
openingHours2.setToTime(new LocalTime(17, 30));
OpeningMonth openingMonth2 = new OpeningMonth();
OpeningHours openingHours3 = new OpeningHours();
OpeningHours openingHours4 = new OpeningHours();
openingMonth2.addOpeningHours(openingHours3);
openingMonth2.addOpeningHours(openingHours4);
openingMonth2.setMonthActivated(3, true);
openingMonth2.setMonthActivated(4, true);
openingHours3.setAllDaysActivated(false);
openingHours3.setDayActivated(6, true);
openingHours4.setAllDaysActivated(false);
openingHours4.setDayActivated(5, true);
openingHours4.setFromTime(new LocalTime(8, 10));
openingHours4.setToTime(new LocalTime(19, 45));
openingTime.addOpeningMonth(openingMonth1);
openingTime.addOpeningMonth(openingMonth2);
Assert.assertEquals(parser.toValue(openingTime), "Feb-Mar: We 08:00-18:00, Sa 05:30-17:30; Apr-May: Su 08:00-18:00, Sa 08:10-19:45");
}
use of io.jawg.osmcontributor.model.utils.OpeningMonth in project osm-contributor by jawg.
the class OpeningTimeValueParserTest method parseMonths1.
@Test
public void parseMonths1() {
OpeningTime openingTime = new OpeningTime();
OpeningMonth openingMonth = new OpeningMonth();
openingMonth.setMonthActivated(0, true);
openingMonth.setMonthActivated(1, true);
openingMonth.setMonthActivated(7, true);
openingMonth.setMonthActivated(8, true);
openingMonth.setMonthActivated(10, true);
openingTime.addOpeningMonth(openingMonth);
Assert.assertEquals(parser.toValue(openingTime), "Jan-Feb,Aug-Sep,Nov");
}
use of io.jawg.osmcontributor.model.utils.OpeningMonth in project osm-contributor by jawg.
the class OpeningTimeValueParserTest method parseDays2.
@Test
public void parseDays2() {
OpeningTime openingTime = new OpeningTime();
OpeningMonth openingMonth = new OpeningMonth();
OpeningHours openingHours = new OpeningHours();
openingHours.setAllDaysActivated(false);
openingMonth.addOpeningHours(openingHours);
openingTime.addOpeningMonth(openingMonth);
openingHours.setDayActivated(5, true);
Assert.assertEquals(parser.toValue(openingTime), "Sa 08:00-18:00");
}
use of io.jawg.osmcontributor.model.utils.OpeningMonth in project osm-contributor by jawg.
the class OpeningTimeValueParserTest method parseMonthAndDays1.
@Test
public void parseMonthAndDays1() {
OpeningTime openingTime = new OpeningTime();
OpeningMonth openingMonth = new OpeningMonth();
OpeningHours openingHours = new OpeningHours();
openingHours.setAllDaysActivated(false);
openingMonth.addOpeningHours(openingHours);
openingMonth.setMonthActivated(0, true);
openingMonth.setMonthActivated(2, true);
openingMonth.setMonthActivated(4, true);
openingMonth.setMonthActivated(5, true);
openingMonth.setMonthActivated(6, true);
openingMonth.setMonthActivated(7, true);
openingMonth.setMonthActivated(8, true);
openingMonth.setMonthActivated(10, true);
openingMonth.setMonthActivated(11, true);
openingHours.setDayActivated(0, true);
openingHours.setDayActivated(1, true);
openingHours.setDayActivated(6, true);
openingTime.addOpeningMonth(openingMonth);
Assert.assertEquals(parser.toValue(openingTime), "Jan,Mar,May-Sep,Nov-Dec: Mo-Tu,Su 08:00-18:00");
}
Aggregations