The output from ActiveSupport::Duration is wildly unhelpful in those cases
Fixes #3210
end
def block_duration_in_words(duration)
+ # Ensure the requested duration isn't negative, even by a millisecond
+ duration = 0 if duration.negative?
parts = ActiveSupport::Duration.build(duration).parts
if duration < 1.day
t("user_blocks.helper.block_duration.hours", :count => parts.fetch(:hours, 0))
words = block_duration_in_words(0)
assert_equal "0 hours", words
+
+ # Ensure that (slightly) negative durations don't mess everything up
+ # This can happen on zero hour blocks when ends_at is a millisecond before created_at
+ words = block_duration_in_words(-0.001)
+ assert_equal "0 hours", words
end
end