From 18edf2d340f829b4791ef1d2c6fac9c25c174c9e Mon Sep 17 00:00:00 2001 From: Matteo Centenaro Date: Tue, 7 Feb 2017 09:46:43 +0100 Subject: [PATCH] Properly use user timezone in leaderboards Fix #258 --- app/operations/increment_score.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/operations/increment_score.rb b/app/operations/increment_score.rb index c5fc24a0..0d12d814 100644 --- a/app/operations/increment_score.rb +++ b/app/operations/increment_score.rb @@ -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 @@ -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