Commit bb42181e authored by Sean Arnold's avatar Sean Arnold Committed by Stan Hu

Fix cases of Time misuse

Time.at => Time.zone.at
Time.parse => Time.zone.parse
Time.new => Time.zone.local
parent 968fd96e
...@@ -144,7 +144,7 @@ class Import::GithubController < Import::BaseController ...@@ -144,7 +144,7 @@ class Import::GithubController < Import::BaseController
end end
def provider_rate_limit(exception) def provider_rate_limit(exception)
reset_time = Time.at(exception.response_headers['x-ratelimit-reset'].to_i) reset_time = Time.zone.at(exception.response_headers['x-ratelimit-reset'].to_i)
session[access_token_key] = nil session[access_token_key] = nil
redirect_to new_import_url, redirect_to new_import_url,
alert: _("GitHub API rate limit exceeded. Try again after %{reset_time}") % { reset_time: reset_time } alert: _("GitHub API rate limit exceeded. Try again after %{reset_time}") % { reset_time: reset_time }
......
...@@ -58,7 +58,7 @@ class ProjectsController < Projects::ApplicationController ...@@ -58,7 +58,7 @@ class ProjectsController < Projects::ApplicationController
@project = ::Projects::CreateService.new(current_user, project_params(attributes: project_params_create_attributes)).execute @project = ::Projects::CreateService.new(current_user, project_params(attributes: project_params_create_attributes)).execute
if @project.saved? if @project.saved?
cookies[:issue_board_welcome_hidden] = { path: project_path(@project), value: nil, expires: Time.at(0) } cookies[:issue_board_welcome_hidden] = { path: project_path(@project), value: nil, expires: Time.zone.at(0) }
redirect_to( redirect_to(
project_path(@project, custom_import_params), project_path(@project, custom_import_params),
......
...@@ -17,8 +17,8 @@ module Projects ...@@ -17,8 +17,8 @@ module Projects
result = adapter.query( result = adapter.query(
:packet_flow, environment.deployment_namespace, :packet_flow, environment.deployment_namespace,
params[:interval] || "minute", params[:interval] || "minute",
(Time.parse(params[:from]) rescue 1.hour.ago).to_s, (Time.zone.parse(params[:from]) rescue 1.hour.ago).to_s,
(Time.parse(params[:to]) rescue Time.current).to_s (Time.zone.parse(params[:to]) rescue Time.current).to_s
) )
respond_to do |format| respond_to do |format|
......
...@@ -41,7 +41,7 @@ describe Projects::Security::NetworkPoliciesController do ...@@ -41,7 +41,7 @@ describe Projects::Security::NetworkPoliciesController do
expect(adapter).to( expect(adapter).to(
receive(:query) receive(:query)
.with(:packet_flow, kubernetes_namespace, "minute", 1.hour.ago.to_s, Time.current.to_s) .with(:packet_flow, kubernetes_namespace, "minute", 1.hour.ago.to_s, Time.current.to_s)
.and_return({ success: true, data: { ops_rate: [[Time.at(0).to_i, 10]], ops_total: 10 } }) .and_return({ success: true, data: { ops_rate: [[Time.zone.at(0).to_i, 10]], ops_total: 10 } })
) )
subject subject
end end
...@@ -55,14 +55,14 @@ describe Projects::Security::NetworkPoliciesController do ...@@ -55,14 +55,14 @@ describe Projects::Security::NetworkPoliciesController do
let(:action_params) do let(:action_params) do
{ {
project_id: project, namespace_id: project.namespace, environment_id: environment, project_id: project, namespace_id: project.namespace, environment_id: environment,
interval: "day", from: Time.at(0), to: Time.at(100) interval: "day", from: Time.zone.at(0), to: Time.zone.at(100)
} }
end end
it 'queries with requested arguments' do it 'queries with requested arguments' do
expect(adapter).to( expect(adapter).to(
receive(:query) receive(:query)
.with(:packet_flow, kubernetes_namespace, "day", Time.at(0).to_s, Time.at(100).to_s) .with(:packet_flow, kubernetes_namespace, "day", Time.zone.at(0).to_s, Time.zone.at(100).to_s)
.and_return({ success: true, data: {} }) .and_return({ success: true, data: {} })
) )
subject subject
......
...@@ -14,7 +14,7 @@ describe ApplicationController do ...@@ -14,7 +14,7 @@ describe ApplicationController do
end end
it 'redirects if the user is over their password expiry' do it 'redirects if the user is over their password expiry' do
user.password_expires_at = Time.new(2002) user.password_expires_at = Time.zone.local(2002)
expect(user.ldap_user?).to be_falsey expect(user.ldap_user?).to be_falsey
allow(controller).to receive(:current_user).and_return(user) allow(controller).to receive(:current_user).and_return(user)
...@@ -35,7 +35,7 @@ describe ApplicationController do ...@@ -35,7 +35,7 @@ describe ApplicationController do
end end
it 'does not redirect if the user is over their password expiry but they are an ldap user' do it 'does not redirect if the user is over their password expiry but they are an ldap user' do
user.password_expires_at = Time.new(2002) user.password_expires_at = Time.zone.local(2002)
allow(user).to receive(:ldap_user?).and_return(true) allow(user).to receive(:ldap_user?).and_return(true)
allow(controller).to receive(:current_user).and_return(user) allow(controller).to receive(:current_user).and_return(user)
...@@ -47,7 +47,7 @@ describe ApplicationController do ...@@ -47,7 +47,7 @@ describe ApplicationController do
it 'does not redirect if the user is over their password expiry but password authentication is disabled for the web interface' do it 'does not redirect if the user is over their password expiry but password authentication is disabled for the web interface' do
stub_application_setting(password_authentication_enabled_for_web: false) stub_application_setting(password_authentication_enabled_for_web: false)
stub_application_setting(password_authentication_enabled_for_git: false) stub_application_setting(password_authentication_enabled_for_git: false)
user.password_expires_at = Time.new(2002) user.password_expires_at = Time.zone.local(2002)
allow(controller).to receive(:current_user).and_return(user) allow(controller).to receive(:current_user).and_return(user)
expect(controller).not_to receive(:redirect_to) expect(controller).not_to receive(:redirect_to)
......
...@@ -56,7 +56,7 @@ describe Groups::Settings::RepositoryController do ...@@ -56,7 +56,7 @@ describe Groups::Settings::RepositoryController do
'id' => be_a(Integer), 'id' => be_a(Integer),
'name' => deploy_token_params[:name], 'name' => deploy_token_params[:name],
'username' => deploy_token_params[:username], 'username' => deploy_token_params[:username],
'expires_at' => Time.parse(deploy_token_params[:expires_at]), 'expires_at' => Time.zone.parse(deploy_token_params[:expires_at]),
'token' => be_a(String), 'token' => be_a(String),
'scopes' => deploy_token_params.inject([]) do |scopes, kv| 'scopes' => deploy_token_params.inject([]) do |scopes, kv|
key, value = kv key, value = kv
......
...@@ -73,7 +73,7 @@ describe Projects::Settings::RepositoryController do ...@@ -73,7 +73,7 @@ describe Projects::Settings::RepositoryController do
'id' => be_a(Integer), 'id' => be_a(Integer),
'name' => deploy_token_params[:name], 'name' => deploy_token_params[:name],
'username' => deploy_token_params[:username], 'username' => deploy_token_params[:username],
'expires_at' => Time.parse(deploy_token_params[:expires_at]), 'expires_at' => Time.zone.parse(deploy_token_params[:expires_at]),
'token' => be_a(String), 'token' => be_a(String),
'scopes' => deploy_token_params.inject([]) do |scopes, kv| 'scopes' => deploy_token_params.inject([]) do |scopes, kv|
key, value = kv key, value = kv
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment