Time In English
Plain-English convenience methods for dealing with dates and times.
- after
- ago
- atto
- before
- bit
- bit
- bits
- bits
- byte
- byte
- bytes
- bytes
- centi
- day
- days
- deci
- deka
- exa
- exbi
- femto
- fortnight
- fortnights
- from_now
- gibi
- giga
- hecto
- hour
- hours
- kibi
- kilo
- later
- mebi
- mega
- method_missing
- micro
- milli
- minute
- minutes
- month
- months
- nano
- octet_units
- pebi
- peta
- pico
- second
- seconds
- since
- strfbits
- strfbytes
- tebi
- tera
- until
- week
- weeks
- year
- years
Calculates time after a given time. Default time is now. Reads best with argument: 10.minutes.after(time)
[ show source ]
# File lib/facets/more/times.rb, line 94 def after(time = ::Time.now) time + self end
Alias for before
[ show source ]
# File lib/facets/more/multipliers.rb, line 66 def atto ; self.to_f / 1000000000000000000 ; end
Calculates time before a given time. Default time is now. Reads best with arguments: 10.days.before( Time.now - 1.day )
[ show source ]
# File lib/facets/more/times.rb, line 86 def before(time = ::Time.now) time - self end
Bits and Bytes
[ show source ]
# File lib/facets/more/multipliers.rb, line 79 def bit ; self ; end
[ show source ]
# File lib/facets/more/bytes.rb, line 62 def bit ; self ; end
[ show source ]
# File lib/facets/more/bytes.rb, line 63 def bits ; self ; end
[ show source ]
# File lib/facets/more/multipliers.rb, line 80 def bits ; self ; end
[ show source ]
# File lib/facets/more/multipliers.rb, line 81 def byte ; self * 8 ; end
[ show source ]
# File lib/facets/more/bytes.rb, line 64 def byte ; self * 8 ; end
[ show source ]
# File lib/facets/more/bytes.rb, line 65 def bytes ; self * 8 ; end
[ show source ]
# File lib/facets/more/multipliers.rb, line 82 def bytes ; self * 8 ; end
[ show source ]
# File lib/facets/more/multipliers.rb, line 60 def centi ; self.to_f / 100 ; end
Alias for days
Converts days into seconds.
[ show source ]
# File lib/facets/more/times.rb, line 58 def days ; self * 24.hours ; end
SI Fractional
[ show source ]
# File lib/facets/more/multipliers.rb, line 59 def deci ; self.to_f / 10 ; end
SI Multipliers
[ show source ]
# File lib/facets/more/multipliers.rb, line 48 def deka ; self * 10 ; end
[ show source ]
# File lib/facets/more/multipliers.rb, line 55 def exa ; self * 1000000000000000000 ; end
[ show source ]
# File lib/facets/more/multipliers.rb, line 75 def exbi ; self * 1024**6 ; end
[ show source ]
# File lib/facets/more/multipliers.rb, line 65 def femto ; self.to_f / 1000000000000000 ; end
Alias for fortnights
Converts fortnights into seconds. (A fortnight is 2 weeks)
[ show source ]
# File lib/facets/more/times.rb, line 69 def fortnights ; self * 2.weeks ; end
Alias for after
[ show source ]
# File lib/facets/more/multipliers.rb, line 72 def gibi ; self * 1024**3 ; end
[ show source ]
# File lib/facets/more/multipliers.rb, line 52 def giga ; self * 1000000000 ; end
[ show source ]
# File lib/facets/more/multipliers.rb, line 49 def hecto ; self * 100 ; end
Alias for hours
Converts hours into seconds.
[ show source ]
# File lib/facets/more/times.rb, line 53 def hours ; self * 60.minutes ; end
SI Binary
[ show source ]
# File lib/facets/more/multipliers.rb, line 70 def kibi ; self * 1024 ; end
[ show source ]
# File lib/facets/more/multipliers.rb, line 50 def kilo ; self * 1000 ; end
Alias for after
[ show source ]
# File lib/facets/more/multipliers.rb, line 71 def mebi ; self * 1024**2 ; end
[ show source ]
# File lib/facets/more/multipliers.rb, line 51 def mega ; self * 1000000 ; end
[ show source ]
# 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
[ show source ]
# File lib/facets/more/multipliers.rb, line 62 def micro ; self.to_f / 1000000 ; end
[ show source ]
# File lib/facets/more/multipliers.rb, line 61 def milli ; self.to_f / 1000 ; end
Alias for minutes
Converts minutes into seconds.
[ show source ]
# File lib/facets/more/times.rb, line 48 def minutes ; self * 60 ; end
Alias for months
Converts months into seconds. WARNING: This is not exact as it assumes 30 days to a month.
[ show source ]
# File lib/facets/more/times.rb, line 75 def months ; self * 30.days ; end
[ show source ]
# File lib/facets/more/multipliers.rb, line 63 def nano ; self.to_f / 1000000000 ; end
Alias for strfbytes
[ show source ]
# File lib/facets/more/multipliers.rb, line 74 def pebi ; self * 1024**5 ; end
[ show source ]
# File lib/facets/more/multipliers.rb, line 54 def peta ; self * 1000000000000000 ; end
[ show source ]
# File lib/facets/more/multipliers.rb, line 64 def pico ; self.to_f / 1000000000000 ; end
Alias for 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.
[ show source ]
# File lib/facets/more/times.rb, line 43 def seconds ; self ; end
Alias for after
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"
[ show source ]
# 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
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"
[ show source ]
# 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
[ show source ]
# File lib/facets/more/multipliers.rb, line 73 def tebi ; self * 1024**4 ; end
[ show source ]
# File lib/facets/more/multipliers.rb, line 53 def tera ; self * 1000000000000 ; end
Alias for before
Alias for weeks
Converts weeks into seconds.
[ show source ]
# File lib/facets/more/times.rb, line 63 def weeks ; self * 7.days ; end
Alias for years
Converts years into seconds.
[ show source ]
# File lib/facets/more/times.rb, line 80 def years ; self * 365.days ; end