DateTime.new => Time.zone.local

This commit is contained in:
simon lehericey 2018-10-25 15:19:29 +02:00
parent 4b25d16f5a
commit e684cec516
9 changed files with 41 additions and 41 deletions

View file

@ -25,7 +25,7 @@ class Champs::DatetimeChamp < Champ
begin begin
hash_date = YAML.safe_load(value.gsub('=>', ': ')) hash_date = YAML.safe_load(value.gsub('=>', ': '))
year, month, day, hour, minute = hash_date.values_at(1,2,3,4,5) year, month, day, hour, minute = hash_date.values_at(1,2,3,4,5)
DateTime.new(year, month, day, hour, minute).strftime("%d/%m/%Y %H:%M") Time.zone.local(year, month, day, hour, minute).strftime("%d/%m/%Y %H:%M")
rescue rescue
nil nil
end end

View file

@ -8,8 +8,8 @@ namespace :'2018_03_08_send_missing_accuse_reception' do
# `bug_date` and `fix_date` were determined empirically by looking at the release times, # `bug_date` and `fix_date` were determined empirically by looking at the release times,
# and checking for dossiers with a missing accusé de réception. # and checking for dossiers with a missing accusé de réception.
bug_date = DateTime.new(2018, 3, 1, 9, 50) bug_date = Time.zone.local(2018, 3, 1, 9, 50)
fix_date = DateTime.new(2018, 3, 5, 18, 40) fix_date = Time.zone.local(2018, 3, 5, 18, 40)
# Only send the accusé for dossiers that are still en construction. # Only send the accusé for dossiers that are still en construction.
# For dossiers that have moved on, other mails have been sent since, and a late # For dossiers that have moved on, other mails have been sent since, and a late

View file

@ -7,7 +7,7 @@ namespace :'2018_05_30_missed_ar_messages' do
end end
def create_commentaires(date_name, template_name, dossiers = Dossier) def create_commentaires(date_name, template_name, dossiers = Dossier)
error_range = DateTime.new(2018, 05, 28, 13, 33)..DateTime.new(2018, 05, 30, 15, 39) error_range = Time.zone.local(2018, 05, 28, 13, 33)..Time.zone.local(2018, 05, 30, 15, 39)
dossiers.includes(:procedure).where(date_name => error_range).find_each(batch_size: 100) do |dossier| dossiers.includes(:procedure).where(date_name => error_range).find_each(batch_size: 100) do |dossier|
print "#{dossier.id}\n" print "#{dossier.id}\n"

View file

@ -7,7 +7,7 @@ namespace :'2018_09_12_fix_templates' do
end end
# 16:15 in Paris -> 14:15 UTC # 16:15 in Paris -> 14:15 UTC
DEPLOY_DATETIME = DateTime.new(2018, 9, 5, 14, 15, 0) DEPLOY_DATETIME = Time.zone.local(2018, 9, 5, 14, 15, 0)
def find_dossiers_with_sent_and_invalid_attestations def find_dossiers_with_sent_and_invalid_attestations
invalid_procedures_ids = AttestationTemplate invalid_procedures_ids = AttestationTemplate

View file

@ -8,7 +8,7 @@ RSpec.describe Administrateurs::ActivateBeforeExpirationJob, type: :job do
subject { Administrateurs::ActivateBeforeExpirationJob.perform_now } subject { Administrateurs::ActivateBeforeExpirationJob.perform_now }
before do before do
Timecop.freeze(DateTime.new(2018, 03, 20)) Timecop.freeze(Time.zone.local(2018, 03, 20))
administrateur.reload administrateur.reload
allow(AdministrateurMailer).to receive(:activate_before_expiration).and_return(mailer_double) allow(AdministrateurMailer).to receive(:activate_before_expiration).and_return(mailer_double)
end end
@ -25,7 +25,7 @@ RSpec.describe Administrateurs::ActivateBeforeExpirationJob, type: :job do
context "created a long time ago" do context "created a long time ago" do
before do before do
administrateur.update_columns(created_at: DateTime.new(2018, 03, 10)) administrateur.update_columns(created_at: Time.zone.local(2018, 03, 10))
subject subject
end end
@ -34,7 +34,7 @@ RSpec.describe Administrateurs::ActivateBeforeExpirationJob, type: :job do
context "created 3 days ago" do context "created 3 days ago" do
before do before do
administrateur.update_columns(created_at: DateTime.new(2018, 03, 17, 20, 00)) administrateur.update_columns(created_at: Time.zone.local(2018, 03, 17, 20, 00))
subject subject
end end
@ -52,7 +52,7 @@ RSpec.describe Administrateurs::ActivateBeforeExpirationJob, type: :job do
context "created a long time ago" do context "created a long time ago" do
before do before do
administrateur.update_columns(created_at: DateTime.new(2018, 03, 10)) administrateur.update_columns(created_at: Time.zone.local(2018, 03, 10))
subject subject
end end
@ -61,7 +61,7 @@ RSpec.describe Administrateurs::ActivateBeforeExpirationJob, type: :job do
context "created 2 days ago" do context "created 2 days ago" do
before do before do
administrateur.update_columns(created_at: DateTime.new(2018, 03, 18, 20, 00)) administrateur.update_columns(created_at: Time.zone.local(2018, 03, 18, 20, 00))
subject subject
end end

