Corrected with rubocop cop 'Rails/TimeZone'.

This commit is contained in:
Thorsten Eckel 2015-05-08 12:20:33 +02:00
parent f3a9fdb8b3
commit 409ae23e78
19 changed files with 56 additions and 56 deletions

View file

@ -196,8 +196,6 @@ Style/CommentIndentation:
Enabled: false
Style/GlobalVars:
Enabled: false
Rails/TimeZone:
Enabled: false
Lint/RescueException:
Enabled: false
Style/ClassVars:

View file

@ -82,9 +82,7 @@ class ApplicationController < ActionController::Base
def session_update
#sleep 0.6
# on many paralell requests, session got reinitialised if Time. is used, as workaround use DateTime.
#session[:ping] = Time.now.utc.iso8601
session[:ping] = DateTime.now.iso8601
session[:ping] = Time.zone.now.iso8601
# check if remote ip need to be updated
if !session[:remote_id] || session[:remote_id] != request.remote_ip

View file

@ -125,8 +125,10 @@ class IcalTicketsController < ApplicationController
event_data = {}
# rubocop:disable Rails/TimeZone
event_data[:dtstart] = Icalendar::Values::DateTime.new( ticket.pending_time )
event_data[:dtend] = Icalendar::Values::DateTime.new( ticket.pending_time )
# rubocop:enable Rails/TimeZone
event_data[:summary] = "#{ ticket.state.name } ticket: '#{ ticket.title }'"
event_data[:description] = "T##{ ticket.number }"
@ -153,8 +155,10 @@ class IcalTicketsController < ApplicationController
event_data = {}
# rubocop:disable Rails/TimeZone
event_data[:dtstart] = Icalendar::Values::DateTime.new( ticket.escalation_time )
event_data[:dtend] = Icalendar::Values::DateTime.new( ticket.escalation_time )
# rubocop:enable Rails/TimeZone
event_data[:summary] = "ticket escalation: '#{ ticket.title }'"
event_data[:description] = "T##{ ticket.number }"

View file

@ -29,7 +29,7 @@ class LongPollingController < ApplicationController
# error handling
if params['data']['timestamp']
log "request spool data > '#{Time.at( params['data']['timestamp'] )}'", client_id
log "request spool data > '#{Time.zone.at( params['data']['timestamp'] )}'", client_id
else
log 'request spool init data', client_id
end
@ -50,7 +50,7 @@ class LongPollingController < ApplicationController
# send spool:sent event to client
sleep 0.2
log 'send spool:sent event', client_id
Sessions.send( client_id, { event: 'spool:sent', data: { timestamp: Time.now.utc.to_i } } )
Sessions.send( client_id, { event: 'spool:sent', data: { timestamp: Time.zone.now.utc.to_i } } )
end
# receive message

View file

@ -45,7 +45,7 @@ class SessionsController < ApplicationController
# check logon session
logon_session_key = nil
if params['logon_session']
logon_session_key = Digest::MD5.hexdigest( rand(999_999).to_s + Time.new.to_s )
logon_session_key = Digest::MD5.hexdigest( rand(999_999).to_s + Time.zone.now.to_s )
# session = ActiveRecord::SessionStore::Session.create(
# :session_id => logon_session_key,
# :data => {

View file

