Skip to content

Commit

Permalink
Properly use user timezone in leaderboards
Browse files Browse the repository at this point in the history
Fix #258
  • Loading branch information
Matteo Centenaro authored and potomak committed Mar 19, 2017
1 parent d8281f2 commit 18edf2d
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions app/operations/increment_score.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ def initialize(user_id, amount, logger = Rails.logger)
end

def process
now = Time.current
upsert_score(DailyScore, to_user_timezone(now.end_of_day))
upsert_score(WeeklyScore, to_user_timezone(now.end_of_week))
upsert_score(MonthlyScore, to_user_timezone(now.end_of_month))
upsert_score(DailyScore, now_in_user_zone.end_of_day)
upsert_score(WeeklyScore, now_in_user_zone.end_of_week)
upsert_score(MonthlyScore, now_in_user_zone.end_of_month)
upsert_score(OverallScore)
end

Expand All @@ -36,7 +35,8 @@ def user
@user ||= User.find(user_id)
end

def to_user_timezone(t)
t.in_time_zone(user.time_zone)
def now_in_user_zone
zone = ActiveSupport::TimeZone[user.time_zone.to_s] || Time.zone
zone.now
end
end

0 comments on commit 18edf2d

Please sign in to comment.