Commit 7f19dfe82f9ec7ce00daa20fc2c728a351f8c629
1 parent
0bd3c635
Exists in
master
and in
20 other branches
Fix how the duration of events are calculated
Showing
2 changed files
with
11 additions
and
1 deletions
Show diff stats
app/models/event.rb
| ... | ... | @@ -110,7 +110,7 @@ class Event < Article |
| 110 | 110 | end |
| 111 | 111 | |
| 112 | 112 | def duration |
| 113 | - (((self.end_date || self.start_date) - self.start_date).to_i/60/60/24) | |
| 113 | + (((self.end_date || self.start_date) - self.start_date).to_i/60/60/24) + 1 | |
| 114 | 114 | end |
| 115 | 115 | |
| 116 | 116 | alias_method :article_lead, :lead | ... | ... |
test/unit/event_test.rb
| ... | ... | @@ -323,4 +323,14 @@ class EventTest < ActiveSupport::TestCase |
| 323 | 323 | assert a.can_display_media_panel? |
| 324 | 324 | end |
| 325 | 325 | |
| 326 | + should 'calculate duration of events with start and end date' do | |
| 327 | + e = build(Event, :start_date => DateTime.new(2015, 1, 1), :end_date => DateTime.new(2015, 1, 5)) | |
| 328 | + assert_equal 5, e.duration | |
| 329 | + end | |
| 330 | + | |
| 331 | + should 'calculate duration of event with only start_date' do | |
| 332 | + e = build(Event, :start_date => DateTime.new(2015, 1, 1)) | |
| 333 | + assert_equal 1, e.duration | |
| 334 | + end | |
| 335 | + | |
| 326 | 336 | end | ... | ... |
-
mentioned in commit 9c951c50f1ecea130a344c96fe52383b6579dcf5