Crates.io | opening-hours |
lib.rs | opening-hours |
version | 0.9.1 |
source | src |
created_at | 2021-02-08 17:49:59.348619 |
updated_at | 2024-11-26 13:06:00.424536 |
description | A parser and evaluation tool for the opening_hours fields in OpenStreetMap. |
homepage | https://github.com/remi-dupre/opening-hours-rs |
repository | https://github.com/remi-dupre/opening-hours-rs |
max_upload_size | |
id | 352415 |
size | 1,888,254 |
🐍 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.
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());
}
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.
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.