Skip to content

Commit

Permalink
Use round instead of floor to calculate number of days
Browse files Browse the repository at this point in the history
If the time span covered the date when the clocks went forward
then the number of days was off by one.
  • Loading branch information
pixeltrix committed Apr 11, 2016
1 parent 28681e1 commit 4faaba1
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/helpers/date_time_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def waiting_for_in_words(date, now = Time.current)
return unless date.present?

scope = :"petitions.waiting_for_in_words"
days = ((now.end_of_day - date.end_of_day) / 86400.0).floor
days = ((now.end_of_day - date.end_of_day) / 86400.0).round
key = WAITING_FOR_KEYS[days]

t(key, scope: scope, formatted_count: number_with_delimiter(days))
Expand Down
26 changes: 26 additions & 0 deletions spec/helpers/date_time_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,32 @@
end
end

context "when the time span crosses the spring DST boundary" do
let(:now) { Time.utc(2016, 4, 11, 11, 0, 0).in_time_zone }
let(:date) { 30.days.ago(now) }

around do |example|
travel_to(now) { example.run }
end

it "returns 'Waiting for 30 days'" do
expect(helper.waiting_for_in_words(date)).to eq("Waiting for 30 days")
end
end

context "when the time span crosses the autumn DST boundary" do
let(:now) { Time.utc(2016, 11, 11, 12, 0, 0).in_time_zone }
let(:date) { 30.days.ago(now) }

around do |example|
travel_to(now) { example.run }
end

it "returns 'Waiting for 30 days'" do
expect(helper.waiting_for_in_words(date)).to eq("Waiting for 30 days")
end
end

context "when the response threshold was reached 3 years ago" do
let(:date) { 1095.days.ago(now) }

Expand Down

0 comments on commit 4faaba1

Please sign in to comment.