When doing
startTime = DateTime.now
startTime = startTime.change(:min => (startTime.min / 5.to_f).ceil * 5)
our production server occasionally produces the following exception
A ArgumentError occurred in controller#action:
invalid date
/opt/ruby-enterprise-1.8.7-2009.10/lib/ruby/1.8/date.rb:1519:in `civil'
vendor/bundle/ruby/1.8/gems/activesupport-3.0.9/lib/active_support/core_ext/date_time/calculations.rb:37:in `change'
And I just can’t figure out what causes the problem nor reproduce it in my development environment. Am I doing something wrong, or what is happening here? What I want to do is create a DateTime instance which is rounded up to the closest 5 min from now.
If DateTime.now.min > 55, then you are setting the min value to 60.
If you only need the time part:
if you need more than this, I’d suggest using
activesupport. Then you could do