Time In English

Plain-English convenience methods for dealing with dates and times.

Methods
Public Instance methods
after(time = ::Time.now)

Calculates time after a given time. Default time is now. Reads best with argument: 10.minutes.after(time)

This method is also aliased as since from_now later
# File lib/facets/more/times.rb, line 94
  def after(time = ::Time.now)
    time + self
  end
ago(time = ::Time.now)

Alias for before

atto()
# File lib/facets/more/multipliers.rb, line 66
  def atto  ; self.to_f / 1000000000000000000 ; end
before(time = ::Time.now)

Calculates time before a given time. Default time is now. Reads best with arguments: 10.days.before( Time.now - 1.day )

This method is also aliased as until ago
# File lib/facets/more/times.rb, line 86
  def before(time = ::Time.now)
    time - self
  end
bit()

Bits and Bytes

# File lib/facets/more/multipliers.rb, line 79
  def bit   ; self ; end
bit()
# File lib/facets/more/bytes.rb, line 62
  def bit   ; self ; end
bits()
# File lib/facets/more/bytes.rb, line 63
  def bits  ; self ; end
bits()
# File lib/facets/more/multipliers.rb, line 80
  def bits  ; self ; end
byte()
# File lib/facets/more/multipliers.rb, line 81
  def byte  ; self * 8 ; end
byte()
# File lib/facets/more/bytes.rb, line 64
  def byte  ; self * 8 ; end
bytes()
# File lib/facets/more/bytes.rb, line 65
  def bytes ; self * 8 ; end
bytes()
# File lib/facets/more/multipliers.rb, line 82
  def bytes ; self * 8 ; end
centi()
# File lib/facets/more/multipliers.rb, line 60
  def centi ; self.to_f / 100 ; end
day()

Alias for days

days()

Converts days into seconds.

This method is also aliased as day
# File lib/facets/more/times.rb, line 58
  def days ; self * 24.hours ; end
deci()

SI Fractional

# File lib/facets/more/multipliers.rb, line 59
  def deci  ; self.to_f / 10 ; end
deka()

SI Multipliers

# File lib/facets/more/multipliers.rb, line 48
  def deka  ; self * 10 ; end
exa()
# File lib/facets/more/multipliers.rb, line 55
  def exa   ; self * 1000000000000000000 ; end
exbi()
# File lib/facets/more/multipliers.rb, line 75
  def exbi ; self * 1024**6 ; end
femto()
# File lib/facets/more/multipliers.rb, line 65
  def femto ; self.to_f / 1000000000000000 ; end
fortnight()

Alias for fortnights

fortnights()

Converts fortnights into seconds. (A fortnight is 2 weeks)

This method is also aliased as fortnight
# File lib/facets/more/times.rb, line 69
  def fortnights ; self * 2.weeks ; end
from_now(time = ::Time.now)

Alias for after

gibi()
# File lib/facets/more/multipliers.rb, line 72
  def gibi ; self * 1024**3 ; end
giga()
# File lib/facets/more/multipliers.rb, line 52
  def giga  ; self * 1000000000 ; end
hecto()
# File lib/facets/more/multipliers.rb, line 49
  def hecto ; self * 100 ; end
hour()

Alias for hours

hours()

Converts hours into seconds.

This method is also aliased as hour
# File lib/facets/more/times.rb, line 53
  def hours ; self * 60.minutes ; end
kibi()

SI Binary

# File lib/facets/more/multipliers.rb, line 70
  def kibi ; self * 1024 ; end
kilo()
# File lib/facets/more/multipliers.rb, line 50
  def kilo  ; self * 1000 ; end
later(time = ::Time.now)

Alias for after

mebi()
# File lib/facets/more/multipliers.rb, line 71
  def mebi ; self * 1024**2 ; end
mega()
# File lib/facets/more/multipliers.rb, line 51
  def mega  ; self * 1000000 ; end
method_missing(m, *args, &blk)
# File lib/facets/more/units.rb, line 820
  def method_missing(m, *args, &blk)
    if args.length == 1
      args[0] = Units::Converter.converter(args[0]) if not args[0].is_a? Units::Converter
      return Value.new(self, Units::Unit.new({m => 1}, args[0])) if args[0].registered?(m)
    elsif Units::Converter.current.registered?(m)
      raise ArgumentError, "Wrong number of arguments" if args.length != 0
      return Units::Value.new(self, Units::Unit.new({m => 1}, Units::Converter.current))
    end
    super
  end
