Class: Date

Inherits:
Object show all
Defined in:
lib/rails_units/date.rb

Instance Method Summary collapse

Instance Method Details

#+(unit) ⇒ Object



8
9
10
11
12
13
14
15
16
# File 'lib/rails_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)
  else
    unit_date_add(unit)
  end
end

#-(unit) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'lib/rails_units/date.rb', line 20

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)
  else
    unit_date_sub(unit)
  end
end

#inspect(raw = false) ⇒ Object



42
43
44
45
# File 'lib/rails_units/date.rb', line 42

def inspect(raw = false)
  return self.units_datetime_inspect if raw
  self.to_s
end

#to_dateObject



48
49
50
# File 'lib/rails_units/date.rb', line 48

def to_date
  Date.civil(self.year, self.month, self.day)
end

#to_timeObject



36
37
38
# File 'lib/rails_units/date.rb', line 36

def to_time
  Time.local(*ParseDate.parsedate(self.to_s))
end

#to_unit(other = nil) ⇒ Object Also known as: unit



30
31
32
# File 'lib/rails_units/date.rb', line 30

def to_unit(other = nil)
  other ? Unit.new(self).to(other) : Unit.new(self)
end

#unit_date_addObject



7
# File 'lib/rails_units/date.rb', line 7

alias :unit_date_add :+

#unit_date_subObject



19
# File 'lib/rails_units/date.rb', line 19

alias :unit_date_sub :-

#units_datetime_inspectObject



41
# File 'lib/rails_units/date.rb', line 41

alias :units_datetime_inspect :inspect