Reputation: 5283
What type should I assign to a variable to store opening and closing time of a place? Should it be datetime, time or just a simple string? Which one is easier to manage?
Upvotes: 0
Views: 405
Reputation: 557
Ruby doesn't have a datatype for representing Time of day. The Time datatype in Ruby is the number of seconds since Epoch (1970.01.01T00:00:00 UTC)
But you could represent opening_hours
as the number of seconds since midnight.
Or you could simply define opening_hours
as TimeWithZone (datetime
in the migration), and then ignore the date part.
Upvotes: 1
Reputation: 1527
The best one is to use :time
because you want to store time, not date
Upvotes: 0