Cover image for Code Kata: Opening Hours

Code Kata: Opening Hours

georgewl profile image George W Langham ・1 min read

I was recently working on something for a client where they were going to provide opening and closing hours for each day of the week, and we were going to parse that in our UI.

The client decided to simplify the requirements, but I still think it would be interesting to see some people's solutions to the following challenge.

The Challenge

Given an object with the same structure as this example:

 Monday:{open: '09:00', close: '17:00'},
 Tuesday:{open: '09:00', close:'17:00'},
 Wednesday:{open: '09:00', close:'15:00'},
 Thursday:{open: '09:00', close:'17:00'},
 Friday:{open: '09:00', close:'17:00'},
 Saturday:{open: '10:00', close:'16:00'},
Enter fullscreen mode Exit fullscreen mode

Return a new array of strings which groups continuous days with same hours together, and keeps the rest seperate.

If a day or group of days has no hours, return the day(s) followed by Closed

In the case of the above example, it would return the following

 'Monday-Tuesday: 09:00-17:00'
 'Wednesday: 09:00-15:00'
 'Saturday: 10:00-16:00'
 'Sunday: Closed'
Enter fullscreen mode Exit fullscreen mode

Challenge Criteria:

  • Can work with any dates and times as long as they're in the expected format.
  • Use whatever programming language you feel comfortable with

I'm going to have a play around with this challenge myself and will post how I went about it in the comments, feel free to respond with how you did it.

Posted on by:

georgewl profile

George W Langham


Web and Software Frontend Developer. Used to work in Full-stack JavaScript. Been at this for a few years now, and think I now understand my specific domain pretty well. Still Learning though.


Editor guide