aoles / OpeningHoursParser

Parser for string values according to the OSM opening hours specification

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

OpeningHoursParser

This is a very simplistic parser for string values according to the OSM opening hours specification.

It parses 146'825 (91%) of 161'268 unique test strings in non-strict mode. The remaining 14'443 are likely valid errors, spot checking shows that they have obvious issues. In strict mode further 22'440 fail (total 36'883).

Deviations from the grammar as of this version of the opening hours specification in all modes:

  • case insensitive
  • leading 0s in times optional
  • unicode EN DASH character is allowed for hyphen
  • various unicode whitespace characters are ignored

In non-strict mode the following further differences are allowed:

  • three-character weekday abbreviations
  • German two-letter weekday abbreviations
  • times extending in to the next day that are missing the extra 24 hours are corrected
  • single 0 for minutes
  • minutes in times optional
  • "." and "h" as minutes separators
  • AM and PM time specifications are allowed (plus A.M. and P.M.)
  • holidays following weekdays
  • 24/7 rules with preceding selectors are corrected to 00:00-24:00 time spans
  • list of month days after months ( Jan 1,4,5 )
  • " to " in lieu of a hyphen for ranges
  • date ranges that do not have the month day specified are corrected (Jan - Feb 15 -> Jan 1 - Feb 15)

Converting the data structures generated by parsing back to strings will result in correct data according to the specification.

Usage

try {
	OpeningHoursParser parser = new OpeningHoursParser(
		new ByteArrayInputStream(line.getBytes()));
	ArrayList<Rule> rules = parser.rules(strict);
	// ...
} catch() {
	// ...
}

Including in your project

You can either download the jar from GitHub or add the following to your build.gradle file(s):

repositories {
    maven {
    	jcenter()
    }
}
dependencies {
    compile "ch.poole:OpeningHoursParser:0.1.2"
}

About

Parser for string values according to the OSM opening hours specification

License:MIT License


Languages

Language:Java 100.0%