Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Time.parse has a ridiculous and incorrect fallback mode

#2898

Time.parse("foo") yields: Fri Jul 10 15:38:38 -0500 2009

Essentially, it is ridiculous for an unparseable time to be understood, without notice, as Time.now. The method essentially says "I don't know how to answer you, but here's something clearly wrong!"

Preferred behaviour would be either to return nil or to raise an exception, in that order of preference, I believe.

At any rate, this method clearly violates the POLS.

Reported by knewter (at gmail) · July 10th, 2009 @ 09:52 PM

State: invalid
Milestone: 2.x
Assigned to: nobody
Importance: none

Activity

  1. knewter (at gmail)
    knewter (at gmail)

    holy moley I thought this was in ActiveSupport. A thousand apologies

    July 10th, 2009 @ 09:54 PM

  2. randy
    randy
    • Tag changed from pols, time.parse to time.parse

    +1 I've been bitten by this more than once!

    July 10th, 2009 @ 09:55 PM

  3. Geoff Buesing
    Geoff Buesing
    • State changed from new to invalid
    • Tag changed from time.parse to time.parse

    Yeah this is in Ruby core. Fortunately, this oddball behavior has been changed in the upcoming Ruby 1.9.2 release -- Time.parse will raise an ArgumentError if it can't parse a Time from a string.

    For use right now: Time.zone.parse will just return nil if it can't parse a string, if that works for your needs.

    July 11th, 2009 @ 03:17 PM

  4. knewter (at gmail)
    knewter (at gmail)

    Thanks a lot, that's fine behavior. :)

    July 11th, 2009 @ 03:49 PM