I need to model the availability of persons by hours by weekday into an indefinite future, for example, ''person X is available Mondays between 9 and 5pm until August 31, 2013.'' I''m stuck trying to figure out how to store this data to support a query like ''find all persons available on March 26 between 12 and 2pm''. It feels like the only solution is to write EVERY interval implied by the weekly availability specified, but that seems like it will be a PITA when the availability is changed -- will I need to rewrite every date-time I stored, when, say some person X''s availability is changed from mondays to tuesdays and sundays, etc.? Any suggestions on strategies or references to gems for this? (Below follows a rough modeling.) HoursInterval start (hrs:mins) stop (hrs:mins) WeeklyTime sunday (has_many HoursIntervals) monday ... ... saturday ... Availability start (date-time) stop (date-time, can be null) has_one WeeklyTime Thx, Lille -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Peter Vandenabeele
2012-Mar-05 21:27 UTC
Re: rails support for intricate date-time persistence strategies?
On Mon, Mar 5, 2012 at 8:44 PM, Lille <lille.penguini-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I need to model the availability of persons by hours by weekday into > an indefinite future, for example, ''person X is available Mondays > between 9 and 5pm until August 31, 2013.'' > > I''m stuck trying to figure out how to store this data to support a > query like ''find all persons available on March 26 between 12 and > 2pm''. > > It feels like the only solution is to write EVERY interval implied by > the weekly availability specified, but that seems like it will be a > PITA when the availability is changed -- will I need to rewrite every > date-time I stored, when, say some person X''s availability is changed > from mondays to tuesdays and sundays, etc.? > > Any suggestions on strategies or references to gems for this?You could expand my ''relativity'' gem for that. You would need to: * implement the WeekTime, WeekTimeRange and WeekTimeRangeArray class av_1 = WeekTimeRange.new("Monday 9:00..Monday 17:00") av_2 = WeekTimeRange.new("Tuesday 9:00..Monday 17:00") av_3 = WeekTimeRange.new("Wednesday 9:00..Monday 13:00") available = WeekTimeRangeArray.new(av_1, av_2, av_3, ...) * implement the include? method on it Check if a certain relative or absolute range is fully inside at least one of the WeekTimeRanges inside the WeekTimeRangeArray * and then the available? method for requested_time_range could be something like: requested_time_range.stop.to_date < Date.new(2013,8,31)) && available.include?(requested_time_range) where requested_time_range would be an absolute time range (e.g. "March 26, 2012 between 12 and 2pm" in your example)> > (Below follows a rough modeling.) > > HoursInterval > start (hrs:mins) > stop (hrs:mins) > > WeeklyTime > sunday (has_many HoursIntervals) > monday ... > ... > saturday ...You have a potential problem here ... What if one of the DayTimeRange s (that''s how I call them) spans night_shift = DayTimeRange.new("22:00..06:00") then your simple mapping to 7 week days with a start-stop per day will fail.> Availability > start (date-time) > stop (date-time, can be null) > has_one WeeklyTimeHTH, Peter -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.