Rounding Time in Increments
I Recently needed to round down a time in certain increments. This is not something I've ever been asked to do previously so it was an interesting problem to figure out. The resulting formula is simple:
```
TIME_MIN - (TIME_MIN % INCREMENT)
```
This will give you the previous incremental minute. ex: Given a 5 minute increment @ 3:12, the result would be 10.
```ruby
time = Time.now
new_min = time.min - (time.min % 5)
```
I happen to be solving this in a project with `ActiveSupport` so there was access to [`Time#change`](https://api.rubyonrails.org/classes/Time.html#method-i-change) so I finished this up with:
```ruby
time.change(min: new_min)
```
mattpolito
April 1, 2020