Class: Time
- Inherits:
-
Object
- Object
- Time
- Defined in:
- lib/ruby_units/time.rb
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
- #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
17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/ruby_units/time.rb', line 17 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
62 63 64 |
# File 'lib/ruby_units/time.rb', line 62 def self.in(duration) Time.now + duration.to_unit end |
.unit_time_at ⇒ Object
9 |
# File 'lib/ruby_units/time.rb', line 9 alias unit_time_at at |
Instance Method Details
#+(other) ⇒ RubyUnits::Unit, Time
45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/ruby_units/time.rb', line 45 def +(other) case other when RubyUnits::Unit other = other.convert_to('d').round.convert_to('s') if %w[y decade century].include? other.units begin unit_add(other.convert_to('s').scalar) rescue RangeError to_datetime + other end else unit_add(other) end end |
#-(other) ⇒ RubyUnits::Unit, Time
69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/ruby_units/time.rb', line 69 def -(other) case other when RubyUnits::Unit other = other.convert_to('d').round.convert_to('s') if %w[y decade century].include? other.units begin unit_sub(other.convert_to('s').scalar) rescue RangeError send(:to_datetime) - other end else unit_sub(other) end end |
#to_unit(other = nil) ⇒ Unit
33 34 35 |
# File 'lib/ruby_units/time.rb', line 33 def to_unit(other = nil) other ? RubyUnits::Unit.new(self).convert_to(other) : RubyUnits::Unit.new(self) end |
#unit_add ⇒ Object
43 |
# File 'lib/ruby_units/time.rb', line 43 alias unit_add + |
#unit_sub ⇒ Object
66 |
# File 'lib/ruby_units/time.rb', line 66 alias unit_sub - |