Module: TimeCrisis::Support::Change::Time

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

Instance Method Summary collapse

Instance Method Details

#beginning_of_dayObject



68
69
70
# File 'lib/time_crisis/support/change.rb', line 68

def beginning_of_day
  change(:hour => 0, :min => 0, :sec => 0, :usec => 0)
end

#beginning_of_monthObject



59
60
61
# File 'lib/time_crisis/support/change.rb', line 59

def beginning_of_month
  change(:day => 1,:hour => 0, :min => 0, :sec => 0, :usec => 0)
end

#beginning_of_yearObject



51
52
53
# File 'lib/time_crisis/support/change.rb', line 51

def beginning_of_year
  change(:month => 1, :day => 1, :hour => 0, :min => 0, :sec => 0)
end

#change(options = {}) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/time_crisis/support/change.rb', line 38

def change(options={})
  ::Time.send(
    utc? ? :utc_time : :local,
    options[:year]  || year,
    options[:month] || month,
    options[:day]   || day,
    options[:hour]  || hour,
    options[:min]   || (options[:hour] ? 0 : min),
    options[:sec]   || ((options[:hour] || options[:min]) ? 0 : sec),
    options[:usec]  || ((options[:hour] || options[:min] || options[:sec]) ? 0 : usec)
  )
end

#end_of_dayObject



72
73
74
# File 'lib/time_crisis/support/change.rb', line 72

def end_of_day
  change(:hour => 23, :min => 59, :sec => 59, :usec => 999999.999)
end

#end_of_monthObject



63
64
65
66
# File 'lib/time_crisis/support/change.rb', line 63

def end_of_month
  last_day = self.class.days_in_month(self.month, self.year)
  change(:day => last_day, :hour => 23, :min => 59, :sec => 59, :usec => 999999.999)
end

#end_of_yearObject



55
56
57
# File 'lib/time_crisis/support/change.rb', line 55

def end_of_year
  change(:month => 12,:day => 31,:hour => 23, :min => 59, :sec => 59)
end