Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #8848: docs_numeric_time.diff

File docs_numeric_time.diff, 3.2 kB (added by dlehman, 1 year ago)
  • activesupport/lib/active_support/core_ext/numeric/time.rb

    old new  
    22  module CoreExtensions #:nodoc: 
    33    module Numeric #:nodoc: 
    44      # Enables the use of time calculations and declarations, like 45.minutes + 2.hours + 4.years. 
    5       # 
     5      #  
    66      # These methods use Time#advance for precise date calculations when using from_now, ago, etc.  
    77      # as well as adding or subtracting their results from a Time object. For example: 
    88      # 
     
    3535        end 
    3636        alias :second :seconds 
    3737 
     38        # Returns the number of seconds for the specified number of minutes 
     39        # 
     40        # 30.minutes 
     41        # # => 1800 seconds 
    3842        def minutes 
    3943          ActiveSupport::Duration.new(self * 60, [[:seconds, self * 60]]) 
    4044        end 
    4145        alias :minute :minutes   
    4246         
     47        # Returns the number of seconds for the specified number of hours 
     48        # 
     49        # 2.hours 
     50        # # => 7200 seconds 
    4351        def hours 
    4452          ActiveSupport::Duration.new(self * 3600, [[:seconds, self * 3600]]) 
    4553        end 
    4654        alias :hour :hours 
    4755         
     56        # Returns the number of days for the specified number of days 
     57        # 
     58        # 2.days 
     59        # # => 2 days 
    4860        def days 
    4961          ActiveSupport::Duration.new(self * 24.hours, [[:days, self]]) 
    5062        end 
    5163        alias :day :days 
    5264 
     65        # Returns the number of days for the specified number of weeks 
     66        # 
     67        # 3.weeks 
     68        # # => 21 days 
    5369        def weeks 
    5470          ActiveSupport::Duration.new(self * 7.days, [[:days, self * 7]]) 
    5571        end 
    5672        alias :week :weeks 
    5773         
     74        # Returns the number of days for the specified number of fortnights 
     75        # 
     76        # 2.fortnights 
     77        # # => 28 days 
    5878        def fortnights 
    5979          ActiveSupport::Duration.new(self * 2.weeks, [[:days, self * 14]]) 
    6080        end 
    6181        alias :fortnight :fortnights 
    6282         
     83        # Returns the number of months for the specified number of months 
     84        # 
     85        # 2.months 
     86        # # => 2 months 
    6387        def months 
    6488          ActiveSupport::Duration.new(self * 30.days, [[:months, self]]) 
    6589        end 
     
    7094        end 
    7195        alias :year :years 
    7296 
    73         # Reads best without arguments:  10.minutes.ago 
     97        # Returns Time object of the current time adjusted backward by the specified amount 
     98        # 
     99        # DateTime.now 
     100        # # => Sun, 01 Jul 2007 02:00:00 -0500 
     101        # 1.hour.ago 
     102        # # => Sun, 01 Jul 2007 01:00:00 -0500 
    74103        def ago(time = ::Time.now) 
    75104          time - self 
    76105        end 
     
    83112          time + self 
    84113        end 
    85114 
    86         # Reads best without arguments:  10.minutes.from_now 
     115        # Returns Time object of the current time adjusted forwards by the specified amount 
     116        # 
     117        # DateTime.now 
     118        # # => Sun, 01 Jul 2007 02:00:00 -0500 
     119        # 1.hour.from_now 
     120        # # => Sun, 01 Jul 2007 03:00:00 -0500 
    87121        alias :from_now :since 
    88122      end 
    89123    end