DateTime.parse => Time.zone.parse

This commit is contained in:
simon lehericey 2018-10-25 15:17:33 +02:00
parent 2238e5bd9f
commit f620e4aee2
11 changed files with 19 additions and 19 deletions

View file

@ -24,7 +24,7 @@ class ChampDecorator < Draper::Decorator
if type_champ == TypeDeChamp.type_champs.fetch(:date)
object.value
elsif type_champ == TypeDeChamp.type_champs.fetch(:datetime) && object.value != ' 00:00'
DateTime.parse(object.value, "%Y-%m-%d %H:%M").strftime("%Y-%m-%d")
Time.zone.parse(object.value, "%Y-%m-%d %H:%M").strftime("%Y-%m-%d")
end
end
end

View file

@ -30,7 +30,7 @@ class Champs::DatetimeChamp < Champ
nil
end
elsif /^\d{2}\/\d{2}\/\d{4}\s\d{2}:\d{2}$/.match?(value) # old browsers can send with dd/mm/yyyy hh:mm format
self.value = DateTime.parse(value, "%d/%m/%Y %H:%M").strftime("%Y-%m-%d %H:%M")
self.value = Time.zone.parse(value, "%d/%m/%Y %H:%M").strftime("%Y-%m-%d %H:%M")
elsif !(/^\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}$/.match?(value)) # a datetime not correctly formatted should not be stored
self.value = nil
end

View file

@ -1,4 +1,4 @@
- parsed_value = champ.value.present? ? DateTime.parse(champ.value) : Time.zone.now
- parsed_value = champ.value.present? ? Time.zone.parse(champ.value) : Time.zone.now
.datetime
= form.datetime_select(:value, selected: parsed_value, start_year: 1950, end_year: 2100, minute_step: 5)

View file

@ -12,7 +12,7 @@ namespace :'2018_01_18_clean_datetime_in_champs' do
# Match "dd/mm/YYYY HH:MM" => "YYYY-mm-dd HH:MM"
datetime_champs.select { |c| /^\d{2}\/\d{2}\/\d{4}\s\d{2}:\d{2}$/ =~ c.value }.each do |c|
formated_date = DateTime.parse(c.value, "%d/%m/%Y %H:%M").strftime("%Y-%m-%d %H:%M")
formated_date = Time.zone.parse(c.value, "%d/%m/%Y %H:%M").strftime("%Y-%m-%d %H:%M")
rake_puts "cleaning #{c.value} => #{formated_date}"
c.update_columns(value: formated_date)
end

View file

@ -104,7 +104,7 @@ namespace :cloudstorage do
Rake::Task['cloudstorage:init'].invoke
@cont.objects_detail.each { |object, details|
last_modified = DateTime.parse(details[:last_modified])
last_modified = Time.zone.parse(details[:last_modified])
@cont.delete_object(object) if last_modified.utc <= (Time.zone.now - 2.years).utc
}
end

View file

@ -82,7 +82,7 @@ describe FranceConnect::ParticulierController, type: :controller do
before { subject }
it { expect(stored_fci).to have_attributes(user_info.merge(birthdate: DateTime.parse(birthdate))) }
it { expect(stored_fci).to have_attributes(user_info.merge(birthdate: Time.zone.parse(birthdate))) }
end
it { is_expected.to redirect_to(root_path) }

View file

@ -23,7 +23,7 @@ feature 'The user' do
fill_in('text', with: 'super texte')
fill_in('textarea', with: 'super textarea')
fill_in('date', with: '12/12/2012')
select_date_and_time(DateTime.parse('06/01/1985 7h05'), form_id_for('datetime'))
select_date_and_time(Time.zone.parse('06/01/1985 7h05'), form_id_for('datetime'))
fill_in('number', with: '42')
check('checkbox')
choose('Madame')
@ -67,7 +67,7 @@ feature 'The user' do
expect(page).to have_field('text', with: 'super texte')
expect(page).to have_field('textarea', with: 'super textarea')
expect(page).to have_field('date', with: '2012-12-12')
check_date_and_time(DateTime.parse('06/01/1985 7:05'), form_id_for('datetime'))
check_date_and_time(Time.zone.parse('06/01/1985 7:05'), form_id_for('datetime'))
expect(page).to have_field('number', with: '42')
expect(page).to have_checked_field('checkbox')
expect(page).to have_checked_field('Madame')

View file

