Skip to content

Latest commit

 

History

History
249 lines (140 loc) · 6.45 KB

API.md

File metadata and controls

249 lines (140 loc) · 6.45 KB

Table of Contents

OpeningHoursParser

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

Parameters

  • value string The opening_hours=* value

getTable

Get the parsed value as a table

Returns Object The hours, as { day: [ hours ] }

OpeningHoursBuilder

OpeningHoursBuilder allows to create a clean value for OSM tag opening_hours\=*

Parameters

  • 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

getValue

Get as OSM opening_hours value

Returns string The OSM tag value

IsPeriodValid

Is a given period valid ?

Parameters

  • p Object The period to check

Returns boolean True if valid

DaysToOH

Converts a single list of days into opening_hours syntax

Parameters

Returns string The opening_hours syntax for these days

HoursToOH

Converts a list of hour ranges into opening_hours syntax

Parameters

  • hours Array<string> The list of ranges (each range in format HH:MM-HH:MM)

Returns string The opening_hours syntax for these ranges

TimeToMinutes

Convert a time string like "12:00" into minutes from midnight (0 for 00:00, 720 for 12:00, 1440 for 24:00)

Parameters

  • time string The string to convert

Returns int The amount of minutes since midnight

MinutesToTime

Converts an amount of minutes since midnight into time string like "12:00". This is the revert operation of TimeToMinutes.

Parameters

  • minutes int The amount of minutes since midnight

Returns string The corresponding hour, in format HH:MM

TransportHours

TransportHours is the main class of the library. It contains all main functions which can help managing public transport hours.

tagsToHoursObject

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=*

Parameters

  • 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.

intervalsObjectToTags

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).

Parameters

  • 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

intervalConditionalStringToObject

Reads an interval:conditional=* tag from OpenStreetMap, and converts it into a JS object.

Parameters

Returns Array<Object> A list of rules, each having structure { interval: minutes (int), applies: opening hours table }

intervalStringToMinutes

Converts an interval=* string into an amount of minutes

Parameters

Returns number The amount of minutes (can be a decimal values if seconds are used)

minutesToIntervalString

Converts an amount of minutes into an interval=* string

Parameters

  • minutes number The amount of minutes

Returns string The interval string, in HH:MM:SS format