Module: TimeCrisis::Support::Change::Date

Defined in:
lib/time_crisis/support/change.rb

Instance Method Summary collapse

Instance Method Details

#beginning_of_dayObject



28
29
30
# File 'lib/time_crisis/support/change.rb', line 28

def beginning_of_day
  to_time
end

#beginning_of_monthObject



19
20
21
# File 'lib/time_crisis/support/change.rb', line 19

def beginning_of_month
  change(:day => 1)
end

#beginning_of_yearObject



11
12
13
# File 'lib/time_crisis/support/change.rb', line 11

def beginning_of_year
  change(:month => 1, :day => 1)
end

#change(options = {}) ⇒ Object



3
4
5
6
7
8
9
# File 'lib/time_crisis/support/change.rb', line 3

def change(options={})
  ::Date.civil(
    options[:year]  || self.year,
    options[:month] || self.month,
    options[:day]   || self.day
  )
end

#end_of_dayObject



32
33
34
# File 'lib/time_crisis/support/change.rb', line 32

def end_of_day
  to_time.end_of_day
end

#end_of_monthObject



23
24
25
26
# File 'lib/time_crisis/support/change.rb', line 23

def end_of_month
  last_day = self.class.days_in_month(self.month, self.year)
  change(:day => last_day)
end

#end_of_yearObject



15
16
17
# File 'lib/time_crisis/support/change.rb', line 15

def end_of_year
  change(:month => 12, :day => 31)
end