Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><strong>NEW ANSWER:</strong> I thought about it a bit, I think you actually have the solution in your original idea. For each business, have a storehours ListProperty that only stores times when the business is open, like you currently do. Then calculate the current time, and round it to the nearest half hour, so 12:50 -> 1200, then do a query</p> <pre><code>now = 1200 Select * FROM Business WHERE now in hours </code></pre> <p>I'm not certain about the proper GQL query syntax, but there's definitely an "in" filter. </p> <p><strong>OLD ANSWER (Do not read)</strong>: I'm doing something similar, I don't really have a solution, except for "try something different".</p> <p>Firstly, you need to store both the open and close times. Either as two separate fields, or encode them into one field, like '09001700' for 9-5, or even 'M09001700'. Or hash the two into a number, I don't think this makes a huge difference, whichever way you do it.</p> <p>Then the bad news. I'm not particularly great at number theory, but what we're trying to do here is encode two linear sets of numbers (open and close times) in such a way that you can do a linear > or &lt; comparison on a third number that represents 'now'. I don't think this is possible, you can only get a successful > or &lt; comparison on one of the two numbers, either open or close times. So given that we can only do an inequality on one property, I don't think it's possible to have a single query isolate only the open stores.</p> <p>I also don't think you need to do two queries, you only need to do one query on say the open hours, and then filter through them to see which ones are closed. If you </p> <p>You don't necessarily need to AND two big sets together. You could query on all items where now > opentime, and manually filter through the results looking for items where now &lt; closetime. If you sort the query based on closetime, this should make the filtering somewhat easier.</p> <p>The solution that I eventually went with, which might work for you, is to not query on store hours at all, but query on something that will return a more limited dataset, and then filter the returned results based on store hours. For example, if your users search by location, query your businesses based on the location, and filter the resulting business by store hours, then only display the open ones to the user.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload