Class: Date
Instance Method Summary collapse
- #+(unit) ⇒ Object
- #-(unit) ⇒ Object
- #inspect(raw = false) ⇒ Object
- #to_date ⇒ Object
- #to_time ⇒ Object
- #to_unit(other = nil) ⇒ Object (also: #unit)
- #unit_date_add ⇒ Object
- #unit_date_sub ⇒ Object
- #units_datetime_inspect ⇒ Object
Instance Method Details
#+(unit) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/ruby_units/date.rb', line 8 def +(unit) case unit when Unit unit = unit.to('d').round if ['y', 'decade', 'century'].include? unit.units unit_date_add(unit.to('day').scalar) when Time unit_date_add(unit.to_datetime) else unit_date_add(unit) end end |
#-(unit) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/ruby_units/date.rb', line 22 def -(unit) case unit when Unit unit = unit.to('d').round if ['y', 'decade', 'century'].include? unit.units unit_date_sub(unit.to('day').scalar) when Time unit_date_sub(unit.to_datetime) else unit_date_sub(unit) end end |
#inspect(raw = false) ⇒ Object
46 47 48 49 |
# File 'lib/ruby_units/date.rb', line 46 def inspect(raw = false) return self.units_datetime_inspect if raw self.to_s end |
#to_date ⇒ Object
52 53 54 |
# File 'lib/ruby_units/date.rb', line 52 def to_date Date.civil(self.year, self.month, self.day) end |
#to_time ⇒ Object
40 41 42 |
# File 'lib/ruby_units/date.rb', line 40 def to_time Time.local(*ParseDate.parsedate(self.to_s)) end |
#to_unit(other = nil) ⇒ Object Also known as: unit
34 35 36 |
# File 'lib/ruby_units/date.rb', line 34 def to_unit(other = nil) other ? Unit.new(self).to(other) : Unit.new(self) end |
#unit_date_add ⇒ Object
7 |
# File 'lib/ruby_units/date.rb', line 7 alias :unit_date_add :+ |
#unit_date_sub ⇒ Object
21 |
# File 'lib/ruby_units/date.rb', line 21 alias :unit_date_sub :- |
#units_datetime_inspect ⇒ Object
45 |
# File 'lib/ruby_units/date.rb', line 45 alias :units_datetime_inspect :inspect |