Sha256: 4d059ff88d4e369d5dc6a2fcc4d08d4803bd2869895aa392129dbe7431ba8015

Contents?: true

Size: 364 Bytes

Versions: 10

Compression:

Stored size: 364 Bytes

Contents

require 'facets/time/trunc'

class Time

  # Round time at the nearest range (in seconds).
  #
  #   t1 = Time.now
  #   t2 = t1.round_to(60*60)
  #   t2.min #=> 0
  #   t2.sec #=> 0
  #
  # TODO: What about `round(:minute)`?
  #
  # TODO: Fractional seconds should round the usec.
  #
  def round_to(seconds)
    (self + seconds / 2.0).trunc(seconds)
  end

end

Version data entries

10 entries across 9 versions & 2 rubygems

Version Path
facets-glimmer-3.2.0 lib/core/facets/time/round_to.rb
facets-3.1.0 lib/core/facets/time/round_to.rb
facets-3.0.0 lib/core/facets/time/round_to.rb
facets-2.9.3 lib/core/facets/time/round_to.rb
facets-2.9.2 lib/core/facets/time/round_to.rb
facets-2.9.2 src/core/facets/time/round_to.rb
facets-2.9.1 lib/core/facets/time/round_to.rb
facets-2.9.0 lib/core/facets/time/round_to.rb
facets-2.9.0.pre.2 lib/core/facets/time/round_to.rb
facets-2.9.0.pre.1 lib/core/facets/time/round_to.rb