Remove User#at_midnight

Replace it with a class called DateUtils with a method called
`#midnight_for` that takes a preference instance and date to convert to
midnight.
This commit is contained in:
Matt Rogers 2013-07-29 16:34:23 -05:00
parent e7c6142684
commit a1aaa283f1
6 changed files with 12 additions and 8 deletions

View file

@ -22,6 +22,6 @@ class Preference < ActiveRecord::Base
raise ArgumentError.new("Bad argument type:#{s.class}")
end
user.at_midnight(date)
DateUtils::midnight_for(self, date)
end
end

View file

@ -260,7 +260,7 @@ class Todo < ActiveRecord::Base
activate
else
# parse Date objects into the proper timezone
date = user.at_midnight(date) if (date.is_a? Date)
date = DateUtils.midnight_for(user.prefs, date) if (date.is_a? Date)
# show_from needs to be set before state_change because of "bug" in aasm.
# If show_from is not set, the todo will not validate and thus aasm will not save

View file

@ -167,10 +167,6 @@ class User < ActiveRecord::Base
time.midnight
end
def at_midnight(date)
return ActiveSupport::TimeZone[prefs.time_zone].local(date.year, date.month, date.day, 0, 0, 0)
end
def generate_token
self.token = Digest::SHA1.hexdigest "#{Time.now.to_i}#{rand}"
end