Sha256: 97ac66f34f5ff3adb7041fcdf02139fc6c0044d57bc498129e991f0048a97328
Contents?: true
Size: 1.28 KB
Versions: 2
Compression:
Stored size: 1.28 KB
Contents
class Time # Returns a new Time representing the time # a number of time-units ago. def ago(number, units=:seconds) case units.to_s.downcase.to_sym when :years set(:year=>(year - number)) when :months years = (month - number / 12).to_i set(:year=>(year - years), :month=>(month - number) % 12) when :weeks self - (number * 604800) when :days self - (number * 86400) when :hours self - (number * 3600) when :minutes self - (number * 60) when :seconds, nil self - number else raise ArgumentError, "unrecognized time units -- #{units}" end end # Returns a new Time representing the time # a number of time-units hence. def hence(number, units=:seconds) case units.to_s.downcase.to_sym when :years set(:year=>(year + number)) when :months years = (month + number / 12).to_i set(:year=>(year + years), :month=>(month + number) % 12) when :weeks self + (number * 604800) when :days self + (number * 86400) when :hours self + (number * 3600) when :minutes self + (number * 60) when :seconds self + number else raise ArgumentError, "unrecognized time units -- #{units}" end end alias_method :in, :hence end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
facets-2.4.0 | lib/facets/time/hence.rb |
facets-2.4.1 | lib/facets/time/hence.rb |