Forum: Ruby How to set the default year for DateTime.parse

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Kyle S. (Guest)
on 2009-04-03 01:35
(Received via mailing list)
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
This topic is locked and can not be replied to.