Quellcode durchsuchen

Avoid DateTime usage

Maarten van den Berg vor 6 Jahren
Ursprung
Commit
79cbb9ab11

+ 0 - 11
.rubocop.yml

70
     - 'app/mailers/participant_mailer.rb'
70
     - 'app/mailers/participant_mailer.rb'
71
     - 'db/seeds.rb'
71
     - 'db/seeds.rb'
72
 
72
 
73
-# Offense count: 8
74
-# Configuration parameters: AllowCoercion.
75
-Style/DateTime:
76
-  Exclude:
77
-    - 'app/controllers/api/groups_controller.rb'
78
-    - 'app/controllers/authentication_controller.rb'
79
-    - 'app/controllers/dashboard_controller.rb'
80
-    - 'app/helpers/authentication_helper.rb'
81
-    - 'app/models/group.rb'
82
-    - 'db/seeds.rb'
83
-
84
 # Offense count: 55
73
 # Offense count: 55
85
 Style/Documentation:
74
 Style/Documentation:
86
   Enabled: false
75
   Enabled: false

+ 1 - 1
app/controllers/api/groups_controller.rb

61
       return unless input
61
       return unless input
62
 
62
 
63
       begin
63
       begin
64
-        DateTime.parse input
64
+        DateTime.parse input # rubocop:disable Style/DateTime
65
       rescue ArgumentError
65
       rescue ArgumentError
66
         nil
66
         nil
67
       end
67
       end

+ 2 - 1
app/controllers/authentication_controller.rb

159
       redirect_to action: 'login'
159
       redirect_to action: 'login'
160
       return false
160
       return false
161
     end
161
     end
162
-    if token.expires && (token.expires < DateTime.now)
162
+
163
+    if token.expires&.past?
163
       flash_message(:warning, I18n.t('authentication.token_expired'))
164
       flash_message(:warning, I18n.t('authentication.token_expired'))
164
       redirect_to action: 'login'
165
       redirect_to action: 'login'
165
       return false
166
       return false

+ 1 - 1
app/controllers/dashboard_controller.rb

5
     @upcoming = current_person
5
     @upcoming = current_person
6
                 .participants
6
                 .participants
7
                 .joins(:activity)
7
                 .joins(:activity)
8
-                .where('activities.end >= ? OR (activities.end IS NULL AND activities.start >= ?)', DateTime.now, DateTime.now)
8
+                .where('activities.end >= ? OR (activities.end IS NULL AND activities.start >= ?)', Time.now, Time.now)
9
                 .order('activities.start ASC')
9
                 .order('activities.start ASC')
10
     @user_organized = @upcoming
10
     @user_organized = @upcoming
11
                       .where(is_organizer: true)
11
                       .where(is_organizer: true)

+ 3 - 3
app/helpers/authentication_helper.rb

60
   def logged_in?
60
   def logged_in?
61
     # Case 1: User has an active session inside the cookie.
61
     # Case 1: User has an active session inside the cookie.
62
     # We verify that the session hasn't expired yet.
62
     # We verify that the session hasn't expired yet.
63
-    if session[:user_id] && session[:expires].to_time > DateTime.now
63
+    if session[:user_id] && session[:expires].to_time.future?
64
 
64
 
65
       user_session
65
       user_session
66
 
66
 
67
-      return false if !@user_session.active || @user_session.expires < Time.now
67
+      return false if !@user_session.active || @user_session.expires.past?
68
 
68
 
69
       true
69
       true
70
 
70
 
80
 
80
 
81
         session_password = BCrypt::Password.new @user_session.remember_digest
81
         session_password = BCrypt::Password.new @user_session.remember_digest
82
 
82
 
83
-        if @user_session.expires > DateTime.now &&
83
+        if @user_session.expires.future? &&
84
            session_password == cookies.signed.permanent[:remember_token]
84
            session_password == cookies.signed.permanent[:remember_token]
85
           log_in @user_session.user, false, false
85
           log_in @user_session.user, false, false
86
           return true
86
           return true

+ 1 - 1
app/models/group.rb

30
 
30
 
31
   # @return [Array<Activity>] the activities that haven't started yet.
31
   # @return [Array<Activity>] the activities that haven't started yet.
32
   def future_activities
32
   def future_activities
33
-    self.activities.where('start > ?', DateTime.now)
33
+    self.activities.where('start > ?', Time.now)
34
   end
34
   end
35
 
35
 
36
   # @return [Array<Activity>]
36
   # @return [Array<Activity>]

+ 1 - 1
db/seeds.rb

64
 
64
 
65
 Group.all.each do |g|
65
 Group.all.each do |g|
66
   10.times do
66
   10.times do
67
-    starttime = Faker::Time.between(DateTime.now, 1.years.since, :morning)
67
+    starttime = Faker::Time.between(Time.now, 1.years.since, :morning)
68
     endtime   = Faker::Time.between(1.hours.since(starttime), 1.days.since(starttime), :afternoon)
68
     endtime   = Faker::Time.between(1.hours.since(starttime), 1.days.since(starttime), :afternoon)
69
     deadline  = 5.days.ago(starttime)
69
     deadline  = 5.days.ago(starttime)
70
 
70