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