Kaynağa Gözat

Avoid DateTime usage

Maarten van den Berg 6 yıl önce
ebeveyn
işleme
79cbb9ab11

+ 0 - 11
.rubocop.yml

@@ -70,17 +70,6 @@ Style/ConditionalAssignment:
70 70
     - 'app/mailers/participant_mailer.rb'
71 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 73
 # Offense count: 55
85 74
 Style/Documentation:
86 75
   Enabled: false

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

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

+ 2 - 1
app/controllers/authentication_controller.rb

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

+ 1 - 1
app/controllers/dashboard_controller.rb

@@ -5,7 +5,7 @@ class DashboardController < ApplicationController
5 5
     @upcoming = current_person
6 6
                 .participants
7 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 9
                 .order('activities.start ASC')
10 10
     @user_organized = @upcoming
11 11
                       .where(is_organizer: true)

+ 3 - 3
app/helpers/authentication_helper.rb

@@ -60,11 +60,11 @@ module AuthenticationHelper
60 60
   def logged_in?
61 61
     # Case 1: User has an active session inside the cookie.
62 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 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 69
       true
70 70
 
@@ -80,7 +80,7 @@ module AuthenticationHelper
80 80
 
81 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 84
            session_password == cookies.signed.permanent[:remember_token]
85 85
           log_in @user_session.user, false, false
86 86
           return true

+ 1 - 1
app/models/group.rb

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

+ 1 - 1
db/seeds.rb

@@ -64,7 +64,7 @@ Activity.create!(
64 64
 
65 65
 Group.all.each do |g|
66 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 68
     endtime   = Faker::Time.between(1.hours.since(starttime), 1.days.since(starttime), :afternoon)
69 69
     deadline  = 5.days.ago(starttime)
70 70