Skip to content

Latest commit

 

History

History
61 lines (47 loc) · 2.16 KB

README.md

File metadata and controls

61 lines (47 loc) · 2.16 KB

OSM opening hours evaluator

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.

Installation

Maven Central

It's available on Maven Central.

compile group: 'io.leonard', name: 'opening-hours-evaluator', version: '<latest version>'

Usage

Is it open now?

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);

When does it close then?

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.isOpenUntil(time, rules);

When is it open next?

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);

When was it last open?

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);

Completeness

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.