Here''s an intersting one: I have a client who wants to store hours of operation of a business for their RoR web app. I came up with a solution, but I really don''t like it. I have a MySQL table that has these fields monday_start, monday_end, tuesday_start, tuesday_end, etc., all as time fields. That''s all find and dandy. The kicker is, the client wants the hours to display thusly: If the start and end are the same all week: Monday - Friday 6:00 AM - 10:00 PM If the hours are different for one day only: Monday 6:00 AM - 10:00 PM Tuesday 7:00 AM - 10:00 PM Wednesday - Sunday 6:00 AM - 10:00 PM And so on. I''m really at a loss as to the best way to do the display. If anyone can think of an elegant solution, I''d really appreciate it. Thanks in Advance. -- Posted via http://www.ruby-forum.com/.
On 26-May-06, at 5:33 PM, Guest wrote:> Here''s an intersting one: > > I have a client who wants to store hours of operation of a business > for > their RoR web app. I came up with a solution, but I really don''t like > it. > > I have a MySQL table that has these fields > > monday_start, monday_end, tuesday_start, tuesday_end, etc., all as > time > fields. >I would organize it differently. My table (opening_times) would be just open_at, close_at plus some sort of belongs_to column that points to the owner (i.e. store owner). Then I''d have days_opening_times table that had a weekday (probably just the index, sunday = 0, monday =1) and an id column that pointed to the id of the opening_times table. Then it''s a matter of stepping through the list of weekdays in the days_opening_times table. If two consecutive weekdays have the same opening_times id then it''s a range. If the range two days, you say "monday, tuesday - 9am - 6pm". If the range is more than two days, you say "monday - friday: 6am -9pm". Clearly this is just off the top of my head and may be fatally flawed... but it might be an alternative. Trevor -- Trevor Squires http://somethinglearned.com> That''s all find and dandy. The kicker is, the client wants the > hours to > display thusly: > > If the start and end are the same all week: > > Monday - Friday 6:00 AM - 10:00 PM > > If the hours are different for one day only: > > Monday 6:00 AM - 10:00 PM > Tuesday 7:00 AM - 10:00 PM > Wednesday - Sunday 6:00 AM - 10:00 PM > > And so on. I''m really at a loss as to the best way to do the display. > > If anyone can think of an elegant solution, I''d really appreciate it. > > Thanks in Advance. > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails
On 26-May-06, at 7:33 PM, Guest wrote:> Here''s an intersting one: > > I have a client who wants to store hours of operation of a business > for > their RoR web app. I came up with a solution, but I really don''t like > it. > > I have a MySQL table that has these fields > > monday_start, monday_end, tuesday_start, tuesday_end, etc., all as > time > fields.What about a table like this: store_hours: - store_id - week_day - open_time - close_time You could then select all days for a given store, ordered by start time, close time. Count the number of times each range occurs and decide how many different days until you just list them all individually. If it''s just Thursday they are open late, you''d see 4 x 8am-4pm, and 1 x 8am-6pm. If three are different, maybe list all 5 days.
On 5/26/06, Guest <blamemike@gmail.com> wrote:> > Here''s an intersting one: > > I have a client who wants to store hours of operation of a business for > their RoR web app. I came up with a solution, but I really don''t like > it. > > I have a MySQL table that has these fields > > monday_start, monday_end, tuesday_start, tuesday_end, etc., all as time > fields. > > That''s all find and dandy. The kicker is, the client wants the hours to > display thusly: > > If the start and end are the same all week: > > Monday - Friday 6:00 AM - 10:00 PM > > If the hours are different for one day only: > > Monday 6:00 AM - 10:00 PM > Tuesday 7:00 AM - 10:00 PM > Wednesday - Sunday 6:00 AM - 10:00 PM > > And so on. I''m really at a loss as to the best way to do the display. > > If anyone can think of an elegant solution, I''d really appreciate it. > > Thanks in Advance. > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >I would think about the simplest solution. The times seem essentially to be up to 7 "arbitrary" strings. Unless you need to perform some type of actual date calculation against the open-hours policy, then this data is for display/reference only. So, treat it like display-only user-input data. For editing the list I would even go so far as to treat it like 7 static textboxes that the owner can update any time they want. (I''m expecting up to 7 different hours, one for each day) At display, include the rows that actually contain content. You can think about wether to store empty data for all 7 rows or only those that contain data (I would go with data-content only). Keep it simpler unless you have a further reason to calculate based upon this data. -- ------------------------------ Apple MacBook. Black. It''s the new White! ------------------------------ Peter Fitzgibbons -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060527/a39af2ef/attachment-0001.html
On 26-May-06, at 8:16 PM, Peter Fitzgibbons wrote:> I would think about the simplest solution. The times seem > essentially to be up to 7 "arbitrary" strings. Unless you need to > perform some type of actual date calculation against the open-hours > policy, then this data is for display/reference only. So, treat it > like display-only user-input data.I like this idea. As you''ve said, "unless you need to perform some type of actual date calculation" it would work very well and be quite simple to implement. Two concerns: standardizing the data inputted, and as mentioned, not being able to do calculations--while you might not see any need for them now, maybe you will in the future. Having a thousand entries to re-enter *might make you wish you did it differently.
Sorry guys. But you are totally missing the simplest solution. It would be like this: table store_times store_id :int opening_times :text and into that textfield would come the data: "Monday 6:00 AM - 10:00 PM Tuesday 7:00 AM - 10:00 PM Wednesday - Sunday 6:00 AM - 10:00 PM" You have not said anything here that really tells me that you need some extensive system to handle this and do some complex calculation to find out opening times. Remember that if it''s not needed then it''s just there to increase the chances of a bug. However if there is some other reason for why you need to have all the dates seperate it would help to know why. On 5/27/06, Mike Oligny <mike@schema.ca> wrote:> On 26-May-06, at 8:16 PM, Peter Fitzgibbons wrote: > > > I would think about the simplest solution. The times seem > > essentially to be up to 7 "arbitrary" strings. Unless you need to > > perform some type of actual date calculation against the open-hours > > policy, then this data is for display/reference only. So, treat it > > like display-only user-input data. > > I like this idea. > > As you''ve said, "unless you need to perform some type of actual date > calculation" it would work very well and be quite simple to > implement. Two concerns: standardizing the data inputted, and as > mentioned, not being able to do calculations--while you might not see > any need for them now, maybe you will in the future. Having a > thousand entries to re-enter *might make you wish you did it > differently. > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- -------------- Jon Gretar Borgthorsson http://www.jongretar.net/
Hey J?n, That''s pretty much a solution I posed to my client, but unfortunately, and I kind of left this out of the original message -- they don''t want the UI to be a text field. The client wants to minimize input errors by having them select the times from like a time_select helper. So I could still store it as text, but showing it from the database would be a nightmare. Thanks for all the suggestions above everyone! I''m still thinking about the best solution. Hmm... J?n Borg??rsson wrote:> Sorry guys. But you are totally missing the simplest solution. > > It would be like this: > table store_times > store_id :int > opening_times :text > > and into that textfield would come the data: > "Monday 6:00 AM - 10:00 PM > Tuesday 7:00 AM - 10:00 PM > Wednesday - Sunday 6:00 AM - 10:00 PM" > > You have not said anything here that really tells me that you need > some extensive system to handle this and do some complex calculation > to find out opening times. Remember that if it''s not needed then it''s > just there to increase the chances of a bug. > > However if there is some other reason for why you need to have all the > dates seperate it would help to know why. > > On 5/27/06, Mike Oligny <mike@schema.ca> wrote: >> As you''ve said, "unless you need to perform some type of actual date >> http://lists.rubyonrails.org/mailman/listinfo/rails >> > > > ---- Posted via http://www.ruby-forum.com/.
Oh ok... I thought it was a case of when sometimes you forget the simple things. Btw. To complicate your life even further. The WILL contact you next december because they need to add the holiday opening times to the system and other specific dates. :) I really dislike clients. Can''t live with them. Can''t take their money if they don''t exist. On 5/27/06, Guest <blamemike@gmail.com> wrote:> > Hey J?n, > > That''s pretty much a solution I posed to my client, but unfortunately, > and I kind of left this out of the original message -- they don''t want > the UI to be a text field. The client wants to minimize input errors by > having them select the times from like a time_select helper. So I could > still store it as text, but showing it from the database would be a > nightmare. > > Thanks for all the suggestions above everyone! > > I''m still thinking about the best solution. Hmm... > > > J?n Borg??rsson wrote: > > Sorry guys. But you are totally missing the simplest solution. > > > > It would be like this: > > table store_times > > store_id :int > > opening_times :text > > > > and into that textfield would come the data: > > "Monday 6:00 AM - 10:00 PM > > Tuesday 7:00 AM - 10:00 PM > > Wednesday - Sunday 6:00 AM - 10:00 PM" > > > > You have not said anything here that really tells me that you need > > some extensive system to handle this and do some complex calculation > > to find out opening times. Remember that if it''s not needed then it''s > > just there to increase the chances of a bug. > > > > However if there is some other reason for why you need to have all the > > dates seperate it would help to know why. > > > > On 5/27/06, Mike Oligny <mike@schema.ca> wrote: > >> As you''ve said, "unless you need to perform some type of actual date > >> http://lists.rubyonrails.org/mailman/listinfo/rails > >> > > > > > > -- > > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- -------------- Jon Gretar Borgthorsson http://www.jongretar.net/
Haha!! They already mentioned the holiday hours. Hahah! So I''m thinking I need to have a one (business) to many (hours) association where they can add multiple, and name it. The display formatting is still irking me! Grrrr!!! J?n Borg??rsson wrote:> Oh ok... I thought it was a case of when sometimes you forget the simple > things. > > Btw. To complicate your life even further. The WILL contact you next > december because they need to add the holiday opening times to the > system and other specific dates. :) > I really dislike clients. Can''t live with them. Can''t take their money > if they don''t exist. > > On 5/27/06, Guest <blamemike@gmail.com> wrote: >> >> > >> > However if there is some other reason for why you need to have all the >> >> -- >> Posted via http://www.ruby-forum.com/. >> _______________________________________________ >> Rails mailing list >> Rails@lists.rubyonrails.org >> http://lists.rubyonrails.org/mailman/listinfo/rails >> > > > ---- Posted via http://www.ruby-forum.com/.
Another possibility would be to have a series of helpers whose output would read like <select name="hours_line[1][day1]"><option value="Monday">....</select> - <select name="hours_line[1][day2]"><option value="Optional">....</select>, <select name="hours_line[1][time1]"><option value="Hours go here">....</select> - <select name="hours_line[1][time2]"><option value="Optional">....</select> Then your controller could parse the input so the result is a contiguous string, and place it in a varchar field in your db -----Original Message----- From: rails-bounces@lists.rubyonrails.org [mailto:rails-bounces@lists.rubyonrails.org] On Behalf Of Guest Sent: Saturday, May 27, 2006 3:00 AM To: rails@lists.rubyonrails.org Subject: [Rails] Re: Displaying Hours Hey J?n, That''s pretty much a solution I posed to my client, but unfortunately, and I kind of left this out of the original message -- they don''t want the UI to be a text field. The client wants to minimize input errors by having them select the times from like a time_select helper. So I could still store it as text, but showing it from the database would be a nightmare. Thanks for all the suggestions above everyone! I''m still thinking about the best solution. Hmm... J?n Borg??rsson wrote:> Sorry guys. But you are totally missing the simplest solution. > > It would be like this: > table store_times > store_id :int > opening_times :text > > and into that textfield would come the data: > "Monday 6:00 AM - 10:00 PM > Tuesday 7:00 AM - 10:00 PM > Wednesday - Sunday 6:00 AM - 10:00 PM" > > You have not said anything here that really tells me that you need > some extensive system to handle this and do some complex calculation > to find out opening times. Remember that if it''s not needed then it''s > just there to increase the chances of a bug. > > However if there is some other reason for why you need to have all the > dates seperate it would help to know why. > > On 5/27/06, Mike Oligny <mike@schema.ca> wrote: >> As you''ve said, "unless you need to perform some type of actual date >> http://lists.rubyonrails.org/mailman/listinfo/rails >> > > > ---- Posted via http://www.ruby-forum.com/. _______________________________________________ Rails mailing list Rails@lists.rubyonrails.org http://lists.rubyonrails.org/mailman/listinfo/rails
Oh excellent idea Daniel! Thanks! Daniel Higginbotham wrote:> Another possibility would be to have a series of helpers whose output > would > read like > > <select name="hours_line[1][day1]"><option value="Monday">....</select> > - > <select name="hours_line[1][day2]"><option > value="Optional">....</select>, > <select name="hours_line[1][time1]"><option value="Hours go > here">....</select> - > <select name="hours_line[1][time2]"><option > value="Optional">....</select> > > Then your controller could parse the input so the result is a contiguous > string, and place it in a varchar field in your db-- Posted via http://www.ruby-forum.com/.