Skip to content

Instantly share code, notes, and snippets.

@lperrin
Last active October 22, 2015 20:08
Show Gist options
  • Save lperrin/542f5dce8e797dec2091 to your computer and use it in GitHub Desktop.
Save lperrin/542f5dce8e797dec2091 to your computer and use it in GitHub Desktop.

Open Hours

A team responding to customers' requests may only be available during certain hours during the week. These open hours could be for example:

  • Monday: 9am to 5pm
  • Tuesday: 9am to 5pm
  • Wednesday: 9am to 5pm
  • Thursday: 9am to 5pm
  • Friday: 9am to 5pm
  • Saturday: 9am to 12am
  • Sunday: closed

If a request is made Tuesday at 4h45pm and the team replies on Wednesday at 10am, we will consider the response time to be 1h15.

Define a general JSON representation for open hours

Imagine that you have a UI letting an administrator define open hours. What format should the API accept?

Implement responseTime()

Write a function (in a language of you choosing): responseTime(time1, time2, openHours) where:

  • time1 and time2 are 2 UNIX timestamps.
  • openHours is the data structure you previously defined.
  • the returned value is the difference between time1 and time2, excluding time where the team was not available.

For example, with the previous example, responseTime(<monday 8am>, <monday 10am>, oh) would be only 1 hour.

Bonus: can you guess the format used in Front?

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