Skip to content

Repository files navigation

JOSM plugin: Paste opening hours

Converts opening hours written for humans into the OSM opening_hours syntax and applies it to the selected objects.

Mon-Fri 9am-5pm            Mo-Fr 09:00-17:00;
Sat 10-2            →      Sa 10:00-14:00;
Closed Sunday              Su off

Using it

Data → Paste opening hours… (Ctrl+Alt+Shift+H), with at least one object selected.

The dialog pre-fills from the clipboard. The converted value appears below the paste box and is editable — once you type in it, the parser stops overwriting your edit until you change the pasted text again. Apply is enabled whenever the value is valid opening_hours syntax, and writes the tag through JOSM's undo stack.

Anything the parser did not understand is listed below the value rather than dropped silently.

What it handles

  • Day names and ranges in any of the usual spellings: Mon, Monday, Mo, Mon-Fri, Mon/Wed/Fri, Sat & Sun, weekdays, weekends, daily
  • 12- and 24-hour times: 9am-5pm, 9:00 AM – 5:00 PM, 06:00-11:00, noon, midnight
  • Bare numbers, where am/pm is inferred: 9-509:00-17:00, 10-210:00-14:00
  • Closed SundaySu off, 24/7 and Open 24 hours24/7
  • Split shifts: Mon 9-12, 1-5Mo 09:00-12:00,13:00-17:00
  • Days on their own line, the way a table pastes, and days written after the times (9am-5pm Monday through Friday)
  • Table columns with no dash at all, where the opening and closing times are just separated by whitespace or tabs: Monday⇥9:00 AM⇥5:30 PM
  • Open-ended hours: 10am to Close / 5pm to close10:00+ / 17:00+
  • Food/kitchen service hours (Food served 11am-10pm) are noted rather than folded into the general schedule, since opening_hours describes access, not a specific service
  • Conflicting hours given for the same day (e.g. a schedule change the parser can't tie to a date range it understands) are reported rather than merged into a broken value

Not handled: public holidays (PH), comments such as "by appointment", and seasonal or month based rules. Those show up as unrecognized text for you to add by hand.

Building

Needs a JOSM checkout with dist/josm-custom.jar built.

ant -Djosm.dir=/path/to/josm dist      # build dist/openinghours.jar
ant -Djosm.dir=/path/to/josm test      # run the parser corpus
ant -Djosm.dir=/path/to/josm install   # copy the jar to ~/Library/JOSM/plugins

After install, enable openinghours in JOSM's plugin preferences.

Unit tests use the JUnit 5 jars from ~/.ivy2/cache, which the JOSM build populates.

Layout

src/…/openinghours/parse/ holds the conversion and has no dependency on JOSM classes, so it can be tested on its own. The pipeline is:

TextNormalizer  → Tokenizer → FragmentParser → ScheduleBuilder → OpeningHoursValidator
lower case,       day/time    tokens into      per-day schedule   ch.poole parser checks
ASCII dashes,     tokens      day + time       merged into rules  and normalizes formatting
one line per                  fragments
fragment

The validator wraps ch.poole.openinghoursparser, which JOSM already ships and exposes to plugins, so nothing extra is bundled.

License

GPLv2 or later. See LICENSE.

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages