John Merlino
2012-Jan-22 22:36 UTC
undefined method `gsub!'' for 2012-01-22 17:00:00 -0500..2012-01-23 00:00:00 -0500:Chronic::Span
Hey all, I am getting this error: NoMethodError (undefined method `gsub!'' for 2012-01-22 17:00:00 -0500..2012-01-23 00:00:00 -0500:Chronic::Span): in this code: date_range = Chronic.parse(the_date, :guess => false) reports.sum_distance_by_date(date_range).each do |d| u[:m] << d end def self.sum_distance_by_date(time) time = time ? Date.parse(time) : Date.today.to_s reports = find_by_sql(["SELECT date_trunc(''day'', time), SUM(distance * 0.000621371192) AS sum FROM reports WHERE \"time\" = ? GROUP BY date_trunc(''day'', time)", time]) reports end Basically Chronic returns a range back, and I just want to be able to use that result inside the find_by_sql query to get all records by that date. thanks for response -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Tom Meinlschmidt
2012-Jan-22 22:46 UTC
Re: undefined method `gsub!'' for 2012-01-22 17:00:00 -0500..2012-01-23 00:00:00 -0500:Chronic::Span
On Jan 22, 2012, at 23:36 , John Merlino wrote:> Hey all, > > I am getting this error: > > NoMethodError (undefined method `gsub!'' for 2012-01-22 17:00:00 > -0500..2012-01-23 00:00:00 -0500:Chronic::Span): > > > in this code: > > date_range = Chronic.parse(the_date, :guess => > false)try to add logger: logger.debug "*** ''#{date_range}'', class is #{date_range.class}"> > reports.sum_distance_by_date(date_range).each do |d| > u[:m] << d > end > > > def self.sum_distance_by_date(time) > > time = time ? Date.parse(time) : Date.today.to_s > reports = find_by_sql(["SELECT date_trunc(''day'', time), > SUM(distance * 0.000621371192) AS sum FROM reports WHERE \"time\" = ? > GROUP BY date_trunc(''day'', time)", time]) > reports > endbetter to write as def self.sum_distance_by(time = nil) time ||=Date.today reports = find_by_sql(...., time) end as Date.today is Date class, the same as Date.parse() tom> > Basically Chronic returns a range back, and I just want to be able to > use that result inside the find_by_sql query to get all records by > that date. > > thanks for response > > -- > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.-- ==============================================================================Tomas Meinlschmidt, MS {MCT, MCP+I, MCSE, AER}, NetApp Filer/NetCache www.meinlschmidt.com www.maxwellrender.cz www.lightgems.cz ============================================================================== -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
John Merlino
2012-Jan-23 15:21 UTC
Re: undefined method `gsub!'' for 2012-01-22 17:00:00 -0500..2012-01-23 00:00:00 -0500:Chronic::Span
thanks for response, Now I get a new issue: ActiveRecord::StatementInvalid in HomesController#map PGError: ERROR: time zone displacement out of range: "(2012-01-23 10:00:00 -0500..2012-01-24 00:00:00 -0500)" LINE 1: ....000621371192) AS sum FROM reports WHERE "time" ''(2012-01-... ^ : SELECT date_trunc(''day'', time), SUM(distance * 0.000621371192) AS sum FROM reports WHERE "time" = ''(2012-01-23 10:00:00 -0500..2012-01-24 00:00:00 -0500)'' GROUP BY date_trunc(''day'', time) with: def self.sum_distance_by(time=nil) time ||= Date.today reports = find_by_sql(["SELECT date_trunc(''day'', time), SUM(distance * 0.000621371192) AS sum FROM reports WHERE \"time\" = ? GROUP BY date_trunc(''day'', time)", String(time)]) #reports.each { |r| logger.info "sum: #{r.sum} date: #{r.date_trunc}"} reports end On Jan 22, 5:46 pm, Tom Meinlschmidt <to...-ooGa/4BNRfTT2+6r9I86XQ@public.gmane.org> wrote:> On Jan 22, 2012, at 23:36 , John Merlino wrote: > > > Hey all, > > > I am getting this error: > > > NoMethodError (undefined method `gsub!'' for 2012-01-22 17:00:00 > > -0500..2012-01-23 00:00:00 -0500:Chronic::Span): > > > in this code: > > > date_range = Chronic.parse(the_date, :guess => > > false) > > try to add logger: > logger.debug "*** ''#{date_range}'', class is #{date_range.class}" > > > > > reports.sum_distance_by_date(date_range).each do |d| > > u[:m] << d > > end > > > def self.sum_distance_by_date(time) > > > time = time ? Date.parse(time) : Date.today.to_s > > reports = find_by_sql(["SELECT date_trunc(''day'', time), > > SUM(distance * 0.000621371192) AS sum FROM reports WHERE \"time\" = ? > > GROUP BY date_trunc(''day'', time)", time]) > > reports > > end > > better to write as > > def self.sum_distance_by(time = nil) > time ||=Date.today > reports = find_by_sql(...., time) > end > > as Date.today is Date class, the same as Date.parse() > > tom > > > > > Basically Chronic returns a range back, and I just want to be able to > > use that result inside the find_by_sql query to get all records by > > that date. > > > thanks for response > > > -- > > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > For more options, visit this group athttp://groups.google.com/group/rubyonrails-talk?hl=en. > > -- > =========================================================================== ===> Tomas Meinlschmidt, MS {MCT, MCP+I, MCSE, AER}, NetApp Filer/NetCache > > www.meinlschmidt.com www.maxwellrender.cz www.lightgems.cz > =========================================================================== ===-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
John Merlino
2012-Jan-23 15:33 UTC
Re: undefined method `gsub!'' for 2012-01-22 17:00:00 -0500..2012-01-23 00:00:00 -0500:Chronic::Span
using Chronic.parse without false got rid of that issue On Jan 23, 10:21 am, John Merlino <stoici...-YDxpq3io04c@public.gmane.org> wrote:> thanks for response, > > Now I get a new issue: > > ActiveRecord::StatementInvalid in HomesController#map > > PGError: ERROR: time zone displacement out of range: "(2012-01-23 > 10:00:00 -0500..2012-01-24 00:00:00 -0500)" > LINE 1: ....000621371192) AS sum FROM reports WHERE "time" > ''(2012-01-... > ^ > : SELECT date_trunc(''day'', time), SUM(distance * 0.000621371192) AS > sum FROM reports WHERE "time" = ''(2012-01-23 10:00:00 > -0500..2012-01-24 00:00:00 -0500)'' GROUP BY date_trunc(''day'', time) > > with: > > def self.sum_distance_by(time=nil) > > time ||= Date.today > reports = find_by_sql(["SELECT date_trunc(''day'', time), > SUM(distance * 0.000621371192) AS sum FROM reports WHERE \"time\" = ? > GROUP BY date_trunc(''day'', time)", String(time)]) > #reports.each { |r| logger.info "sum: #{r.sum} date: > #{r.date_trunc}"} > reports > end > > On Jan 22, 5:46 pm, Tom Meinlschmidt <to...-ooGa/4BNRfTT2+6r9I86XQ@public.gmane.org> wrote: > > > > > > > > > On Jan 22, 2012, at 23:36 , John Merlino wrote: > > > > Hey all, > > > > I am getting this error: > > > > NoMethodError (undefined method `gsub!'' for 2012-01-22 17:00:00 > > > -0500..2012-01-23 00:00:00 -0500:Chronic::Span): > > > > in this code: > > > > date_range = Chronic.parse(the_date, :guess => > > > false) > > > try to add logger: > > logger.debug "*** ''#{date_range}'', class is #{date_range.class}" > > > > reports.sum_distance_by_date(date_range).each do |d| > > > u[:m] << d > > > end > > > > def self.sum_distance_by_date(time) > > > > time = time ? Date.parse(time) : Date.today.to_s > > > reports = find_by_sql(["SELECT date_trunc(''day'', time), > > > SUM(distance * 0.000621371192) AS sum FROM reports WHERE \"time\" = ? > > > GROUP BY date_trunc(''day'', time)", time]) > > > reports > > > end > > > better to write as > > > def self.sum_distance_by(time = nil) > > time ||=Date.today > > reports = find_by_sql(...., time) > > end > > > as Date.today is Date class, the same as Date.parse() > > > tom > > > > Basically Chronic returns a range back, and I just want to be able to > > > use that result inside the find_by_sql query to get all records by > > > that date. > > > > thanks for response > > > > -- > > > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > > > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh4Ykp1iOSErHA@public.gmane.orgm. > > > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > > For more options, visit this group athttp://groups.google.com/group/rubyonrails-talk?hl=en. > > > -- > > =========================================================================== ===> > Tomas Meinlschmidt, MS {MCT, MCP+I, MCSE, AER}, NetApp Filer/NetCache > > >www.meinlschmidt.com www.maxwellrender.cz www.lightgems.cz > > =========================================================================== ===-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Velimir L.
2012-Jan-23 21:42 UTC
Re: undefined method `gsub!'' for 2012-01-22 17:00:00 -0500..2012-01-23 00:00:00 -0500:Chronic::Span
You have to convert the input to string as: the_date.to_s Chronic.parse(the_date.to_s) -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.