title: Rails Active Record Query Total leaves on a weekday
body: <p>The scenario is that there is hotel and it has so many employees. now employees can apply for the leaves.</p>
  
  <p>Leaves table have the start and end date column suppose a employee takes leave from 5, December to 15 December than start date will be 5 December and end date will be 15 December.</p>
  
  <p>How can I get the total leaves in 2017 on particular weekday like on Monday?</p>
  
  <p>Found the solution:</p>
  
  <pre><code>def calculate_weekdays
  count_weekday = {}
  (0..6).to_a.select{|t| count_weekday[t]=0 }
  Event.all.each do |event|
    start_date, end_date = event.start_time, event.end_time
    result = ( start_date.to_date..end_date.to_date ).to_a.select { |k| count_weekday[k.wday]=count_weekday[k.wday]+1}
  end
  return count_weekday
  end
  </code></pre>