@ -29,7 +29,7 @@ returns
role = self.class.activity_stream_support_config[:role]
updated_at = self.updated_at
if force
updated_at = Time.new
updated_at = Time.zone.now
end
ActivityStream.add(
o_id: self['id'],

View file

@ -12,7 +12,7 @@ class Job < ApplicationModel
notify_clients_support
def self.run
time = Time.new
time = Time.zone.now
day_map = {
0 => 'sun',
1 => 'mon',
@ -26,11 +26,11 @@ class Job < ApplicationModel
jobs.each do |job|
# only execute jobs, older then 1 min, to give admin posibility to change
next if job.updated_at > Time.now - 1.minutes
next if job.updated_at > Time.zone.now - 1.minutes
# check if jobs need to be executed
# ignore if job was running within last 10 min.
next if job.last_run_at && job.last_run_at > Time.now - 10.minutes
next if job.last_run_at && job.last_run_at > Time.zone.now - 10.minutes
# check day
next if !job.timeplan['days'].include?( day_map[time.wday] )
@ -66,7 +66,7 @@ class Job < ApplicationModel
ticket.save
end
job.last_run_at = Time.now
job.last_run_at = Time.zone.now
job.save
end
true

View file

@ -27,6 +27,6 @@ class Observer::Ticket::CloseTime < ActiveRecord::Observer
return true if state_type.name != 'closed'
# set close_time
record.close_time = Time.now
record.close_time = Time.zone.now
end
end

View file

@ -20,7 +20,7 @@ class Package < ApplicationModel
end
build_date = REXML::Element.new('build_date')
build_date.text = Time.now.utc.iso8601
build_date.text = Time.zone.now.iso8601
build_host = REXML::Element.new('build_host')
build_host.text = Socket.gethostname

View file

@ -61,10 +61,10 @@ class Scheduler < ApplicationModel
}
end
def self._start_job( job, runner, runner_count, try_count = 0, try_run_time = Time.now )
def self._start_job( job, runner, runner_count, try_count = 0, try_run_time = Time.zone.now )
sleep 5
begin
job.last_run = Time.now
job.last_run = Time.zone.now
job.pid = Thread.current.object_id
job.save
logger.info "execute #{job.method} (runner #{runner} of #{runner_count}, try_count #{try_count})..."
@ -83,10 +83,10 @@ class Scheduler < ApplicationModel
try_count += 1
# reset error counter if to old
if try_run_time + ( 60 * 5 ) < Time.now
if try_run_time + ( 60 * 5 ) < Time.zone.now
try_count = 0
end
try_run_time = Time.now
try_run_time = Time.zone.now
# restart job again
if try_run_max > try_count
@ -122,8 +122,8 @@ class Scheduler < ApplicationModel
end
def self.check( name, time_warning = 10, time_critical = 20 )
time_warning_time = Time.now - time_warning.minutes
time_critical_time = Time.now - time_critical.minutes
time_warning_time = Time.zone.now - time_warning.minutes
time_critical_time = Time.zone.now - time_critical.minutes
scheduler = Scheduler.find_by( name: name )
if !scheduler
puts "CRITICAL - no such scheduler jobs '#{name}'"

View file

@ -9,7 +9,7 @@ class Taskbar < ApplicationModel
private
def update_last_contact
self.last_contact = Time.now
self.last_contact = Time.zone.now
end
def set_user

View file

@ -206,7 +206,7 @@ returns
sql += " #{key} IN (?)"
bind.push value
elsif value.class == Hash || value.class == ActiveSupport::HashWithIndifferentAccess
time = Time.now
time = Time.zone.now
if value['area'] == 'minute'
if value['direction'] == 'last'
time -= value['count'].to_i * 60

View file

@ -399,7 +399,7 @@ returns
=end
def update_last_login
self.last_login = Time.now
self.last_login = Time.zone.now
# reset login failed
self.login_failed = 0

View file

@ -29,10 +29,10 @@ module SessionHelper
def self.cleanup_expired
# web sessions
ActiveRecord::SessionStore::Session.where('request_type = ? AND updated_at < ?', 1, Time.now - 90.days ).delete_all
ActiveRecord::SessionStore::Session.where('request_type = ? AND updated_at < ?', 1, Time.zone.now - 90.days ).delete_all
# http basic auth calls
ActiveRecord::SessionStore::Session.where('request_type = ? AND updated_at < ?', 2, Time.now - 2.days ).delete_all
ActiveRecord::SessionStore::Session.where('request_type = ? AND updated_at < ?', 2, Time.zone.now - 2.days ).delete_all
end
def self.get(id)

View file

@ -33,7 +33,7 @@ returns
session_file = "#{path_tmp}/session"
# collect session data
meta[:last_ping] = Time.new.to_i.to_s
meta[:last_ping] = Time.zone.now.to_i.to_s
data = {
user: session,
meta: meta,
@ -189,7 +189,7 @@ returns
list_of_closed_sessions = []
clients = Sessions.list
clients.each { |client_id, client|
if !client[:meta] || !client[:meta][:last_ping] || ( client[:meta][:last_ping].to_i + idle_time_in_sec ) < Time.now.to_i
if !client[:meta] || !client[:meta][:last_ping] || ( client[:meta][:last_ping].to_i + idle_time_in_sec ) < Time.zone.now.to_i
list_of_closed_sessions.push client_id
Sessions.destory( client_id )
end
@ -213,7 +213,7 @@ returns
data = get(client_id)
return false if !data
path = "#{@path}/#{client_id}"
data[:meta][:last_ping] = Time.new.to_i.to_s
data[:meta][:last_ping] = Time.zone.now.to_i.to_s
content = data.to_json
File.open( path + '/session', 'wb' ) { |file|
file.write content
@ -289,7 +289,7 @@ returns
def self.send( client_id, data )
path = "#{@path}/#{client_id}/"
filename = "send-#{ Time.new().to_f }"
filename = "send-#{ Time.zone.now.to_f }"
check = true
count = 0
while check
@ -422,11 +422,11 @@ returns
def self.spool_create( msg )
path = "#{@path}/spool/"
FileUtils.mkpath path
file = "#{Time.new.to_f}-#{rand(99_999)}"
file = "#{Time.zone.now.to_f}-#{rand(99_999)}"
File.open( path + '/' + file, 'wb' ) { |file|
data = {
msg: msg,
timestamp: Time.now.to_i,
timestamp: Time.zone.now.to_i,
}
file.write data.to_json
}
@ -457,7 +457,7 @@ returns
end
# ignore message older then 48h
if spool['timestamp'] + (2 * 86_400) < Time.now.to_i
if spool['timestamp'] + (2 * 86_400) < Time.zone.now.to_i
to_delete.push "#{path}/#{entry}"
next
end
@ -568,7 +568,7 @@ returns
=end
def self.thread_client(client_id, try_count = 0, try_run_time = Time.now)
def self.thread_client(client_id, try_count = 0, try_run_time = Time.zone.now)
Rails.logger.debug "LOOP #{client_id} - #{try_count}"
begin
Sessions::Client.new(client_id)
@ -586,10 +586,10 @@ returns
try_count += 1
# reset error counter if to old
if try_run_time + ( 60 * 5 ) < Time.now
if try_run_time + ( 60 * 5 ) < Time.zone.now
try_count = 0
end
try_run_time = Time.now
try_run_time = Time.zone.now
# restart job again
if try_run_max > try_count

View file

@ -11,11 +11,11 @@ module Sessions::CacheIn
def self.set( key, value, params = {} )
if params[:expires_in]
@@expires_in[key] = Time.now + params[:expires_in]
@@expires_in[key] = Time.zone.now + params[:expires_in]
@@expires_in_ttl[key] = params[:expires_in]
end
@@data[ key ] = value
@@data_time[ key ] = Time.now
@@data_time[ key ] = Time.zone.now
end
def self.expired( key, params = {} )
@ -29,14 +29,14 @@ module Sessions::CacheIn
# set re_expire
if params[:re_expire]
if @@expires_in[key]
@@expires_in[key] = Time.now + @@expires_in_ttl[key]
@@expires_in[key] = Time.zone.now + @@expires_in_ttl[key]
end
return false
end
# check if expired
if @@expires_in[key]
return true if @@expires_in[key] < Time.now
return true if @@expires_in[key] < Time.zone.now
return false
end

View file

@ -5,7 +5,7 @@ namespace :test do
desc 'Start browser tests'
task :browser, [:opts] => :environment do |_t, args|
start = Time.now()
start = Time.zone.now
if !args.opts
args.opts = ''
end
@ -14,7 +14,7 @@ namespace :test do
fail 'Failed test. ' + res.inspect if !ok
end
}
puts 'All browser tests, elapsed: ' + (Time.now() - start).to_s + ' seconds'
puts 'All browser tests, elapsed: ' + (Time.zone.now - start).to_s + ' seconds'
end
end

View file

@ -22,15 +22,15 @@ put working hours matrix and timezone in function, returns UTC working hours mat
time_diff = 0
if timezone
begin
time_diff = Time.parse(start_time.to_s).in_time_zone(timezone).utc_offset
time_diff = Time.zone.parse(start_time.to_s).in_time_zone(timezone).utc_offset
rescue Exception => e
Rails.logger.error "Can't fine tomezone #{timezone}"
Rails.logger.error e.inspect
Rails.logger.error e.backtrace
end
end
beginning_of_workday = Time.parse("1977-10-27 #{config['beginning_of_workday']}")
end_of_workday = Time.parse("1977-10-27 #{config['end_of_workday']}") - 3600
beginning_of_workday = Time.zone.parse("1977-10-27 #{config['beginning_of_workday']}")
end_of_workday = Time.zone.parse("1977-10-27 #{config['end_of_workday']}") - 3600
config_ok = false
working_hours = {}
[:Mon, :Tue, :Wed, :Thu, :Fri, :Sat, :Sun].each {|day|
@ -43,7 +43,7 @@ put working hours matrix and timezone in function, returns UTC working hours mat
config_ok = true
(0..23).each {|hour|
time = Time.parse("1977-10-27 #{hour}:00:00")
time = Time.zone.parse("1977-10-27 #{hour}:00:00")
if time >= beginning_of_workday && time <= end_of_workday
working_hours[day].push true
else
@ -116,10 +116,10 @@ put working hours matrix and timezone in function, returns UTC working hours mat
def self.business_time_diff(start_time, end_time, config = nil, timezone = '')
if start_time.class == String
start_time = Time.parse( start_time.to_s + 'UTC' )
start_time = Time.zone.parse( start_time.to_s + 'UTC' )
end
if end_time.class == String
end_time = Time.parse( end_time.to_s + 'UTC' )
end_time = Time.zone.parse( end_time.to_s + 'UTC' )
end
# if no config is given, just return calculation directly
@ -236,7 +236,7 @@ put working hours matrix and timezone in function, returns UTC working hours mat
def self.dest_time(start_time, diff_in_min, config = nil, timezone = '')
if start_time.class == String
start_time = Time.parse( start_time.to_s + ' UTC' )
start_time = Time.zone.parse( start_time.to_s + ' UTC' )
end
return start_time if diff_in_min == 0

View file

@ -95,7 +95,7 @@ EventMachine.run {
if !@clients.include? client_id
@clients[client_id] = {
websocket: ws,
last_ping: Time.new,
last_ping: Time.zone.now,
error_count: 0,
}
end
@ -139,7 +139,7 @@ EventMachine.run {
# error handling
if data['timestamp']
log 'notice', "request spool data > '#{Time.at(data['timestamp'])}'", client_id
log 'notice', "request spool data > '#{Time.zone.at(data['timestamp'])}'", client_id
else
log 'notice', 'request spool with init data', client_id
end
@ -164,7 +164,7 @@ EventMachine.run {
# send spool:sent event to client
log 'notice', 'send spool:sent event', client_id
@clients[client_id][:websocket].send( '[{"event":"spool:sent","data":{"timestamp":' + Time.now.utc.to_i.to_s + '}}]' )
@clients[client_id][:websocket].send( '[{"event":"spool:sent","data":{"timestamp":' + Time.zone.now.to_i.to_s + '}}]' )
end
# get session
@ -175,7 +175,7 @@ EventMachine.run {
# remember ping, send pong back
elsif data['action'] == 'ping'
Sessions.touch(client_id)
@clients[client_id][:last_ping] = Time.now
@clients[client_id][:last_ping] = Time.zone.now
@clients[client_id][:websocket].send( '[{"action":"pong"}]' )
# broadcast
@ -298,7 +298,7 @@ EventMachine.run {
# close unused web socket sessions
@clients.each { |client_id, client|
next if ( client[:last_ping] + idle_time_in_sec ) >= Time.now
next if ( client[:last_ping] + idle_time_in_sec ) >= Time.zone.now
log 'notice', 'closing idle websocket connection', client_id
@ -324,8 +324,8 @@ EventMachine.run {
if !@options[:v]
return if level == 'debug'
end
puts "#{Time.now}:client(#{ client_id }) #{ data }"
# puts "#{Time.now}:#{ level }:client(#{ client_id }) #{ data }"
puts "#{Time.zone.now}:client(#{ client_id }) #{ data }"
# puts "#{Time.zone.now}:#{ level }:client(#{ client_id }) #{ data }"
end
}