Parser for string values according to the OSM opening hours specification
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


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'490 fail (total 36'872).

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

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


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 {
dependencies {
    compile "ch.poole:OpeningHoursParser:0.1.2"