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.
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.
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.