From 9de9a1fd719f057ef482b45db010a33d88995bab Mon Sep 17 00:00:00 2001 From: maatinito <15379878+maatinito@users.noreply.github.com> Date: Mon, 25 Nov 2019 13:39:42 +0000 Subject: [PATCH] Use time.zone functions instead of server time functions (Time.zone.today vs Date.today) --- app/controllers/stats_controller.rb | 4 ++-- app/helpers/commentaire_helper.rb | 2 +- app/lib/helpscout/user_conversations_adapter.rb | 2 +- app/models/champs/date_champ.rb | 6 +++--- .../france_connect/particulier_controller_spec.rb | 2 +- spec/services/bill_signature_service_spec.rb | 2 +- spec/services/france_connect_service_spec.rb | 2 +- 7 files changed, 10 insertions(+), 10 deletions(-) diff --git a/app/controllers/stats_controller.rb b/app/controllers/stats_controller.rb index 89f3e211f..5d23ead64 100644 --- a/app/controllers/stats_controller.rb +++ b/app/controllers/stats_controller.rb @@ -163,8 +163,8 @@ class StatsController < ApplicationController def contact_percentage number_of_months = 13 - from = Date.today.prev_month(number_of_months) - to = Date.today.prev_month + from = Time.zone.today.prev_month(number_of_months) + to = Time.zone.today.prev_month adapter = Helpscout::UserConversationsAdapter.new(from, to) if !adapter.can_fetch_reports? diff --git a/app/helpers/commentaire_helper.rb b/app/helpers/commentaire_helper.rb index a92b48b3c..aae8dc85d 100644 --- a/app/helpers/commentaire_helper.rb +++ b/app/helpers/commentaire_helper.rb @@ -18,7 +18,7 @@ module CommentaireHelper end def commentaire_date(commentaire) - is_current_year = (commentaire.created_at.year == Date.current.year) + is_current_year = (commentaire.created_at.year == Time.zone.today.year) template = is_current_year ? :message_date : :message_date_with_year I18n.l(commentaire.created_at, format: template) end diff --git a/app/lib/helpscout/user_conversations_adapter.rb b/app/lib/helpscout/user_conversations_adapter.rb index ced3a1b66..12ed81dc1 100644 --- a/app/lib/helpscout/user_conversations_adapter.rb +++ b/app/lib/helpscout/user_conversations_adapter.rb @@ -35,7 +35,7 @@ class Helpscout::UserConversationsAdapter end def fetch_productivity_report(year, month) - if year == Date.today.year && month == Date.today.month + if year == Time.zone.today.year && month == Time.zone.today.month raise ArgumentError, 'The report for the current month will change in the future, and cannot be cached.' end diff --git a/app/models/champs/date_champ.rb b/app/models/champs/date_champ.rb index 309091603..71e7082bf 100644 --- a/app/models/champs/date_champ.rb +++ b/app/models/champs/date_champ.rb @@ -6,11 +6,11 @@ class Champs::DateChamp < Champ end def to_s - value.present? ? I18n.l(Date.parse(value)) : "" + value.present? ? I18n.l(Time.zone.parse(value), format: '%d %B %Y') : "" end def for_tag - value.present? ? I18n.l(Date.parse(value)) : "" + value.present? ? I18n.l(Time.zone.parse(value), format: '%d %B %Y') : "" end private @@ -18,7 +18,7 @@ class Champs::DateChamp < Champ def format_before_save self.value = begin - Date.parse(value).iso8601 + Time.zone.parse(value).to_date.iso8601 rescue nil end diff --git a/spec/controllers/france_connect/particulier_controller_spec.rb b/spec/controllers/france_connect/particulier_controller_spec.rb index 4e1f1f66b..d718a65ff 100644 --- a/spec/controllers/france_connect/particulier_controller_spec.rb +++ b/spec/controllers/france_connect/particulier_controller_spec.rb @@ -107,7 +107,7 @@ describe FranceConnect::ParticulierController, type: :controller do before { subject } - it { expect(stored_fci).to have_attributes(user_info.merge(birthdate: Date.parse(birthdate))) } + it { expect(stored_fci).to have_attributes(user_info.merge(birthdate: Time.zone.parse(birthdate).to_datetime)) } end it { is_expected.to redirect_to(root_path) } diff --git a/spec/services/bill_signature_service_spec.rb b/spec/services/bill_signature_service_spec.rb index 2a88478df..209973c4c 100644 --- a/spec/services/bill_signature_service_spec.rb +++ b/spec/services/bill_signature_service_spec.rb @@ -4,7 +4,7 @@ describe BillSignatureService do describe ".grouped_unsigned_operation_until" do subject { BillSignatureService.grouped_unsigned_operation_until(date).length } - let(:date) { Date.today } + let(:date) { Time.zone.today } context "when operations of several days need to be signed" do before do diff --git a/spec/services/france_connect_service_spec.rb b/spec/services/france_connect_service_spec.rb index fb6ba85a2..561c0740d 100644 --- a/spec/services/france_connect_service_spec.rb +++ b/spec/services/france_connect_service_spec.rb @@ -33,7 +33,7 @@ describe FranceConnectService do expect(subject).to have_attributes({ given_name: given_name, family_name: family_name, - birthdate: Date.parse(birthdate), + birthdate: Time.zone.parse(birthdate).to_date, birthplace: birthplace, gender: gender, email_france_connect: email,