#openstreetmap #hours #opening #parser #evaluation #osm #holidays

bin+lib opening-hours

A parser and evaluation tool for the opening_hours fields in OpenStreetMap

35 releases

new 0.9.0 Nov 19, 2024
0.8.2 Oct 30, 2024
0.6.18 Nov 27, 2023
0.6.15 Jun 14, 2023
0.4.1 Feb 22, 2021

#53 in Date and time

Download history 20/week @ 2024-08-02 38/week @ 2024-08-09 31/week @ 2024-08-16 56/week @ 2024-08-23 53/week @ 2024-08-30 126/week @ 2024-09-06 132/week @ 2024-09-13 113/week @ 2024-09-20 159/week @ 2024-09-27 134/week @ 2024-10-04 110/week @ 2024-10-11 98/week @ 2024-10-18 463/week @ 2024-10-25 206/week @ 2024-11-01 165/week @ 2024-11-08 425/week @ 2024-11-15

1,263 downloads per month

MIT/Apache

460KB
5K SLoC

🦀 Rust implementation for OSM Opening Hours

🐍 Python bindings can be found here

A Rust library for parsing and working with OSM's opening hours field. You can find its specification here and the reference JS library here.

Note that the specification is quite messy and that the JS library takes liberty to extend it quite a lot. This means that most of the real world data don't actually comply to the very restrictive grammar detailed in the official specification. This library tries to fit with the real world data while remaining as close as possible to the core specification.

Usage

Add this to your Cargo.toml:

[dependencies]
opening-hours = "0"

Here's a simple example that parse an opening hours description and displays its current status and date for next change:

use chrono::Local;
use opening_hours::OpeningHours;

// Opens until 18pm during the week and until 12am the week-end.
const OH: &str = "Mo-Fr 10:00-18:00; Sa-Su 10:00-12:00";

fn main() {
    let oh: OpeningHours = OH.parse().unwrap();
    let date = Local::now().naive_local();
    println!("Current status is {:?}", oh.state(date));
    println!("This will change at {:?}", oh.next_change(date).unwrap());
}

Supported features

Holidays

A public holiday database is loaded using nager. You can refer to their website for more detail on supported country or if you want to contribute.

Syntax

If you are only interested in parsing expressions but not on the evaluation or if you want to build your own evaluation engine, you should probably rely on the opening-hours-syntax crate.

"Package"


"Syntax Package"


"Documentation"


"Python package"


"Code coverage"
"Worldwide holidays (REST API)"

Dependencies

~4.5MB
~81K SLoC