@ -479,9 +479,9 @@ describe Dossier do
end
context 'when they are a lot of advice' do
let!(:avis_1) { Avis.create(dossier: dossier, claimant: expert_1, gestionnaire: expert_2, confidentiel: false, created_at: DateTime.parse('10/01/2010')) }
let!(:avis_2) { Avis.create(dossier: dossier, claimant: expert_1, gestionnaire: expert_2, confidentiel: false, created_at: DateTime.parse('9/01/2010')) }
let!(:avis_3) { Avis.create(dossier: dossier, claimant: expert_1, gestionnaire: expert_2, confidentiel: false, created_at: DateTime.parse('11/01/2010')) }
let!(:avis_1) { Avis.create(dossier: dossier, claimant: expert_1, gestionnaire: expert_2, confidentiel: false, created_at: Time.zone.parse('10/01/2010')) }
let!(:avis_2) { Avis.create(dossier: dossier, claimant: expert_1, gestionnaire: expert_2, confidentiel: false, created_at: Time.zone.parse('9/01/2010')) }
let!(:avis_3) { Avis.create(dossier: dossier, claimant: expert_1, gestionnaire: expert_2, confidentiel: false, created_at: Time.zone.parse('11/01/2010')) }
it { expect(dossier.avis_for(gestionnaire)).to match([avis_2, avis_1, avis_3]) }
it { expect(dossier.avis_for(expert_1)).to match([avis_2, avis_1, avis_3]) }
@ -566,9 +566,9 @@ describe Dossier do
describe '.downloadable_sorted' do
let(:procedure) { create(:procedure) }
let!(:dossier) { create(:dossier, :with_entreprise, procedure: procedure, state: Dossier.states.fetch(:brouillon)) }
let!(:dossier2) { create(:dossier, :with_entreprise, procedure: procedure, state: Dossier.states.fetch(:en_construction), en_construction_at: DateTime.parse('03/01/2010')) }
let!(:dossier3) { create(:dossier, :with_entreprise, procedure: procedure, state: Dossier.states.fetch(:en_instruction), en_construction_at: DateTime.parse('01/01/2010')) }
let!(:dossier4) { create(:dossier, :with_entreprise, procedure: procedure, state: Dossier.states.fetch(:en_instruction), archived: true, en_construction_at: DateTime.parse('02/01/2010')) }
let!(:dossier2) { create(:dossier, :with_entreprise, procedure: procedure, state: Dossier.states.fetch(:en_construction), en_construction_at: Time.zone.parse('03/01/2010')) }
let!(:dossier3) { create(:dossier, :with_entreprise, procedure: procedure, state: Dossier.states.fetch(:en_instruction), en_construction_at: Time.zone.parse('01/01/2010')) }
let!(:dossier4) { create(:dossier, :with_entreprise, procedure: procedure, state: Dossier.states.fetch(:en_instruction), archived: true, en_construction_at: Time.zone.parse('02/01/2010')) }
subject { procedure.dossiers.downloadable_sorted }
@ -734,7 +734,7 @@ describe Dossier do
describe 'updated_at' do
let!(:dossier) { create(:dossier) }
let(:modif_date) { DateTime.parse('01/01/2100') }
let(:modif_date) { Time.zone.parse('01/01/2100') }
before { Timecop.freeze(modif_date) }
after { Timecop.return }
@ -985,7 +985,7 @@ describe Dossier do
let(:young_dossier) { create(:dossier, :en_instruction, en_instruction_at: Time.zone.now, procedure: procedure) }
let(:just_expired_dossier) { create(:dossier, :en_instruction, en_instruction_at: 6.months.ago, procedure: procedure) }
let(:long_expired_dossier) { create(:dossier, :en_instruction, en_instruction_at: 1.year.ago, procedure: procedure) }
let(:modif_date) { DateTime.parse('01/01/2100') }
let(:modif_date) { Time.zone.parse('01/01/2100') }
before { Timecop.freeze(modif_date) }
after { Timecop.return }

View file

@ -376,7 +376,7 @@ describe Gestionnaire, type: :model do
describe '#mark_tab_as_seen' do
let!(:dossier) { create(:dossier, :followed, state: Dossier.states.fetch(:en_construction)) }
let(:gestionnaire) { dossier.follows.first.gestionnaire }
let(:freeze_date) { DateTime.parse('12/12/2012') }
let(:freeze_date) { Time.zone.parse('12/12/2012') }
context 'when demande is acknowledged' do
let(:follow) { gestionnaire.follows.find_by(dossier: dossier) }

View file

@ -716,7 +716,7 @@ describe Procedure do
context 'which is termine' do
before do
dossier.accepte!
processed_date = DateTime.parse('12/12/2012')
processed_date = Time.zone.parse('12/12/2012')
instruction_date = processed_date - 1.day
dossier.update(en_instruction_at: instruction_date, processed_at: processed_date)
end

View file

@ -33,7 +33,7 @@ describe FranceConnectService do
expect(subject).to have_attributes({
given_name: given_name,
family_name: family_name,
birthdate: DateTime.parse(birthdate),
birthdate: Time.zone.parse(birthdate),
birthplace: birthplace,
gender: gender,
email_france_connect: email,