User:M!dgard/Key:opening hours/Syntax

From OpenStreetMap Wiki
Jump to navigation Jump to search

This page is meant to explain the full syntax of the opening_hours=* key.

Structure

The opening_hours=* values all have in common a same structure. They are a list of rules, and each rule defines an opening or closing time for a given range of days, weeks, months... These rules are separated by some special characters (semicolons, commas, double pipes). Let's take an example:

opening_hours=Mo-We 10:00-18:00; Th,Fr 16:00-23:00; PH off || "on appointment"

Everything here in red is a rule, and everything in blue is a separator.


Rules

A rule defines an opening or closing time. Each rule has two parts: a date selector and a time selector. Let's take an example, the first rule used in the previous opening_hours:

Mo-We 10:00-18:00

The part in red is the date selector, and the part in blue is the time selector. This example means "it is open from 10:00 to 18:00 on Monday, Tuesday and Wednesday". This rule alone doesn't say what happens on other days of the weeks.

A rule can have date and time, or only one of the two. A rule with only a time selector means it applies everyday, and a rule with only a date selector means it applies on the given days, but during all the day (24/24). See #Other rules for more complex examples of rules.


Date selector

A date selector defines on which days a rule applies. We will use the following abbreviations:

  • YYYY means the year on 4 digits
  • MMM the month on 3 characters (Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec)
  • DD means the day of the month on 2 digits
  • WW means the week of the year on 2 digits
  • WD means a weekday on two characters (Mo, Tu, We, Th, Fr, Sa, Su).
  • N means a integer positive number.

There are several sorts of date selectors:

  • Precise day: a day in the year, or an interval of precise days
    • Syntax: YYYY MMM DD or MMM DD or YYYY MMM DD-YYYY MMM DD or MMM DD-MMM DD or MMM DD-DD
    • Examples:
      • 2015 Apr 03
      • Jan 15
      • 2014 Feb 28-2017 Aug 03
      • Jan 01-Aug 15
      • Feb 15-28
  • Monthday: A day or a range of days during a month
    • Syntax: day DD or day DD-DD or day DD-DD/N
    • Examples:
      • day 03 for the third day of a month
      • day 01-15 for the first half of a month
      • day 01-15/2 for one day over two from first day of the month to the 15th day of month.
  • A week or a range of weeks
    • Syntax: week WW or week WW-WW or week WW-WW/N
    • Examples:
      • week 01 for the first week of the year
      • week 10-15 for each week from week 10 to 15
      • week 10-30/3 for one week over three from week 10 to week 30
  • A weekday or a list of weekdays
    • Syntax: WD or WD-WD
    • Examples:
      • Mo for Monday
      • Mo-Fr for everyday from Monday to Friday
  • Holidays
    • Syntax: PH for public holidays, SH for school holidays, easter

Combination

The previous date selectors can be used alone, or they can be combined. We can distinguish two cases:

Same kind of selectors

You can combine several selectors which are of the same kind, for example two ranges of weeks. Here, they will be separated by commas (without any space after the comma). This will signify that the rule apply on each defined date selector (the first one OR the second one OR the third one...).

  • Examples:
    • Apr 01,May 02,Jun 03
    • 2015,2016
    • day 01-15,20-25
    • week 01-10,20-25,32-36
    • Mo,Tu,Fr-Su

Different kind of selectors

You can also combine several selectors which are of different kind. In this case, they are separated by spaces. This will signify that the given rule applies if ALL the selectors are fulfilled. For example, Apr Mo will concern all the Mondays during April. The selectors must be sorted from wider to smaller. Here are some examples:

  • Apr Mo,Tu
  • week 01-15 We-Fr
  • 2015 Jun-Sep Fr-Su
  • 2010-2020 PH
  • SH Mo-Fr

Time selector

Other rules