Sha256: ebc1ac03fc7cf5037b7766f8aec627f52cd50643315d984ee4fbcb28be3f7dc7

Contents?: true

Size: 1.02 KB

Versions: 3

Compression:

Stored size: 1.02 KB

Contents

class Time 
	# Return a float of time since linux epoch
	#
  # @example
  #
	#   Time.time     -> 1295953427.0005338
	#
	# @return [Float] 
	def self.time 
    now.to_f 
  end
end

class Numeric
  # Reports the approximate distance in time between two Time, Date or DateTime objects or integers as seconds.
  #
  # @example
  #
  #   1.time_humanize(true)    -> 1 seconds
  #   36561906.time_humanize   -> 1 years 2 months 3 days 4 hours 5 minutes
  #
  def time_humanize(include_seconds=false)
    deta = self
    deta, seconds = deta.divmod(60)
    deta, minutes = deta.divmod(60)
    deta, hours = deta.divmod(24)
    deta, days = deta.divmod(30)
    years, months = deta.divmod(12)

    ret = ""
    ret << "#{years} years " unless years == 0
    ret << "#{months} months " unless months == 0
    ret << "#{days} days " unless days == 0
    ret << "#{hours} hours " unless hours == 0
    ret << "#{minutes} minutes " unless minutes == 0
    ret << "#{seconds} seconds" if include_seconds

    ret.rstrip
  end
end

require "active_support/time"

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
tagen-2.0.2 lib/tagen/core/time.rb
tagen-2.0.1 lib/tagen/core/time.rb
tagen-2.0.0 lib/tagen/core/time.rb