Low commit activity in last 3 years
A long-lived project that still receives updates
Datetime range to opening hours, opening hours to datetime range. Very strongly inspired by YoHours.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Development

>= 0
>= 0

Runtime

>= 0
 Project Readme

Opening Hours Converter

OpenStreetMap Opening Hours to Date & Date to Opening Hours

See Wiki for OpenStreetMap Opening Hours specification.

Installation

gem install opening_hours_converter

Usage

require 'opening_hours_converter'

parsed_oh = OpeningHoursConverter::OpeningHoursParser.new.parse('Mo 10:00-12:00')
oh_string = OpeningHoursConverter::OpeningHoursBuilder.new.build(parsed_oh)

Open intervals over a period

get_open_intervals returns the concrete opening periods of an opening hours string inside a window, as [{ start: Time, end: Time }], sorted by start and clamped to [from, to]. It is the equivalent of getOpenIntervals in opening_hours.js.

OpeningHoursConverter::Iterator.new.get_open_intervals(
  'Mo-Fr 08:00-12:00; Tu off',
  Time.new(2026, 6, 1),
  Time.new(2026, 6, 8)
)
# => [{ start: 2026-06-01 08:00, end: 2026-06-01 12:00 },
#     { start: 2026-06-03 08:00, end: 2026-06-03 12:00 },
#     { start: 2026-06-04 08:00, end: 2026-06-04 12:00 },
#     { start: 2026-06-05 08:00, end: 2026-06-05 12:00 }]

Rules are applied in the order they were written, so a later one overrides an earlier one: Jul-Aug off; Mo-Fr 09:00-17:00 is open in July, while Mo-Fr 09:00-17:00; Jul-Aug off is closed. Intervals crossing midnight end on the following day, and Time values are built from wall clock components, so a daylight saving change does not shift the time of day.

Unlike get_time_iterator, it applies off rules, handles midnight crossings and covers every year the window touches rather than the current one.

Test

Install the dependencies with:

bundle install

Then run all the tests with:

rspec spec --format=documentation

Credits

Done with YoHours as inspiration and with constant help from the Evaluation tool/repository.