How to set the default year for DateTime.parse

K

Kyle Schmitt

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:in `parse'
from (irb):2
puts DateTime.parse("Apr 2 2009 16:30:31")
=>2009-04-02T16:30:31Z


Thanks
--Kyle
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,197
Latest member
Sean29G025

Latest Threads

Top