Skip to content

Instantly share code, notes, and snippets.

@icoloma
Last active December 19, 2015 06:19
Show Gist options
  • Save icoloma/5910377 to your computer and use it in GitHub Desktop.
Save icoloma/5910377 to your computer and use it in GitHub Desktop.
In which a data model for Opening Hours gets introduced with an evil plan to get transformed into a working implementation. Eventually.
var examples = {
// Monday to Friday 9 to 1 and 3 to 7
"Mon,Tue,Wed,Thu,Fri": "09:00-13:00,15:00-19:00",
// Saturdays, 9 to 2
"Sat": "09:00-14:00",
// Sundays closed
"Sun": "",
// also closed Dec 24 and Jan 6
"2412,0601": "",
// In summer (June to September) open mornings only
"[0106-0110]Mon,Tue,Wed,Thu,Fri": "09:00-13:00"
}

Behold the Opening Hours spec

This is a proposal for a compact specification of opening hours as a data model. This spec aims to store opening hours as a map of strings following this grossly oversimplified regular expression pseudocode:

(date_interval)?(day,?)+=(time_interval,?)*

Where:

date_interval: an (optional) interval of dates where one (but not both) may be optional. Defines the interval of dates where your hours apply, including the start and excluding the end of the interval: 0101-0102 includes Jan 1 to Jan 31, both inclusive.

\[date?-date?\]

day: a day of the week or a concrete date

Mon|Tue|Wed|Thu|Fri|Sat|Sun|date

date: a day in format ddMM with two digits for the day (01-31) and two for the month (01-12)

\d\d\d\d

time_interval: a time interval in format HH:mm using two digits for the hour (00-23) and two for the minutes (00-59). If no interval is specified it is understood to be closed.

\d\d:\d\d

A working implementation

We'll get into that at some point. So far this is just a quick'n dirty idea, so feel free to sling feedback in the comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment