This Java package takes opening hours in OSM format and an instance of java.time.LocalDateTime
and checks
if the POI is open or not at the specified time.
It's available on Maven Central.
compile group: 'io.leonard', name: 'opening-hours-evaluator', version: '<latest version>'
var openingHours = "Mo-Fr 09:00-18:00"
var parser = new OpeningHoursParser(new ByteArrayInputStream(openingHours.getBytes()));
var rules = parser.rules(true);
var time = LocalDateTime.parse("2020-08-07T12:09:17");
OpeningHoursEvaluator.isOpenAt(time, rules);
var openingHours = "Mo-Fr 09:00-18:00"
var parser = new OpeningHoursParser(new ByteArrayInputStream(openingHours.getBytes()));
var rules = parser.rules(true);
var time = LocalDateTime.parse("2020-08-07T12:09:17");
OpeningHoursEvaluator.isOpenAtUntil(time, rules);
var openingHours = "Mo-Fr 09:00-18:00"
var parser = new OpeningHoursParser(new ByteArrayInputStream(openingHours.getBytes()));
var rules = parser.rules(true);
var time = LocalDateTime.parse("2020-08-07T12:09:17");
OpeningHoursEvaluator.isOpenNext(time, rules);
var openingHours = "Mo-Fr 09:00-18:00"
var parser = new OpeningHoursParser(new ByteArrayInputStream(openingHours.getBytes()));
var rules = parser.rules(true);
var time = LocalDateTime.parse("2020-08-07T12:09:17");
OpeningHoursEvaluator.wasOpenLast(time, rules);
Since the opening hours specification is complex,
not every feature is supported. To get an idea of what exactly is working, please check the unit test input files
open.csv
and closed.csv
.