Merge pull request #202 from TracksApp/extract-extras-from-user

Extract time and date concerns from User
This commit is contained in:
Matt Rogers 2013-08-01 14:59:17 -07:00
commit 6681df9530
17 changed files with 71 additions and 41 deletions

View file

@ -1,7 +1,7 @@
class Preference < ActiveRecord::Base
belongs_to :user
belongs_to :sms_context, :class_name => 'Context'
def self.due_styles
{ :due_in_n_days => 0, :due_on => 1}
end
@ -22,6 +22,6 @@ class Preference < ActiveRecord::Base
raise ArgumentError.new("Bad argument type:#{s.class}")
end
user.at_midnight(date)
UserTime.new(user).midnight(date)
end
end

View file

@ -99,9 +99,10 @@ class Project < ActiveRecord::Base
end
end
def needs_review?(current_user)
def needs_review?(user)
current_time = UserTime.new(user).time
return active? && ( last_reviewed.nil? ||
(last_reviewed < current_user.time - current_user.prefs.review_period.days))
(last_reviewed < current_time - user.prefs.review_period.days))
end
def blocked?
@ -134,7 +135,7 @@ class Project < ActiveRecord::Base
end
def age_in_days
@age_in_days ||= (Date.today - created_at.to_date + 1).to_i
@age_in_days ||= ((Time.now.utc - created_at).to_i / 1.day) + 1
end
def self.import(params, user)

View file

@ -263,7 +263,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 = UserTime.new(user).midnight(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

@ -159,16 +159,8 @@ class User < ActiveRecord::Base
save!
end
def time
Time.now.in_time_zone(prefs.time_zone)
end
def date
time.midnight
end
def at_midnight(date)
return ActiveSupport::TimeZone[prefs.time_zone].local(date.year, date.month, date.day, 0, 0, 0)
UserTime.new(self).midnight(Time.now)
end
def generate_token