micro()
# File lib/facets/more/multipliers.rb, line 62
  def micro ; self.to_f / 1000000 ; end
milli()
# File lib/facets/more/multipliers.rb, line 61
  def milli ; self.to_f / 1000 ; end
minute()

Alias for minutes

minutes()

Converts minutes into seconds.

This method is also aliased as minute
# File lib/facets/more/times.rb, line 48
  def minutes ; self * 60 ; end
month()

Alias for months

months()

Converts months into seconds. WARNING: This is not exact as it assumes 30 days to a month.

This method is also aliased as month
# File lib/facets/more/times.rb, line 75
  def months ; self * 30.days ; end
nano()
# File lib/facets/more/multipliers.rb, line 63
  def nano  ; self.to_f / 1000000000 ; end
octet_units(fmt='%.2f')

Alias for strfbytes

pebi()
# File lib/facets/more/multipliers.rb, line 74
  def pebi ; self * 1024**5 ; end
peta()
# File lib/facets/more/multipliers.rb, line 54
  def peta  ; self * 1000000000000000 ; end
pico()
# File lib/facets/more/multipliers.rb, line 64
  def pico  ; self.to_f / 1000000000000 ; end
second()

Alias for seconds

seconds()

Enables the use of time calculations and declarations, like 45.minutes + 2.hours + 4.years. The base unit for all of these Numeric time methods is seconds.

This method is also aliased as second
# File lib/facets/more/times.rb, line 43
  def seconds ; self ; end
since(time = ::Time.now)

Alias for after

strfbits(fmt='%.2f')

Formated string of bits proportial to size.

  1024.bits_to_s            #=> "1.00 kb"
  1048576.bits_to_s         #=> "1.00 mb"
  1073741824.bits_to_s      #=> "1.00 gb"
  1099511627776.bits_to_s   #=> "1.00 tb"

Takes a format string to adjust output.

  1024.bits_to_s('%.0f')    #=> "1 kb"
# File lib/facets/more/bytes.rb, line 102
  def strfbits(fmt='%.2f')
    case
    when self < 1024
      "#{self} bits"
    when self < 1024**2
      "#{fmt % (self.to_f / 1024)} kb"
    when self < 1024**3
      "#{fmt % (self.to_f / 1024**2)} mb"
    when self < 1024**4
      "#{fmt % (self.to_f / 1024**3)} gb"
    when self < 1024**5
      "#{fmt % (self.to_f / 1024**4)} tb"
    else
      "#{self} bits"
    end
  end
strfbytes(fmt='%.2f')

Formated string of bytes proportial to size.

  1024.bytes_to_s            #=> "1.00 KB"
  1048576.bytes_to_s         #=> "1.00 MB"
  1073741824.bytes_to_s      #=> "1.00 GB"
  1099511627776.bytes_to_s   #=> "1.00 TB"

Takes a format string to adjust output.

  1024.bytes_to_s('%.0f')    #=> "1 KB"
This method is also aliased as octet_units
# File lib/facets/more/bytes.rb, line 130
  def strfbytes(fmt='%.2f')
    case
    when self < 1024
      "#{self} bytes"
    when self < 1024**2
      "#{fmt % (self.to_f / 1024)} KB"
    when self < 1024**3
      "#{fmt % (self.to_f / 1024**2)} MB"
    when self < 1024**4
      "#{fmt % (self.to_f / 1024**3)} GB"
    when self < 1024**5
      "#{fmt % (self.to_f / 1024**4)} TB"
    else
      "#{self} bytes"
    end
  end
tebi()
# File lib/facets/more/multipliers.rb, line 73
  def tebi ; self * 1024**4 ; end
tera()
# File lib/facets/more/multipliers.rb, line 53
  def tera  ; self * 1000000000000 ; end
until(time = ::Time.now)

Alias for before

week()

Alias for weeks

weeks()

Converts weeks into seconds.

This method is also aliased as week
# File lib/facets/more/times.rb, line 63
  def weeks ; self * 7.days ; end
year()

Alias for years

years()

Converts years into seconds.

This method is also aliased as year
# File lib/facets/more/times.rb, line 80
  def years ; self * 365.days ; end