rounding という gem を使えば楽。
# gem install rounding
require 'rounding'
Time.parse('2018/08/18 0:49 +09:00')
# => 2018-08-18 00:49:00 +0900
# 15分刻みで切り上げ
Time.parse('2018/08/18 0:49 +09:00').ceil_to(15.minutes)
# => 2018-08-18 01:00:00 +0900
# 15分刻みで切り捨て
Time.parse('2018/08/18 0:49 +09:00').round_to(15.minutes)
# => 2018-08-18 00:45:00 +0900
Rounding is compatible with ActiveSupport's Time extensions, but also works fine without ActiveSupport.
ActiveSupport
の Time
とも互換性があるとのこと。
rounding は時間だけでなく、数値全般を扱える強力な gem
なのでとても便利そう。
参考
brianhempel/rounding: Round by any arbitrary step in Ruby.
https://github.com/brianhempel/rounding