class Numeric
def ago(time = ::Time.current)
def ago(time = ::Time.current) time - self end
def as_json(options = nil) self end #:nodoc:
def as_json(options = nil) self end #:nodoc:
def blank?
0.blank? # => false
1.blank? # => false
No number is blank:
:nodoc:
def blank? false end
def bytes
def bytes self end
def days
def days ActiveSupport::Duration.new(self * 24.hours, [[:days, self]]) end
def duplicable?
3.dup # => TypeError: can't dup Fixnum
3.duplicable? # => false
Numbers are not duplicable:
def duplicable? false end
def encode_json(encoder) to_s end #:nodoc:
:nodoc:
def encode_json(encoder) to_s end #:nodoc:
def exabytes
def exabytes self * EXABYTE end
def fortnights
def fortnights ActiveSupport::Duration.new(self * 2.weeks, [[:days, self * 14]]) end
def gigabytes
def gigabytes self * GIGABYTE end
def hours
def hours ActiveSupport::Duration.new(self * 3600, [[:seconds, self * 3600]]) end
def html_safe?
def html_safe? true end
def kilobytes
def kilobytes self * KILOBYTE end
def megabytes
def megabytes self * MEGABYTE end
def minutes
def minutes ActiveSupport::Duration.new(self * 60, [[:seconds, self * 60]]) end
def petabytes
def petabytes self * PETABYTE end
def seconds
Time[http://stdlib.rubyonrails.org/libdoc/time/rdoc/index.html] should be used for precision
Date[http://stdlib.rubyonrails.org/libdoc/date/rdoc/index.html] and
In such cases, Ruby's core
1.year.to_f.from_now
# equivalent to 365.25.days.to_f.from_now
1.month.to_i.from_now
# equivalent to 30.days.to_i.from_now
converted before use:
should be taken to note that this is not true if the result of `months', `years', etc is
While these methods provide precise calculation when used as in the examples above, care
(4.months + 5.years).from_now
# equivalent to Time.now.advance(:months => 4, :years => 5)
2.years.from_now
# equivalent to Time.now.advance(:years => 2)
1.month.from_now
# equivalent to Time.now.advance(:months => 1)
as well as adding or subtracting their results from a Time object. For example:
These methods use Time#advance for precise date calculations when using from_now, ago, etc.
Enables the use of time calculations and declarations, like 45.minutes + 2.hours + 4.years.
def seconds ActiveSupport::Duration.new(self, [[:seconds, self]]) end
def since(time = ::Time.current)
def since(time = ::Time.current) time + self end
def terabytes
def terabytes self * TERABYTE end
def weeks
def weeks ActiveSupport::Duration.new(self * 7.days, [[:days, self * 7]]) end