title: Time Difference of One Item, Two Fields, Grouped by Days - Rails
body: <p><strong>Controller</strong></p>
  <pre><code>@clock_events = ClockEvent.where(user_id: current_user.id)
  
  @clock_event_days = @clock_events.group_by { |t| t.clock_in.beginning_of_day }
  
  @clock_out = ClockEvent.where(user_id: current_user.id, clock_out: nil).last
  </code></pre>
  <p><strong>View</strong></p>
  <pre><code>&lt;% if @clock_events.exists? %&gt;
          &lt;div class=&quot;row&quot;&gt;
            &lt;% @clock_event_days.each do |day, clock_events| %&gt;
              &lt;div class=&quot;col-md-6&quot;&gt;
                &lt;div class=&quot;list-group&quot;&gt;
                  &lt;h4 class=&quot;list-group-item-heading&quot;&gt;&lt;%= day.strftime(&quot;%A, %B #{day.day.ordinalize}&quot;) %&gt;&lt;/h4&gt;
                  &lt;% clock_events.each do |clock_event| %&gt;
                    &lt;p class=&quot;list-group-item-text time-group&quot;&gt;
                      &lt;%= clock_event.clock_in.strftime(&quot;%l:%M%p&quot;) %&gt;
                        &lt;% if clock_event.clock_out.present? %&gt;
                          -
                          &lt;%= clock_event.clock_out.strftime(&quot;%l:%M%p&quot;) %&gt; -
                            &lt;%= sprintf &quot;%.2f&quot;, ((clock_event.clock_out - clock_event.clock_in) / 1.hour) %&gt; hrs
                              &lt;% end %&gt;
                    &lt;/p&gt;
                    &lt;% end %&gt;
                &lt;/div&gt;
                &lt;div class=&quot;daily-total&quot;&gt;
                  &lt;strong&gt;Total: **need total here**&lt;/strong&gt;&lt;br&gt;
                &lt;/div&gt;
              &lt;/div&gt;
              &lt;% end %&gt;
          &lt;/div&gt;
          &lt;% end %&gt;
  </code></pre>
  <p><strong>Result</strong></p>
  <pre><code>Friday, February 17th
  5:15PM - 6:15PM - 1.00 hrs
  5:29PM - 5:41PM - 0.21 hrs
  5:49PM - 6:45PM - 0.94 hrs
  6:49PM - 6:49PM - 0.00 hrs
  6:50PM - 6:57PM - 0.11 hrs
  Total:
  
  Saturday, February 18th
  4:45PM - 4:52PM - 0.11 hrs
  Total:
  </code></pre>
  <p>Can some one help me get the total hours for each day and then for the entire week (Friday-Thursday)?</p>
  <p>I am guessing I should be using the model for getting the time difference instead of using the view...but I can't seem to figure it out.</p>