-1

What I need in my database could be made as such:

Migration

start_time_hours:integer
start_time_minutes:integer

end_time_hours:integer
end_time_minutes:integer

This is for saving a schedule that repeats every week and needs no other information than this. (An enum for the day, but this seems irrelevant).

Is there a way of doing this that is more the "Rails way", and less hacky?

start_time:time
end_time:time

perhaps?

And (how) would this work more efficient with forms?

Code-MonKy
  • 2,026
  • 2
  • 14
  • 27

2 Answers2

0

Useful information: (source: Is there documentation for the Rails column types?)

  • Date : Stores only a date (year, month, day)
  • Time : Stores only a time (hours, minutes, seconds)
  • DateTime : Stores both date and time
  • Timestamp : Stores both date and time

Note: For the purposes of Rails, both Timestamp and DateTime mean the same thing (use either type to store both date and time). For the TL;DR description of why both exist, read the bottom paragraph (in source link).

So yes, you can do something like

start_time:time
end_time:time

in forms you can use an input type time

<input type="time" name="start_time">

i think this is the best way.

Matias Seguel
  • 788
  • 11
  • 17
0

I would suggest:

start_time: time
duration_in_minutes: integer

In the form you have options, show start and end time and calculate the minutes before saving or show start time plus a pull down with the duration in minutes of the meeting.

s1mpl3
  • 1,456
  • 1
  • 10
  • 14