John Merlino
2012-Jan-01 17:54 UTC
Chronic parsing date range in console but not in application in rails 3
Hey all,
Chronic will parse a date range in console:
Chronic.parse(1/1/2011 - 1/1/2012, :guess => false)
=> 2012-01-01 12:00:00 -0500..2012-01-01 12:00:01 -0500
However, when I use logger to check if it''s parsing in application, it
is not:
logger.info "The value of history date is #{history_date}"
=>
The value of history date is 1/1/2011 - 1/1/2012
logger.info "The value of date range is
#{ Chronic.parse(history_date, :guess => false)}" => The value of
date
range is
See how it returns nil for second logger. I have no clue why it works
fine in console but not in application.
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.
John Merlino
2012-Jan-01 18:28 UTC
Re: Chronic parsing date range in console but not in application in rails 3
This is strange what happened here. Chronic parse was not able to
parse a string when it contained a range like this:
"1/1/2011 - 1/1/2012"
So in order to address this, i had to check for the "-" in the string:
if history_date.include? "-"
date_range Chronic.parse(Date.parse(history_date),
:guess => false)
else
date_range Chronic.parse(history_date, :guess =>
false)
end
Im open to better solutions.
thanks for response
On Jan 1, 12:54 pm, John Merlino <stoici...-YDxpq3io04c@public.gmane.org>
wrote:> Hey all,
>
> Chronic will parse a date range in console:
>
> Chronic.parse(1/1/2011 - 1/1/2012, :guess => false)
> => 2012-01-01 12:00:00 -0500..2012-01-01 12:00:01 -0500
>
> However, when I use logger to check if it''s parsing in
application, it
> is not:
>
> logger.info "The value of history date is
#{history_date}" =>
> The value of history date is 1/1/2011 - 1/1/2012
> logger.info "The value of date range is
> #{ Chronic.parse(history_date, :guess => false)}" => The value
of date
> range is
>
> See how it returns nil for second logger. I have no clue why it works
> fine in console but not in application.
>
> 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@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
Hassan Schroeder
2012-Jan-01 18:28 UTC
Re: Chronic parsing date range in console but not in application in rails 3
On Sun, Jan 1, 2012 at 9:54 AM, John Merlino <stoicism1-YDxpq3io04c@public.gmane.org> wrote:> Chronic will parse a date range in console:> However, when I use logger to check if it''s parsing in application, it > is not:Loading development environment (Rails 3.1.2) ruby-1.9.2-p290 :001 > result = Chronic.parse(1/1/2011 - 1/1/2012, :guess => false) => 2012-01-01 12:00:00 -0800..2012-01-01 12:00:01 -0800 ruby-1.9.2-p290 :002 > result = Chronic.parse(''1/1/2011 - 1/1/2012'', :guess => false) => nil ruby-1.9.2-p290 :003 > result = Chronic.parse(eval(''1/1/2011 - 1/1/2012''), :guess => false) => 2012-01-01 12:00:00 -0800..2012-01-01 12:00:01 -0800 ruby-1.9.2-p290 :004 > HTH! -- Hassan Schroeder ------------------------ hassan.schroeder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org http://about.me/hassanschroeder twitter: @hassan -- 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-01 18:49 UTC
Re: Chronic parsing date range in console but not in application in rails 3
It seems to parse the date wrong:
Chronic.parse(eval("1/1/2011 - 1/1/2012"), :guess => false)
=> 2012-01-01 12:00:00 -0500..2012-01-01 12:00:01 -0500
I specify two years, 2011 and 2012. And it returns a range of 2012.
On Jan 1, 1:28 pm, Hassan Schroeder
<hassan.schroe...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> On Sun, Jan 1, 2012 at 9:54 AM, John Merlino
<stoici...-YDxpq3io04c@public.gmane.org> wrote:
> > Chronic will parse a date range in console:
> > However, when I use logger to check if it''s parsing in
application, it
> > is not:
>
> Loading development environment (Rails 3.1.2)
> ruby-1.9.2-p290 :001 > result = Chronic.parse(1/1/2011 - 1/1/2012,
> :guess => false)
> => 2012-01-01 12:00:00 -0800..2012-01-01 12:00:01 -0800
> ruby-1.9.2-p290 :002 > result = Chronic.parse(''1/1/2011 -
1/1/2012'',
> :guess => false)
> => nil
> ruby-1.9.2-p290 :003 > result = Chronic.parse(eval(''1/1/2011 -
> 1/1/2012''), :guess => false)
> => 2012-01-01 12:00:00 -0800..2012-01-01 12:00:01 -0800
> ruby-1.9.2-p290 :004 >
>
> HTH!
> --
> Hassan Schroeder ------------------------
hassan.schroe...-Re5JQEeQqe80Tx58lXaADg@public.gmane.org://about.me/hassanschroeder
> twitter: @hassan
--
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.
Hassan Schroeder
2012-Jan-01 19:28 UTC
Re: Re: Chronic parsing date range in console but not in application in rails 3
On Sun, Jan 1, 2012 at 10:49 AM, John Merlino <stoicism1-YDxpq3io04c@public.gmane.org> wrote:> It seems to parse the date wrong: > > Chronic.parse(eval("1/1/2011 - 1/1/2012"), :guess => false) > => 2012-01-01 12:00:00 -0500..2012-01-01 12:00:01 -0500 > > I specify two years, 2011 and 2012. And it returns a range of 2012.Actually it returns a span of 1 second :-) I was assuming your original example worked, but it doesn''t. And I haven''t worked with Chronic much, so I''m not sure if that argument is even something it''s expected to handle. For example this works fine: ruby-1.9.2-p290 :007 > result = Chronic.parse(''last year'', :guess => false) => 2011-01-01 00:00:00 -0800..2012-01-01 00:00:00 -0800 ruby-1.9.2-p290 :008 > result.class => Chronic::Span ruby-1.9.2-p290 :009 > result.width => 31536000 while this obviously doesn''t: ruby-1.9.2-p290 :010 > result = Chronic.parse(1/1/2011 - 1/1/2012, :guess => false) => 2012-01-01 12:00:00 -0800..2012-01-01 12:00:01 -0800 ruby-1.9.2-p290 :011 > result.class => Chronic::Span ruby-1.9.2-p290 :012 > result.width => 1 ruby-1.9.2-p290 :013 > Time to jump into the gem source, I think :-) -- Hassan Schroeder ------------------------ hassan.schroeder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org http://about.me/hassanschroeder twitter: @hassan -- 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.
Apparently Analagous Threads
- undefined method `gsub!' for 2012-01-22 17:00:00 -0500..2012-01-23 00:00:00 -0500:Chronic::Span
- Stack Level Too Deep Error (can't seem to figure it out)
- dash symbol
- strange behavior with active relation any? method
- why doesn't an instance of Object get Class's new instance method?