- See: Original repository
OpeningHoursParser handles parsing of opening_hours=* tag. It only supports basic version of the tag, as we don't need full implementation for public transport hours. Based on ubahnverleih implementation, edited to use vanilla JS syntax
value
string The opening_hours=* value
Get the parsed value as a table
Returns Object The hours, as { day: [ hours ] }
OpeningHoursBuilder allows to create a clean value for OSM tag opening_hours\=*
periods
Array<Object> List of periods (objects like { days: [ "mo", "tu", "we" ], hours: [ "08:00-15:00", "19:30-22:50" ] })options
Object? Other parameters
Get as OSM opening_hours value
Returns string The OSM tag value
Is a given period valid ?
p
Object The period to check
Returns boolean True if valid
Converts a single list of days into opening_hours syntax
Returns string The opening_hours syntax for these days
Converts a list of hour ranges into opening_hours syntax
Returns string The opening_hours syntax for these ranges
Convert a time string like "12:00" into minutes from midnight (0 for 00:00, 720 for 12:00, 1440 for 24:00)
time
string The string to convert
Returns int The amount of minutes since midnight
Converts an amount of minutes since midnight into time string like "12:00". This is the revert operation of TimeToMinutes.
minutes
int The amount of minutes since midnight
Returns string The corresponding hour, in format HH:MM
TransportHours is the main class of the library. It contains all main functions which can help managing public transport hours.
Converts OpenStreetMap tags into a ready-to-use JS object representing the hours of the public transport line. Parsed tags are : interval=*, opening_hours=* and interval:conditional=*
tags
Object The list of tags from OpenStreetMap
Returns Object The hours of the line, with structure { opens: opening hours table, defaultInterval: minutes (int), otherIntervals: interval rules object, otherIntervalsByDays: list of interval by days (structure: { days: string[], intervals: { hoursRange: interval } }), allComputedIntervals: same as otherIntervalsByDays but taking also default interval and opening_hours }. Each field can also have value "unset" if no tag is defined, or "invalid" if tag can't be read.
Converts a JS array of periods (object like { days: [ "mo", "tu" ], intervals: { "08:00-15:00": 15 }) into a set of OpenStreetMap tags (opening_hours, interval and interval:conditional).
-
allIntervals
Array<Object> List of periods to parse (same format as allComputedIntervals from tagsToHoursObject function) -
Throws any Error If input data is invalid
Returns Object Parsed tags
Reads an interval:conditional=* tag from OpenStreetMap, and converts it into a JS object.
intervalConditional
string The interval:conditional tag
Returns Array<Object> A list of rules, each having structure { interval: minutes (int), applies: opening hours table }
Converts an interval=* string into an amount of minutes
-
interval
string The interval string -
Throws Error If interval is invalid
Returns number The amount of minutes (can be a decimal values if seconds are used)
Converts an amount of minutes into an interval=* string
minutes
number The amount of minutes
Returns string The interval string, in HH:MM:SS format