From 850ef3bda062189d88ee0a01eff8f34d90300d59 Mon Sep 17 00:00:00 2001 From: ArtOfCode- <hello@artofcode.co.uk> Date: Wed, 16 Dec 2020 16:16:39 +0000 Subject: [PATCH] Use DateTime --- app/controllers/advertisement_controller.rb | 2 +- app/controllers/application_controller.rb | 4 ++-- app/controllers/comments_controller.rb | 2 +- app/controllers/flags_controller.rb | 2 +- app/controllers/posts_controller.rb | 4 ++-- app/controllers/suspicious_votes_controller.rb | 2 +- app/controllers/votes_controller.rb | 2 +- 7 files changed, 9 insertions(+), 9 deletions(-) diff --git a/app/controllers/advertisement_controller.rb b/app/controllers/advertisement_controller.rb index e884040c6..12f2b34f7 100644 --- a/app/controllers/advertisement_controller.rb +++ b/app/controllers/advertisement_controller.rb @@ -197,7 +197,7 @@ class AdvertisementController < ApplicationController if category.nil? category = Category.where(use_for_advertisement: true) end - Post.undeleted.where(last_activity: (Rails.env.development? ? 365 : 7).days.ago..Time.zone.now) + Post.undeleted.where(last_activity: (Rails.env.development? ? 365 : 7).days.ago..DateTime.now) .where(post_type_id: Question.post_type_id) .where(category: category) .where('score > ?', SiteSetting['HotPostsScoreThreshold']) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 527bc7b61..2cc78054b 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -115,7 +115,7 @@ class ApplicationController < ActionController::Base end def check_edits_limit!(post) - recent_edits = SuggestedEdit.where(created_at: 24.hours.ago..Time.zone.now, user: current_user) \ + recent_edits = SuggestedEdit.where(created_at: 24.hours.ago..DateTime.now, user: current_user) \ .where('active = TRUE OR accepted = FALSE').count max_edits = SiteSetting[if current_user.privilege?('unrestricted') @@ -232,7 +232,7 @@ class ApplicationController < ActionController::Base end @hot_questions = Rails.cache.fetch("#{RequestContext.community_id}/hot_questions", expires_in: 4.hours) do Rack::MiniProfiler.step 'hot_questions: cache miss' do - Post.undeleted.where(last_activity: (Rails.env.development? ? 365 : 7).days.ago..Time.zone.now) + Post.undeleted.where(last_activity: (Rails.env.development? ? 365 : 7).days.ago..DateTime.now) .where(post_type_id: [Question.post_type_id, Article.post_type_id]) .joins(:category).where(categories: { use_for_hot_posts: true }) .where('score >= ?', SiteSetting['HotPostsScoreThreshold']) diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index c860421ac..3356e4b95 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -15,7 +15,7 @@ class CommentsController < ApplicationController @comment = Comment.new comment_params.merge(user: current_user) - recent_comments = Comment.where(created_at: 24.hours.ago..Time.zone.now, user: current_user).where \ + recent_comments = Comment.where(created_at: 24.hours.ago..DateTime.now, user: current_user).where \ .not(post: Post.includes(:parent).where(parents_posts: { user_id: current_user.id })) \ .where.not(post: Post.where(user_id: current_user.id)).count max_comments_per_day = SiteSetting[current_user.privilege?('unrestricted') ? 'RL_Comments' : 'RL_NewUserComments'] diff --git a/app/controllers/flags_controller.rb b/app/controllers/flags_controller.rb index b07e521d1..d1d057520 100644 --- a/app/controllers/flags_controller.rb +++ b/app/controllers/flags_controller.rb @@ -9,7 +9,7 @@ class FlagsController < ApplicationController PostFlagType.find params[:flag_type] end - recent_flags = Flag.where(created_at: 24.hours.ago..Time.zone.now, user: current_user).count + recent_flags = Flag.where(created_at: 24.hours.ago..DateTime.now, user: current_user).count max_flags_per_day = SiteSetting[current_user.privilege?('unrestricted') ? 'RL_Flags' : 'RL_NewUserFlags'] if recent_flags >= max_flags_per_day diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index d2aea372e..0486ab394 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -68,7 +68,7 @@ class PostsController < ApplicationController level_name = @post_type.is_top_level? ? 'TopLevel' : 'SecondLevel' level_type_ids = @post_type.is_top_level? ? top_level_post_types : second_level_post_types - recent_level_posts = Post.where(created_at: 24.hours.ago..Time.zone.now, user: current_user) + recent_level_posts = Post.where(created_at: 24.hours.ago..DateTime.now, user: current_user) .where(post_type_id: level_type_ids).count setting_name = current_user.privilege?('unrestricted') ? "RL_#{level_name}Posts" : "RL_NewUser#{level_name}Posts" max_posts = SiteSetting[setting_name] @@ -230,7 +230,7 @@ class PostsController < ApplicationController return end - if @post.update(closed: false, closed_by: current_user, closed_at: Time.zone.now, + if @post.update(closed: false, closed_by: current_user, closed_at: DateTime.now, last_activity: DateTime.now, last_activity_by: current_user, close_reason: nil, duplicate_post: nil) PostHistory.question_reopened(@post, current_user) diff --git a/app/controllers/suspicious_votes_controller.rb b/app/controllers/suspicious_votes_controller.rb index 7092843a8..9189e5af0 100644 --- a/app/controllers/suspicious_votes_controller.rb +++ b/app/controllers/suspicious_votes_controller.rb @@ -15,7 +15,7 @@ class SuspiciousVotesController < ApplicationController def investigated @sv = SuspiciousVote.find params[:id] @sv.was_investigated = true - @sv.investigated_at = Time.zone.now + @sv.investigated_at = DateTime.now @sv.investigated_by = current_user.id if @sv.save render json: { status: 'success' } diff --git a/app/controllers/votes_controller.rb b/app/controllers/votes_controller.rb index cad1790c7..a8c13a7b9 100644 --- a/app/controllers/votes_controller.rb +++ b/app/controllers/votes_controller.rb @@ -10,7 +10,7 @@ class VotesController < ApplicationController render(json: { status: 'failed', message: 'You may not vote on your own posts.' }, status: :forbidden) && return end - recent_votes = Vote.where(created_at: 24.hours.ago..Time.zone.now, user: current_user) \ + recent_votes = Vote.where(created_at: 24.hours.ago..DateTime.now, user: current_user) \ .where.not(post: Post.includes(:parent).where(parents_posts: { user_id: current_user.id })).count max_votes_per_day = SiteSetting[current_user.privilege?('unrestricted') ? 'RL_Votes' : 'RL_NewUserVotes'] -- GitLab