How to set the default year for DateTime.parse


#1

I’m running into an odd little issue. I banged out a quick script on
my laptop (running ubuntu) this afternoon, and moved it over to one of
my servers (running CentOS 5.2). Even though both have ruby 1.8, I
ran into an odd inconsistency with DateTime.parse

It looks like on the Ubuntu box, parse just goes ahead and uses the
current year if none is given. On the CentOS box, it doesn’t and
errors out.

Ubuntu, ruby 1.8.7
puts DateTime.parse(“Apr 2 16:30:31”)
=>2009-04-02T16:30:31+00:00
puts DateTime.parse(“Apr 2 2009 16:30:31”)
=>2009-04-02T16:30:31+00:00

CentOS, ruby 1.8.5
puts DateTime.parse(“Apr 2 16:30:31”)
ArgumentError: 3 elements of civil date are necessary
from /usr/lib/ruby/1.8/date.rb:1214:in new_with_hash' from /usr/lib/ruby/1.8/date.rb:1258:inparse’
from (irb):2
puts DateTime.parse(“Apr 2 2009 16:30:31”)
=>2009-04-02T16:30:31Z

Thanks
–Kyle