Question

I am currently working on a appointment booking application where the search results are displayed in a table and the columns contains buttons for a specific time. Please have a look at the attached screenshot:

enter image description here

I am looking for a way where the dates like 1st October to 7th October (as seen in the screenshot) are dynamically populated with the current week dates for example in the current week Monday was 19th November and Sunday is going to be 25th November. I have searched online to find out a way to do this and also I have searched Ruby Toolbox to find something which will help me in achieving this but so far no success.

Can anyone recommend a suitable way of doing this ?

Thanks

Was it helpful?

Solution

I would try to combine the previous answer solution with DateTime.now.beginning_of_week:

week_beginning = DateTime.now.beginning_of_week

7.times do |day_number|

  day = week_beginning + day_number.days

  #assuming we start at 8:30AM
  first_hour = day + 8.hours + 30.minutes

  #you have the 'pivot' for the day, just create as much time ranges as you want now
  hour1 = first_hour + 1.hour
  hour2 = ...
  # (Obviously you will somehow iterate to get all the hours)      
end

Rails date and time support is really fantastic, just have a look at ActiveSupport's extensions.

OTHER TIPS

You can do something like

Time.now + 1.day
Time.now + 2.day
...

in your view for 7 days to get a date for each day of the week, and just substitue Time.now for whatever date you want to start on. Does this accomplish what you're looking for?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top