View file

@ -187,9 +187,9 @@ describe TagsSubstitutionConcern, type: :model do
context "when using a date tag" do context "when using a date tag" do
before do before do
dossier.en_construction_at = DateTime.new(2001, 2, 3) dossier.en_construction_at = Time.zone.local(2001, 2, 3)
dossier.en_instruction_at = DateTime.new(2004, 5, 6) dossier.en_instruction_at = Time.zone.local(2004, 5, 6)
dossier.processed_at = DateTime.new(2007, 8, 9) dossier.processed_at = Time.zone.local(2007, 8, 9)
end end
context "with date de dépôt" do context "with date de dépôt" do

View file

@ -138,7 +138,7 @@ describe Gestionnaire, type: :model do
describe 'last_week_overview' do describe 'last_week_overview' do
let!(:gestionnaire2) { create(:gestionnaire) } let!(:gestionnaire2) { create(:gestionnaire) }
subject { gestionnaire2.last_week_overview } subject { gestionnaire2.last_week_overview }
let(:friday) { DateTime.new(2017, 5, 12) } let(:friday) { Time.zone.local(2017, 5, 12) }
let(:monday) { Time.zone.now.beginning_of_week } let(:monday) { Time.zone.now.beginning_of_week }
before { Timecop.freeze(friday) } before { Timecop.freeze(friday) }

View file

@ -2,8 +2,8 @@ require 'spec_helper'
describe ProcedureOverview, type: :model do describe ProcedureOverview, type: :model do
let(:procedure) { create(:procedure, libelle: 'libelle') } let(:procedure) { create(:procedure, libelle: 'libelle') }
let(:friday) { DateTime.new(2017, 5, 12) } # vendredi 12 mai 2017, de la semaine du 8 mai let(:friday) { Time.zone.local(2017, 5, 12) } # vendredi 12 mai 2017, de la semaine du 8 mai
let(:monday) { DateTime.new(2017, 5, 8) } let(:monday) { Time.zone.local(2017, 5, 8) }
before { Timecop.freeze(friday) } before { Timecop.freeze(friday) }
after { Timecop.return } after { Timecop.return }

View file

