Class: Time
Overview
calendar better.
Class Method Summary collapse
-
.at(arg, ms = nil) ⇒ RubyUnits::Unit, Time
Convert a duration to a Time value by considering the duration to be the number of seconds since the epoch.
- .in(duration) ⇒ RubyUnits::Unit, Time
- .unit_time_at ⇒ Object
Instance Method Summary collapse
- #+(other) ⇒ RubyUnits::Unit, Time
- #-(other) ⇒ RubyUnits::Unit, Time
- #to_unit(other = nil) ⇒ Unit (also: #unit, #u)
- #unit_add ⇒ Object
- #unit_sub ⇒ Object
Class Method Details
.at(arg, ms = nil) ⇒ RubyUnits::Unit, Time
Convert a duration to a Time value by considering the duration to be the number of seconds since the epoch
18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/ruby_units/time.rb', line 18 def self.at(arg, ms=nil) case arg when Time unit_time_at(arg) when RubyUnits::Unit if ms unit_time_at(arg.convert_to("s").scalar, ms) else unit_time_at(arg.convert_to("s").scalar) end else ms.nil? ? unit_time_at(arg) : unit_time_at(arg, ms) end end |
.in(duration) ⇒ RubyUnits::Unit, Time
65 66 67 |
# File 'lib/ruby_units/time.rb', line 65 def self.in(duration) Time.now + duration.to_unit end |
.unit_time_at ⇒ Object
10 |
# File 'lib/ruby_units/time.rb', line 10 alias unit_time_at at |
Instance Method Details
#+(other) ⇒ RubyUnits::Unit, Time
48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/ruby_units/time.rb', line 48 def +(other) case other when RubyUnits::Unit other = other.convert_to('d').round.convert_to('s') if ['y', 'decade', 'century'].include? other.units begin unit_add(other.convert_to('s').scalar) rescue RangeError self.to_datetime + other end else unit_add(other) end end |
#-(other) ⇒ RubyUnits::Unit, Time
72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/ruby_units/time.rb', line 72 def -(other) case other when RubyUnits::Unit other = other.convert_to('d').round.convert_to('s') if ['y', 'decade', 'century'].include? other.units begin unit_sub(other.convert_to('s').scalar) rescue RangeError self.send(:to_datetime) - other end else unit_sub(other) end end |
#to_unit(other = nil) ⇒ Unit Also known as: unit, u
34 35 36 |
# File 'lib/ruby_units/time.rb', line 34 def to_unit(other = nil) other ? RubyUnits::Unit.new(self).convert_to(other) : RubyUnits::Unit.new(self) end |
#unit_add ⇒ Object
46 |
# File 'lib/ruby_units/time.rb', line 46 alias :unit_add :+ |
#unit_sub ⇒ Object
69 |
# File 'lib/ruby_units/time.rb', line 69 alias :unit_sub :- |