use Chronic gem to parse uploaded date data
This commit is contained in:
parent
484959298c
commit
860ba6f393
1
Gemfile
1
Gemfile
@ -30,6 +30,7 @@ gem 'rack-utf8_sanitizer'
|
|||||||
gem 'newrelic_rpm'
|
gem 'newrelic_rpm'
|
||||||
gem 'actionpack-xml_parser'
|
gem 'actionpack-xml_parser'
|
||||||
gem 'activeadmin', github: 'gregbell/active_admin'
|
gem 'activeadmin', github: 'gregbell/active_admin'
|
||||||
|
gem 'chronic'
|
||||||
|
|
||||||
# to use debugger
|
# to use debugger
|
||||||
# gem 'ruby-debug'
|
# gem 'ruby-debug'
|
||||||
|
@ -90,6 +90,7 @@ GEM
|
|||||||
net-sftp (>= 2.0.0)
|
net-sftp (>= 2.0.0)
|
||||||
net-ssh (>= 2.0.14)
|
net-ssh (>= 2.0.14)
|
||||||
net-ssh-gateway (>= 1.1.0)
|
net-ssh-gateway (>= 1.1.0)
|
||||||
|
chronic (0.10.2)
|
||||||
coffee-rails (4.0.1)
|
coffee-rails (4.0.1)
|
||||||
coffee-script (>= 2.2.0)
|
coffee-script (>= 2.2.0)
|
||||||
railties (>= 4.0.0, < 5.0)
|
railties (>= 4.0.0, < 5.0)
|
||||||
@ -345,6 +346,7 @@ DEPENDENCIES
|
|||||||
autotest
|
autotest
|
||||||
autotest-rails
|
autotest-rails
|
||||||
capistrano (~> 2.15.4)
|
capistrano (~> 2.15.4)
|
||||||
|
chronic
|
||||||
coffee-rails (~> 4.0)
|
coffee-rails (~> 4.0)
|
||||||
daemons
|
daemons
|
||||||
dalli
|
dalli
|
||||||
|
@ -372,6 +372,7 @@ class ChannelsController < ApplicationController
|
|||||||
|
|
||||||
# set time zone
|
# set time zone
|
||||||
Time.zone = params[:feed][:time_zone]
|
Time.zone = params[:feed][:time_zone]
|
||||||
|
Chronic.time_class = Time.zone
|
||||||
|
|
||||||
# read data from uploaded file
|
# read data from uploaded file
|
||||||
csv_array = CSV.parse(params[:upload][:csv].read)
|
csv_array = CSV.parse(params[:upload][:csv].read)
|
||||||
@ -409,8 +410,8 @@ class ChannelsController < ApplicationController
|
|||||||
|
|
||||||
# if 2 or more rows
|
# if 2 or more rows
|
||||||
if !csv_array[1].blank?
|
if !csv_array[1].blank?
|
||||||
date1 = parse_date ? Time.parse(csv_array[0][0]) : Time.at(csv_array[0][0])
|
date1 = Chronic.parse(csv_array[0][0]) if parse_date
|
||||||
date2 = parse_date ? Time.parse(csv_array[1][0]) : Time.at(csv_array[1][0])
|
date2 = Chronic.parse(csv_array[1][0]) if parse_date
|
||||||
|
|
||||||
# reverse the array if 1st date is larger than 2nd date
|
# reverse the array if 1st date is larger than 2nd date
|
||||||
csv_array = csv_array.reverse if date1 > date2
|
csv_array = csv_array.reverse if date1 > date2
|
||||||
@ -440,7 +441,7 @@ class ChannelsController < ApplicationController
|
|||||||
|
|
||||||
# set feed data
|
# set feed data
|
||||||
feed.channel_id = channel.id
|
feed.channel_id = channel.id
|
||||||
feed.created_at = parse_date ? Time.zone.parse(row[0]) : Time.zone.at(row[0].to_f)
|
feed.created_at = Chronic.parse(row[0]) if parse_date
|
||||||
feed.field1 = row[1]
|
feed.field1 = row[1]
|
||||||
feed.field2 = row[2]
|
feed.field2 = row[2]
|
||||||
feed.field3 = row[3]
|
feed.field3 = row[3]
|
||||||
|
@ -217,3 +217,4 @@ class WindowsController < ApplicationController
|
|||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user