@ -133,25 +133,25 @@ describe ProcedurePresentation do
context 'for created_at column' do context 'for created_at column' do
let(:column) { 'created_at' } let(:column) { 'created_at' }
let(:dossier) { Timecop.freeze(DateTime.new(1992, 3, 22)) { create(:dossier, procedure: procedure) } } let(:dossier) { Timecop.freeze(Time.zone.local(1992, 3, 22)) { create(:dossier, procedure: procedure) } }
it { is_expected.to eq(DateTime.new(1992, 3, 22)) } it { is_expected.to eq(Time.zone.local(1992, 3, 22)) }
end end
context 'for en_construction_at column' do context 'for en_construction_at column' do
let(:column) { 'en_construction_at' } let(:column) { 'en_construction_at' }
let(:dossier) { create(:dossier, :en_construction, procedure: procedure, en_construction_at: DateTime.new(2018, 10, 17)) } let(:dossier) { create(:dossier, :en_construction, procedure: procedure, en_construction_at: Time.zone.local(2018, 10, 17)) }
it { is_expected.to eq(DateTime.new(2018, 10, 17)) } it { is_expected.to eq(Time.zone.local(2018, 10, 17)) }
end end
context 'for updated_at column' do context 'for updated_at column' do
let(:column) { 'updated_at' } let(:column) { 'updated_at' }
let(:dossier) { create(:dossier, procedure: procedure) } let(:dossier) { create(:dossier, procedure: procedure) }
before { dossier.touch(time: DateTime.new(2018, 9, 25)) } before { dossier.touch(time: Time.zone.local(2018, 9, 25)) }
it { is_expected.to eq(DateTime.new(2018, 9, 25)) } it { is_expected.to eq(Time.zone.local(2018, 9, 25)) }
end end
end end
@ -236,11 +236,11 @@ describe ProcedurePresentation do
let!(:older_dossier) { create(:dossier, :en_construction, procedure: procedure) } let!(:older_dossier) { create(:dossier, :en_construction, procedure: procedure) }
before do before do
notified_dossier.champs.first.touch(time: DateTime.new(2018, 9, 20)) notified_dossier.champs.first.touch(time: Time.zone.local(2018, 9, 20))
create(:follow, gestionnaire: gestionnaire, dossier: notified_dossier, demande_seen_at: DateTime.new(2018, 9, 10)) create(:follow, gestionnaire: gestionnaire, dossier: notified_dossier, demande_seen_at: Time.zone.local(2018, 9, 10))
notified_dossier.touch(time: DateTime.new(2018, 9, 20)) notified_dossier.touch(time: Time.zone.local(2018, 9, 20))
recent_dossier.touch(time: DateTime.new(2018, 9, 25)) recent_dossier.touch(time: Time.zone.local(2018, 9, 25))
older_dossier.touch(time: DateTime.new(2018, 5, 13)) older_dossier.touch(time: Time.zone.local(2018, 5, 13))
end end
context 'in ascending order' do context 'in ascending order' do
@ -269,16 +269,16 @@ describe ProcedurePresentation do
context 'for created_at column' do context 'for created_at column' do
let(:column) { 'created_at' } let(:column) { 'created_at' }
let!(:recent_dossier) { Timecop.freeze(DateTime.new(2018, 10, 17)) { create(:dossier, procedure: procedure) } } let!(:recent_dossier) { Timecop.freeze(Time.zone.local(2018, 10, 17)) { create(:dossier, procedure: procedure) } }
let!(:older_dossier) { Timecop.freeze(DateTime.new(2003, 11, 11)) { create(:dossier, procedure: procedure) } } let!(:older_dossier) { Timecop.freeze(Time.zone.local(2003, 11, 11)) { create(:dossier, procedure: procedure) } }
it { is_expected.to eq([older_dossier, recent_dossier].map(&:id)) } it { is_expected.to eq([older_dossier, recent_dossier].map(&:id)) }
end end
context 'for en_construction_at column' do context 'for en_construction_at column' do
let(:column) { 'en_construction_at' } let(:column) { 'en_construction_at' }
let!(:recent_dossier) { create(:dossier, :en_construction, procedure: procedure, en_construction_at: DateTime.new(2018, 10, 17)) } let!(:recent_dossier) { create(:dossier, :en_construction, procedure: procedure, en_construction_at: Time.zone.local(2018, 10, 17)) }
let!(:older_dossier) { create(:dossier, :en_construction, procedure: procedure, en_construction_at: DateTime.new(2013, 1, 1)) } let!(:older_dossier) { create(:dossier, :en_construction, procedure: procedure, en_construction_at: Time.zone.local(2013, 1, 1)) }
it { is_expected.to eq([older_dossier, recent_dossier].map(&:id)) } it { is_expected.to eq([older_dossier, recent_dossier].map(&:id)) }
end end
@ -289,8 +289,8 @@ describe ProcedurePresentation do
let(:older_dossier) { create(:dossier, procedure: procedure) } let(:older_dossier) { create(:dossier, procedure: procedure) }
before do before do
recent_dossier.touch(time: DateTime.new(2018, 9, 25)) recent_dossier.touch(time: Time.zone.local(2018, 9, 25))
older_dossier.touch(time: DateTime.new(2018, 5, 13)) older_dossier.touch(time: Time.zone.local(2018, 5, 13))
end end
it { is_expected.to eq([older_dossier, recent_dossier].map(&:id)) } it { is_expected.to eq([older_dossier, recent_dossier].map(&:id)) }
@ -377,16 +377,16 @@ describe ProcedurePresentation do
context 'for self table' do context 'for self table' do
context 'for created_at column' do context 'for created_at column' do
let!(:kept_dossier) { create(:dossier, procedure: procedure, created_at: DateTime.new(2018, 9, 18, 14, 28)) } let!(:kept_dossier) { create(:dossier, procedure: procedure, created_at: Time.zone.local(2018, 9, 18, 14, 28)) }
let!(:discarded_dossier) { create(:dossier, procedure: procedure, created_at: DateTime.new(2018, 9, 17, 23, 59)) } let!(:discarded_dossier) { create(:dossier, procedure: procedure, created_at: Time.zone.local(2018, 9, 17, 23, 59)) }
let(:filter) { [{ 'table' => 'self', 'column' => 'created_at', 'value' => '18/9/2018' }] } let(:filter) { [{ 'table' => 'self', 'column' => 'created_at', 'value' => '18/9/2018' }] }
it { is_expected.to contain_exactly(kept_dossier.id) } it { is_expected.to contain_exactly(kept_dossier.id) }
end end
context 'for en_construction_at column' do context 'for en_construction_at column' do
let!(:kept_dossier) { create(:dossier, :en_construction, procedure: procedure, en_construction_at: DateTime.new(2018, 10, 17)) } let!(:kept_dossier) { create(:dossier, :en_construction, procedure: procedure, en_construction_at: Time.zone.local(2018, 10, 17)) }
let!(:discarded_dossier) { create(:dossier, :en_construction, procedure: procedure, en_construction_at: DateTime.new(2013, 1, 1)) } let!(:discarded_dossier) { create(:dossier, :en_construction, procedure: procedure, en_construction_at: Time.zone.local(2013, 1, 1)) }
let(:filter) { [{ 'table' => 'self', 'column' => 'en_construction_at', 'value' => '17/10/2018' }] } let(:filter) { [{ 'table' => 'self', 'column' => 'en_construction_at', 'value' => '17/10/2018' }] }
it { is_expected.to contain_exactly(kept_dossier.id) } it { is_expected.to contain_exactly(kept_dossier.id) }
@ -398,8 +398,8 @@ describe ProcedurePresentation do
let(:filter) { [{ 'table' => 'self', 'column' => 'updated_at', 'value' => '18/9/2018' }] } let(:filter) { [{ 'table' => 'self', 'column' => 'updated_at', 'value' => '18/9/2018' }] }
before do before do
kept_dossier.touch(time: DateTime.new(2018, 9, 18, 14, 28)) kept_dossier.touch(time: Time.zone.local(2018, 9, 18, 14, 28))
discarded_dossier.touch(time: DateTime.new(2018, 9, 17, 23, 59)) discarded_dossier.touch(time: Time.zone.local(2018, 9, 17, 23, 59))
end end
it { is_expected.to contain_exactly(kept_dossier.id) } it { is_expected.to contain_exactly(kept_dossier.id) }
@ -436,8 +436,8 @@ describe ProcedurePresentation do
context 'for etablissement table' do context 'for etablissement table' do
context 'for entreprise_date_creation column' do context 'for entreprise_date_creation column' do
let!(:kept_dossier) { create(:dossier, procedure: procedure, etablissement: create(:etablissement, entreprise_date_creation: DateTime.new(2018, 6, 21))) } let!(:kept_dossier) { create(:dossier, procedure: procedure, etablissement: create(:etablissement, entreprise_date_creation: Time.zone.local(2018, 6, 21))) }
let!(:discarded_dossier) { create(:dossier, procedure: procedure, etablissement: create(:etablissement, entreprise_date_creation: DateTime.new(2008, 6, 21))) } let!(:discarded_dossier) { create(:dossier, procedure: procedure, etablissement: create(:etablissement, entreprise_date_creation: Time.zone.local(2008, 6, 21))) }
let(:filter) { [{ 'table' => 'etablissement', 'column' => 'entreprise_date_creation', 'value' => '21/6/2018' }] } let(:filter) { [{ 'table' => 'etablissement', 'column' => 'entreprise_date_creation', 'value' => '21/6/2018' }] }
it { is_expected.to contain_exactly(kept_dossier.id) } it { is_expected.to contain_exactly(kept_dossier.id) }