13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/time_calculations.rb', line 13
def round_up(what)
case what
when :year
self == beginning_of_year ? self : advance(:years => 1).beginning_of_year
when :month
self == beginning_of_month ? self : advance(:months => 1).beginning_of_month
when :day
return self unless acts_like?(:time)
self == beginning_of_day ? self : advance(:days => 1).beginning_of_day
when :hour
return self unless acts_like?(:time)
self == beginning_of_hour ? self : advance(:hours => 1).beginning_of_hour
when :minute
return self unless acts_like?(:time)
self == beginning_of_minute ? self : advance(:minutes => 1).beginning_of_minute
else
raise ArgumentError, "Don't know how to round up #{what}"
end
end
|