|
|
|
I'm not sure what's actually correct here. Note that Ruby doesn't blow up on this particular parsed date, but it also doesn't handle it right:
~/NetBeansProjects/jruby $ cat test.rb
require 'parsedate'
res = ParseDate.parsedate('Wed, 10 Oct 2007 11:55:23 -0700')
p Time.gm(*res)
~/NetBeansProjects/jruby $ ruby test.rb
Wed Oct 10 11:55:23 UTC 2007
Note that the output timezone is still UTC, rather than -0700 or CST or whatever. According to the JRuby implementation of Time.gm, it's expecting to get a microsecond value where the "-0700" appears in the parsed array. Here's the rdoc for Time.gm. Note that there's no form that takes the sequence of values parsedate seems to produce, and that the only ones that accept timezone also take weekday, year day, and a DST flag: --------------------------------------------------------------- Time::gm
Time.utc( year [, month, day, hour, min, sec, usec] ) => time
Time.utc( sec, min, hour, day, month, year, wday, yday, isdst, tz
) => time
Time.gm( year [, month, day, hour, min, sec, usec] ) => time
Time.gm( sec, min, hour, day, month, year, wday, yday, isdst, tz
) => time
------------------------------------------------------------------------
Creates a time based on given values, interpreted as UTC (GMT). The
year must be specified. Other values default to the minimum value
for that field (and may be +nil+ or omitted). Months may be
specified by numbers from 1 to 12, or by the three-letter English
month names. Hours are specified on a 24-hour clock (0..23). Raises
an +ArgumentError+ if any values are out of range. Will also accept
ten arguments in the order output by +Time#to_a+.
Time.utc(2000,"jan",1,20,15,1) #=> Sat Jan 01 20:15:01 UTC 2000
Time.gm(2000,"jan",1,20,15,1) #=> Sat Jan 01 20:15:01 UTC 2000
So perhaps Ruby is just ignoring bogus input for some parameters? I've checked with MRI, and it handles an 8 argument form of 'utc' by ignoring the last two arguments
(timezone and weekday). This is probably to be compatible with parsedate, which returns an 8-element array. MRI also allows negative usec values by overflowing. The attached patch handles both the 8 argument case and the negative usec case.
MRI doesn't allow usec values that don't fit in a signed int. Should we follow MRI here? I used the long min value since we already use the long max value. Yes, we should try to mimic MRI here, especially since it's a fairly trivial feature to mimic. It seems like a small thing, but apps break for the weirdest reasons sometimes.
I applied the patch to trunk, since all the tests pass. If you have additional patches, please attach them here.
Ok, the second patch limits usec values to signed int like MRI.
Fixed in commit 4918 on trunk and 4919 on 1.0 branch (patch by Kjetil Ødegaard)
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
$ jirb
;irb(main):001:0> require 'parsedate'
=> true
irb(main):002:0> res = ParseDate.parsedate('Wed, 10 Oct 2007 11:55:23 -0700')
=> [2007, 10, 10, 11, 55, 23, "-0700", 3]
irb(main):003:0> date = Time.gm(*res)
ArgumentError: Argument out of range.
from /usr/local/jruby-1.0.1/lib/ruby/1.8/irb/workspace.rb:52:in `eval'
from /usr/local/jruby-1.0.1/lib/ruby/1.8/irb/workspace.rb:81:in `evaluate'
from /usr/local/jruby-1.0.1/lib/ruby/1.8/irb/context.rb:219:in `evaluate'
from /usr/local/jruby-1.0.1/lib/ruby/1.8/irb.rb:150:in `eval_input'
from /usr/local/jruby-1.0.1/lib/ruby/1.8/irb.rb:70:in `signal_status'
from /usr/local/jruby-1.0.1/lib/ruby/1.8/irb.rb:147:in `eval_input'
from /usr/local/jruby-1.0.1/lib/ruby/1.8/irb.rb:70:in `each_top_level_statement'
from /usr/local/jruby-1.0.1/lib/ruby/1.8/irb.rb:146:in `loop'
from /usr/local/jruby-1.0.1/lib/ruby/1.8/irb/ruby-lex.rb:230:in `each_top_level_statement'
from /usr/local/jruby-1.0.1/lib/ruby/1.8/irb.rb:146:in `catch'
from /usr/local/jruby-1.0.1/lib/ruby/1.8/irb/ruby-lex.rb:229:in `each_top_level_statement'
from /usr/local/jruby-1.0.1/lib/ruby/1.8/irb.rb:146:in `eval_input'
from /usr/local/jruby-1.0.1/lib/ruby/1.8/irb.rb:70:in `start'
from :1:in `catch'
from /usr/local/jruby-1.0.1/lib/ruby/1.8/irb.rb:69:in `start'
from :1
Maybe IRB bug!!
It seems that the date parser does not like this particular format. Note that "Tue Aug 28 00:37:29 2007 -0700" (
JRUBY-1298) works just fine.