Browse Source

Corrected with rubocop cop 'Rails/TimeZone'.

Thorsten Eckel 9 years ago
parent
commit
409ae23e78

+ 0 - 2
.rubocop.yml

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

+ 1 - 3
app/controllers/application_controller.rb

@@ -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

+ 4 - 0
app/controllers/ical_tickets_controller.rb

@@ -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 }"
 

+ 2 - 2
app/controllers/long_polling_controller.rb

@@ -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

+ 1 - 1
app/controllers/sessions_controller.rb

@@ -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 => {

+ 1 - 1
app/models/application_model/activity_stream_base.rb

@@ -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'],

+ 4 - 4
app/models/job.rb

@@ -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

+ 1 - 1
app/models/observer/ticket/close_time.rb

@@ -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

+ 1 - 1
app/models/package.rb

@@ -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
 

+ 6 - 6
app/models/scheduler.rb

@@ -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}'"

Some files were not shown because too many files changed in this diff