mirror of
https://github.com/TracksApp/tracks.git
synced 2026-03-11 23:22:36 +01:00
Merge pull request #202 from TracksApp/extract-extras-from-user
Extract time and date concerns from User
This commit is contained in:
commit
6681df9530
17 changed files with 71 additions and 41 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue