Sha256: 4be8db67022f71fd117a147cf7fc764b59b059daa87e7701be484767b0e8caa3

Contents?: true

Size: 1.12 KB

Versions: 44

Compression:

Stored size: 1.12 KB

Contents

# Provides a a simple way of calling time units and to see the elapsed time between 2 moments
# ==== Examples
#   142.minutes => returns a value in seconds
#   7.days => returns a value in seconds
#   1.week => returns a value in seconds
#   2.weeks.ago => returns a date
#   1.year.since(time) => returns a date
#   5.months.since(2.weeks.from_now) => returns a date
module TimeDSL
  
  def second
    self * 1
  end
  alias_method :seconds, :second
  
  def minute
    self * 60
  end
  alias_method :minutes, :minute
  
  def hour
    self * 3600
  end
  alias_method :hours, :hour
  
  def day
    self * 86400
  end
  alias_method :days, :day
  
  def week
    self * 604800
  end
  alias_method :weeks, :week
  
  def month
    self * 2592000
  end
  alias_method :months, :month
  
  def year
    self * 31471200
  end
  alias_method :years, :year
  
  # Reads best without arguments:  10.minutes.ago
  def ago(time = ::Time.now)
    time - self
  end
  alias :until :ago
  
  # Reads best with argument:  10.minutes.since(time)
  def since(time = ::Time.now)
    time + self
  end
  alias :from_now :since
end

Numeric.send :include, TimeDSL

Version data entries

44 entries across 44 versions & 6 rubygems

Version Path
BrianTheCoder-ratpack-0.3.1 lib/ratpack/time_dsl.rb
merb-core-1.1.3 spec10/public/webrat/test_app/gems/gems/merb-helpers-0.9.14/lib/merb-helpers/time_dsl.rb
merb-helpers-1.1.3 lib/merb-helpers/time_dsl.rb
merb-helpers-1.1.2 lib/merb-helpers/time_dsl.rb
merb-core-1.1.2 spec10/public/webrat/test_app/gems/gems/merb-helpers-0.9.14/lib/merb-helpers/time_dsl.rb
merb-helpers-1.1.1 lib/merb-helpers/time_dsl.rb
merb-core-1.1.1 spec10/public/webrat/test_app/gems/gems/merb-helpers-0.9.14/lib/merb-helpers/time_dsl.rb
merb-helpers-1.1.0 lib/merb-helpers/time_dsl.rb
merb-core-1.1.0 spec10/public/webrat/test_app/gems/gems/merb-helpers-0.9.14/lib/merb-helpers/time_dsl.rb
merb-helpers-1.1.0.rc1 lib/merb-helpers/time_dsl.rb
merb-core-1.1.0.rc1 spec10/public/webrat/test_app/gems/gems/merb-helpers-0.9.14/lib/merb-helpers/time_dsl.rb
merb-helpers-1.1.0.pre lib/merb-helpers/time_dsl.rb
merb-core-1.1.0.pre spec10/public/webrat/test_app/gems/gems/merb-helpers-0.9.14/lib/merb-helpers/time_dsl.rb
merb-helpers-1.0.15 lib/merb-helpers/time_dsl.rb
merb-helpers-1.0.14 lib/merb-helpers/time_dsl.rb
merb-helpers-1.0.13 lib/merb-helpers/time_dsl.rb
merb-helpers-1.0.12 lib/merb-helpers/time_dsl.rb
merb-helpers-0.9.10 lib/merb-helpers/time_dsl.rb
merb-helpers-0.9.8 lib/merb-helpers/time_dsl.rb
merb-helpers-1.0.11 lib/merb-helpers/time_dsl.rb