Class: Time
- Inherits:
-
Object
- Object
- Time
- Defined in:
- lib/nearest.rb
Instance Method Summary collapse
Instance Method Details
#nearest(seconds, opts = {}) ⇒ Object
2 3 4 5 6 7 |
# File 'lib/nearest.rb', line 2 def nearest(seconds, opts={}) method = opts[:force] ? (opts[:force] == :future ? 'ceil' : 'floor') : 'round' new_time = Time.at((self.to_f / seconds).send(method) * seconds) utc? ? new_time.utc : new_time end |