All threads / Is there an easy way to display open or closed based on time of day?

Ask A Question

Notifications

You’re not receiving notifications from this thread.

Is there an easy way to display open or closed based on time of day?

Stefan Sanchez asked in General

So, I am making an application that is listing multiple businesses. I am wanting to have a label that displays open or closed for each individual business. Could anyone give me guidance on how to make this possible? I am hoping to store the function within a model, so that it can be stored with the rest of the business information. Thanks!

Hey Stefan,

So my advice with storing this stuff in the model is only to do it if you'll need it for queries. I think that'll be important (filtering by businesses that are open) so it makes sense to be there. Do you have a data format for saving the hours the places are open? Will they always be a consistently open chunk of time like 9-5? I imagine days and weekends will have different hours too. Do you need to handle that as well?

Join the discussion

Want to stay up-to-date with Ruby on Rails?

Join 33,399+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    logo Created with Sketch.

    Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

    © 2020 GoRails, LLC. All rights reserved.