Parsing opening_hours

I’d like to make a web page that shows all local pharmacies, including whether or not they’re open. So, I need to parse the opening_hours key, and I just can’t seem to get a handle on it.

Has anyone else written code that uses this key? How did you do it? I’m writing in PHP, but frankly any code would probably be useful at this stage.


What are you having problems with specifically?

I’d like to work out whether or not the pharmacy is open now. I figured I’d do that by working out the opening times for today (eg Tuesday), and then work out whether or not the current time is within the “open” window.

I can’t work out how to split a string like “mo-fr 09:00-13:00,14:00-18:00;th 09:00-13:00;sa 09:00-13:00” into either just today’s opening times, or a set of times (one per day)

It looks like it should be simple, but I just don’t seem to be able to get anywhere with it.


I’d start by splitting by semicolons, that will give you something like:

mo-fr 09:00-13:00,14:00-18:00
th 09:00-13:00
sa 09:00-13:00

Then you split on spaces:


You can assume if there is a 3rd param it will be on/off and is on if missing.

The first param will be day or days, try splitting by ‘-’, param 1 will be the start and if param2 is blank start=stop

Next splitting the time will be a little more tricky, start by splitting by the comma or commas and loop through each section splitting by ‘-’

Thanks, that was pretty much the way I was thinking, but for some reason just couldn’t actually get the code right.

I’ve now got it almost working. There is still a bug in that it stops checking as soon as it finds a case that would mean the pharmacy is open, so in the cases quoted above, the pharmacy would be shown as open on Thursday afternoon (because “mo-fr 09:00-13:00,14:00-18:00” comes before “th 09:00-13:00”). I’ll look into fixing that later, at least I’ve now got a solid foundation to work from.

Just in case anyone finds this thread in future when they have a similar issue, I’ve now got the code working with a few limitations, and I’ve put it on the wiki:

I’ve now got an svn account, so the latest version of the code will always be at