Merge pull request #2559 from consul/fix_date_new_to_use_timezone

Fix date parsing to take the TimeZone in account
This commit is contained in:
Alberto Calderón Queimadelos
2018-04-04 19:45:15 +02:00
committed by GitHub
6 changed files with 16 additions and 16 deletions

View File

@@ -29,7 +29,7 @@ class Officing::Residence
document_number: document_number,
document_type: document_type,
geozone: geozone,
date_of_birth: date_of_birth.to_datetime,
date_of_birth: date_of_birth.in_time_zone.to_datetime,
gender: gender,
residence_verified_at: Time.current,
verified_at: Time.current,

View File

@@ -32,7 +32,7 @@ class Verification::Residence
user.update(document_number: document_number,
document_type: document_type,
geozone: geozone,
date_of_birth: date_of_birth.to_datetime,
date_of_birth: date_of_birth.in_time_zone.to_datetime,
gender: gender,
residence_verified_at: Time.current)
end

View File

@@ -23,7 +23,7 @@ class CensusApi
str = data[:datos_habitante][:item][:fecha_nacimiento_string]
day, month, year = str.match(/(\d\d?)\D(\d\d?)\D(\d\d\d?\d?)/)[1..3]
return nil unless day.present? && month.present? && year.present?
Date.new(year.to_i, month.to_i, day.to_i)
Time.zone.local(year.to_i, month.to_i, day.to_i).to_date
end
def postal_code

View File

@@ -17,9 +17,9 @@ describe Admin::Api::StatsController do
context 'events present' do
before do
time_1 = DateTime.parse("2015-01-01").in_time_zone
time_2 = DateTime.parse("2015-01-02").in_time_zone
time_3 = DateTime.parse("2015-01-03").in_time_zone
time_1 = Time.zone.local(2015, 01, 01)
time_2 = Time.zone.local(2015, 01, 02)
time_3 = Time.zone.local(2015, 01, 03)
create :ahoy_event, name: 'foo', time: time_1
create :ahoy_event, name: 'foo', time: time_1
@@ -52,8 +52,8 @@ describe Admin::Api::StatsController do
context 'visits present' do
it 'returns visits formated for working with c3.js' do
time_1 = DateTime.parse("2015-01-01").in_time_zone
time_2 = DateTime.parse("2015-01-02").in_time_zone
time_1 = Time.zone.local(2015, 01, 01)
time_2 = Time.zone.local(2015, 01, 02)
create :visit, started_at: time_1
create :visit, started_at: time_1
@@ -71,8 +71,8 @@ describe Admin::Api::StatsController do
context 'visits and events present' do
it 'returns combined events and visits formated for working with c3.js' do
time_1 = DateTime.parse("2015-01-01").in_time_zone
time_2 = DateTime.parse("2015-01-02").in_time_zone
time_1 = Time.zone.local(2015, 01, 01)
time_2 = Time.zone.local(2015, 01, 02)
create :ahoy_event, name: 'foo', time: time_1
create :ahoy_event, name: 'foo', time: time_2
@@ -94,8 +94,8 @@ describe Admin::Api::StatsController do
context 'budget investments present' do
it 'returns budget investments formated for working with c3.js' do
time_1 = DateTime.parse("2017-04-01").in_time_zone
time_2 = DateTime.parse("2017-04-02").in_time_zone
time_1 = Time.zone.local(2017, 04, 01)
time_2 = Time.zone.local(2017, 04, 02)
budget_investment1 = create(:budget_investment, budget: @budget, created_at: time_1)
budget_investment2 = create(:budget_investment, budget: @budget, created_at: time_2)

View File

@@ -77,7 +77,7 @@ FactoryBot.define do
user
document_number
document_type "1"
date_of_birth Date.new(1980, 12, 31)
date_of_birth Time.zone.local(1980, 12, 31).to_date
postal_code "28013"
terms_of_service '1'

View File

@@ -3,9 +3,9 @@ require 'rails_helper'
describe Ahoy::DataSource do
describe '#build' do
before do
time_1 = DateTime.parse("2015-01-01").in_time_zone
time_2 = DateTime.parse("2015-01-02").in_time_zone
time_3 = DateTime.parse("2015-01-03").in_time_zone
time_1 = Time.zone.local(2015, 01, 01)
time_2 = Time.zone.local(2015, 01, 02)
time_3 = Time.zone.local(2015, 01, 03)
create :ahoy_event, name: 'foo', time: time_1
create :ahoy_event, name: 'foo', time: time_1