rails support for intricate date-time persistence strategies?

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

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 WeeklyTime

HTH,

Peter