From e14a5b2eaf62286805fec7a9295a4aa94fec5d4d Mon Sep 17 00:00:00 2001 From: Bertocq Date: Sun, 11 Jun 2017 10:40:12 +0200 Subject: [PATCH 1/2] Avoid using Date.today, better to use Date.current that takes timezone into account --- app/controllers/concerns/search.rb | 6 +++--- app/models/direct_message.rb | 2 +- app/views/management/proposals/print.html.erb | 2 +- lib/migrate_spending_proposals_to_investments.rb | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/controllers/concerns/search.rb b/app/controllers/concerns/search.rb index 922ad93cc..b4e9fac68 100644 --- a/app/controllers/concerns/search.rb +++ b/app/controllers/concerns/search.rb @@ -41,11 +41,11 @@ module Search end def search_finish_date - (params[:advanced_search][:date_max].to_date rescue Date.today) || Date.today + (params[:advanced_search][:date_max].to_date rescue Date.current) || Date.current end def search_date_range - [100.years.ago, search_start_date].max.beginning_of_day..[search_finish_date, Date.today].min.end_of_day + [100.years.ago, search_start_date].max.beginning_of_day..[search_finish_date, Date.current].min.end_of_day end def set_search_order @@ -54,4 +54,4 @@ module Search end end -end \ No newline at end of file +end diff --git a/app/models/direct_message.rb b/app/models/direct_message.rb index 476194aea..b36cca705 100644 --- a/app/models/direct_message.rb +++ b/app/models/direct_message.rb @@ -8,7 +8,7 @@ class DirectMessage < ActiveRecord::Base validates :receiver, presence: true validate :max_per_day - scope :today, lambda { where('DATE(created_at) = ?', Date.today) } + scope :today, lambda { where('DATE(created_at) = ?', Date.current) } def max_per_day return if errors.any? diff --git a/app/views/management/proposals/print.html.erb b/app/views/management/proposals/print.html.erb index 71220c74b..3314dc1e5 100644 --- a/app/views/management/proposals/print.html.erb +++ b/app/views/management/proposals/print.html.erb @@ -8,7 +8,7 @@ <%= image_tag "header_print_proposals.jpg", class: "for-print-only" %>
- <%= l Date.today, format: :long %> + <%= l Date.current, format: :long %>

<%= t("proposals.index.select_order_long") %> diff --git a/lib/migrate_spending_proposals_to_investments.rb b/lib/migrate_spending_proposals_to_investments.rb index 5db10e2bd..9ef2f096d 100644 --- a/lib/migrate_spending_proposals_to_investments.rb +++ b/lib/migrate_spending_proposals_to_investments.rb @@ -1,7 +1,7 @@ class MigrateSpendingProposalsToInvestments def import(sp) - budget = Budget.last || Budget.create!(name: Date.today.year.to_s, currency_symbol: "€") + budget = Budget.last || Budget.create!(name: Date.current.year.to_s, currency_symbol: "€") group = nil heading = nil From b79df113cdc92851e60f3001506a8bbad1828a66 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Sun, 11 Jun 2017 10:40:41 +0200 Subject: [PATCH 2/2] Switch all Time.curren.to_date for Date.current, same result but better syntax --- app/controllers/officing/residence_controller.rb | 2 +- app/models/poll/voter.rb | 2 +- lib/age.rb | 2 +- spec/factories.rb | 2 +- spec/features/admin/poll/booth_assigments_spec.rb | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/controllers/officing/residence_controller.rb b/app/controllers/officing/residence_controller.rb index 9f24d3a90..ef76162ea 100644 --- a/app/controllers/officing/residence_controller.rb +++ b/app/controllers/officing/residence_controller.rb @@ -26,7 +26,7 @@ class Officing::ResidenceController < Officing::BaseController @officer_assignments = current_user.poll_officer. officer_assignments. voting_days. - where(date: Time.current.to_date) + where(date: Date.current) end def validate_officer_assignment diff --git a/app/models/poll/voter.rb b/app/models/poll/voter.rb index 6da6b98b2..7236865c4 100644 --- a/app/models/poll/voter.rb +++ b/app/models/poll/voter.rb @@ -50,7 +50,7 @@ class Poll if dob.blank? nil else - now = Time.current.to_date + now = Date.current now.year - dob.year - (now.month > dob.month || (now.month == dob.month && now.day >= dob.day) ? 0 : 1) end end diff --git a/lib/age.rb b/lib/age.rb index cf619133d..1169b4f5d 100644 --- a/lib/age.rb +++ b/lib/age.rb @@ -1,5 +1,5 @@ module Age - def self.in_years(dob, now = Time.current.to_date) + def self.in_years(dob, now = Date.current) return nil if dob.blank? # reference: http://stackoverflow.com/questions/819263/get-persons-age-in-ruby#comment21200772_819263 now.year - dob.year - (now.month > dob.month || (now.month == dob.month && now.day >= dob.day) ? 0 : 1) diff --git a/spec/factories.rb b/spec/factories.rb index ed89ec154..bdd50c905 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -429,7 +429,7 @@ FactoryGirl.define do factory :poll_officer_assignment, class: 'Poll::OfficerAssignment' do association :officer, factory: :poll_officer association :booth_assignment, factory: :poll_booth_assignment - date Time.current.to_date + date Date.current trait :final do final true diff --git a/spec/features/admin/poll/booth_assigments_spec.rb b/spec/features/admin/poll/booth_assigments_spec.rb index 7a07eab82..ea2291e91 100644 --- a/spec/features/admin/poll/booth_assigments_spec.rb +++ b/spec/features/admin/poll/booth_assigments_spec.rb @@ -144,7 +144,7 @@ feature 'Admin booths assignments' do poll = create(:poll) booth = create(:poll_booth) booth_assignment = create(:poll_booth_assignment, poll: poll, booth: booth) - today = Time.current.to_date + today = Date.current officer_assignment = create(:poll_officer_assignment, booth_assignment: booth_assignment, date: today) recount = create(:poll_recount,