Skip to content

Arnaudv6/opening-hours-evaluator

 
 

Repository files navigation

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.isOpenAtUntil(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.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 99.3%
  • Makefile 0.7%