app/controllers/schedules_controller.rb
# time range given in :db format
time range given in :db format
time range given in : db format
def date_span(now, span = MONTH)
    date_pair = 
      case span
        when MONTH
          [now.beginning_of_month.since(-86400*now.beginning_of_month.wday).beginning_of_day, now.end_of_month.since(86400*(6-now.end_of_month.wday)).end_of_day]
        when WEEK
          [now.since(-86400*now.wday).beginning_of_day, now.since(86400*(6 - now.wday)).end_of_day]
        when DAY
          [now.beginning_of_day, now.end_of_day]
        when MONTH2
          [now.since(-86400*now.wday).beginning_of_day, now.since(86400*4*7).since(86400*(6-now.since(86400*4*7).wday)).end_of_day]
      end 
    result = date_pair.map do |d| d.to_date.to_s(:db) end
    result.first..result.last
  end
def date_span ( now , span = MONTH ) date_pair = case span when MONTH [ now . beginning_of_month . since ( - 86400 * now . beginning_of_month . wday ) . beginning_of_day , now . end_of_month . since ( 86400 * ( 6 - now . end_of_month . wday ) ) . end_of_day ] when WEEK [ now . since ( - 86400 * now . wday ) . beginning_of_day , now . since ( 86400 * ( 6 - now . wday ) ) . end_of_day ] when DAY [ now . beginning_of_day , now . end_of_day ] when MONTH2 [ now . since ( - 86400 * now . wday ) . beginning_of_day , now . since ( 86400 * 4 * 7 ) . since ( 86400 * ( 6 - now . since ( 86400 * 4 * 7 ) . wday ) ) . end_of_day ] end result = date_pair . map do | d | d . to_date . to_s ( :db ) end result . first .. result . last end
time range given in :db format
time range given in : db format
now
<not_specific>
span
<not_specific>