Sha256: de7074b343f4301650e1779bfdaa021a97f7e0aeaba31d22b9f80651d1f115ab

Contents?: true

Size: 1.63 KB

Versions: 225

Compression:

Stored size: 1.63 KB

Contents

# frozen_string_literal: true

require "active_support/duration"
require "active_support/core_ext/time/calculations"
require "active_support/core_ext/time/acts_like"
require "active_support/core_ext/date/calculations"
require "active_support/core_ext/date/acts_like"

class Numeric
  # Returns a Duration instance matching the number of seconds provided.
  #
  #   2.seconds # => 2 seconds
  def seconds
    ActiveSupport::Duration.seconds(self)
  end
  alias :second :seconds

  # Returns a Duration instance matching the number of minutes provided.
  #
  #   2.minutes # => 2 minutes
  def minutes
    ActiveSupport::Duration.minutes(self)
  end
  alias :minute :minutes

  # Returns a Duration instance matching the number of hours provided.
  #
  #   2.hours # => 2 hours
  def hours
    ActiveSupport::Duration.hours(self)
  end
  alias :hour :hours

  # Returns a Duration instance matching the number of days provided.
  #
  #   2.days # => 2 days
  def days
    ActiveSupport::Duration.days(self)
  end
  alias :day :days

  # Returns a Duration instance matching the number of weeks provided.
  #
  #   2.weeks # => 2 weeks
  def weeks
    ActiveSupport::Duration.weeks(self)
  end
  alias :week :weeks

  # Returns a Duration instance matching the number of fortnights provided.
  #
  #   2.fortnights # => 4 weeks
  def fortnights
    ActiveSupport::Duration.weeks(self * 2)
  end
  alias :fortnight :fortnights

  # Returns the number of milliseconds equivalent to the seconds provided.
  # Used with the standard time durations.
  #
  #   2.in_milliseconds # => 2000
  #   1.hour.in_milliseconds # => 3600000
  def in_milliseconds
    self * 1000
  end
end

Version data entries

225 entries across 210 versions & 25 rubygems

Version Path
activesupport-8.0.0 lib/active_support/core_ext/numeric/time.rb
activesupport-7.2.2 lib/active_support/core_ext/numeric/time.rb
activesupport-7.1.5 lib/active_support/core_ext/numeric/time.rb
activesupport-8.0.0.rc2 lib/active_support/core_ext/numeric/time.rb
activesupport-7.2.1.2 lib/active_support/core_ext/numeric/time.rb
activesupport-7.1.4.2 lib/active_support/core_ext/numeric/time.rb
activesupport-7.0.8.6 lib/active_support/core_ext/numeric/time.rb
activesupport-6.1.7.10 lib/active_support/core_ext/numeric/time.rb
activesupport-8.0.0.rc1 lib/active_support/core_ext/numeric/time.rb
activesupport-6.1.7.9 lib/active_support/core_ext/numeric/time.rb
activesupport-7.2.1.1 lib/active_support/core_ext/numeric/time.rb
activesupport-7.1.4.1 lib/active_support/core_ext/numeric/time.rb
activesupport-7.0.8.5 lib/active_support/core_ext/numeric/time.rb
activesupport-8.0.0.beta1 lib/active_support/core_ext/numeric/time.rb
omg-activesupport-8.0.0.alpha9 lib/active_support/core_ext/numeric/time.rb
omg-activesupport-8.0.0.alpha8 lib/active_support/core_ext/numeric/time.rb
omg-activesupport-8.0.0.alpha7 lib/active_support/core_ext/numeric/time.rb
omg-activesupport-8.0.0.alpha4 lib/active_support/core_ext/numeric/time.rb
omg-activesupport-8.0.0.alpha3 lib/active_support/core_ext/numeric/time.rb
omg-activesupport-8.0.0.alpha2 lib/active_support/core_ext/numeric/time.rb