summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorTim Zallmann <tzallmann@gitlab.com>2017-08-06 05:57:49 +0000
committerTim Zallmann <tzallmann@gitlab.com>2017-08-06 05:57:49 +0000
commit9b93508028e9e0a8ed0f4cbc9f20de568e31cac9 (patch)
treed28754eddf76e7928135acb281565acb20c26299 /lib
parentd1f27076131ef33e18d8d690da7ecf85ff60aa3c (diff)
parent013fe7643a531d2d705c364940155983a17d95c8 (diff)
downloadgitlab-ce-9b93508028e9e0a8ed0f4cbc9f20de568e31cac9.tar.gz
Merge branch '27616-fix-contributions-graph-utc-offset-mysql' into 'master'
Fix Timezone Inconsistencies in User Contribution Calendar Closes #27616 and #1943 See merge request !13208
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab/contributions_calendar.rb14
1 files changed, 10 insertions, 4 deletions
diff --git a/lib/gitlab/contributions_calendar.rb b/lib/gitlab/contributions_calendar.rb
index bf557103cfd..0735243e021 100644
--- a/lib/gitlab/contributions_calendar.rb
+++ b/lib/gitlab/contributions_calendar.rb
@@ -48,7 +48,7 @@ module Gitlab
end
def starting_month
- Date.today.month
+ Date.current.month
end
private
@@ -66,12 +66,18 @@ module Gitlab
.select(:id)
conditions = t[:created_at].gteq(date_from.beginning_of_day)
- .and(t[:created_at].lteq(Date.today.end_of_day))
+ .and(t[:created_at].lteq(Date.current.end_of_day))
.and(t[:author_id].eq(contributor.id))
+ date_interval = if Gitlab::Database.postgresql?
+ "INTERVAL '#{Time.zone.now.utc_offset} seconds'"
+ else
+ "INTERVAL #{Time.zone.now.utc_offset} SECOND"
+ end
+
Event.reorder(nil)
- .select(t[:project_id], t[:target_type], t[:action], 'date(created_at) AS date', 'count(id) as total_amount')
- .group(t[:project_id], t[:target_type], t[:action], 'date(created_at)')
+ .select(t[:project_id], t[:target_type], t[:action], "date(created_at + #{date_interval}) AS date", 'count(id) as total_amount')
+ .group(t[:project_id], t[:target_type], t[:action], "date(created_at + #{date_interval})")
.where(conditions)
.having(t[:project_id].in(Arel::Nodes::SqlLiteral.new(authed_projects.to_sql)))
end