Class: Date
- Inherits:
-
Object
- Object
- Date
- Defined in:
- lib/ruby_units/date.rb
Overview
Allow date objects to do offsets by a time unit Date.today + Unit.new(“1 week”) => gives today+1 week
Instance Method Summary collapse
- #+(other) ⇒ Unit
- #-(other) ⇒ Unit
- #inspect(dump = false) ⇒ Object deprecated Deprecated.
-
#to_date ⇒ Date
:nocov_19:.
- #to_time ⇒ Time
-
#to_unit(other = nil) ⇒ Unit
Construct a unit from a Date.
- #unit_date_add ⇒ Object
- #unit_date_sub ⇒ Object
-
#units_datetime_inspect ⇒ Object
:nocov_19:.
Instance Method Details
#+(other) ⇒ Unit
9 10 11 12 13 14 15 16 17 |
# File 'lib/ruby_units/date.rb', line 9 def +(other) case other when RubyUnits::Unit other = other.convert_to('d').round if %w[y decade century].include? other.units unit_date_add(other.convert_to('day').scalar) else unit_date_add(other) end end |
#-(other) ⇒ Unit
22 23 24 25 26 27 28 29 30 |
# File 'lib/ruby_units/date.rb', line 22 def -(other) case other when RubyUnits::Unit other = other.convert_to('d').round if %w[y decade century].include? other.units unit_date_sub(other.convert_to('day').scalar) else unit_date_sub(other) end end |
#inspect(dump = false) ⇒ Object
Deprecated.
51 52 53 54 |
# File 'lib/ruby_units/date.rb', line 51 def inspect(dump = false) return units_datetime_inspect if dump to_s end |
#to_date ⇒ Date
:nocov_19:
59 60 61 |
# File 'lib/ruby_units/date.rb', line 59 def to_date Date.civil(year, month, day) end |
#to_time ⇒ Time
43 44 45 |
# File 'lib/ruby_units/date.rb', line 43 def to_time Time.local(*ParseDate.parsedate(to_s)) end |
#to_unit(other = nil) ⇒ Unit
Construct a unit from a Date
36 37 38 |
# File 'lib/ruby_units/date.rb', line 36 def to_unit(other = nil) other ? RubyUnits::Unit.new(self).convert_to(other) : RubyUnits::Unit.new(self) end |
#unit_date_add ⇒ Object
6 |
# File 'lib/ruby_units/date.rb', line 6 alias unit_date_add + |
#unit_date_sub ⇒ Object
19 |
# File 'lib/ruby_units/date.rb', line 19 alias unit_date_sub - |
#units_datetime_inspect ⇒ Object
:nocov_19:
49 |
# File 'lib/ruby_units/date.rb', line 49 alias units_datetime_inspect inspect |