On 15 October 2012 22:48, garysweaver (Gary Weaver)
garysweaver@gmail.com wrote:
Issue #7137 has been updated by garysweaver (Gary Weaver).
I respectfully ask to reopen this ticket. The problem is that people expect that Date.parse('Monitoring') to fail or return nil because it isn't a date nor does it contain anything that should be interpreted as a date. The problem was not the one that Alexey last stated (Date.parse('10/11/12')) which was the stated reason for closing this ticket by @tadf (tadayoshi funaba), although I appreciate his help.
@tadf (tadayoshi funaba), I understand that @matz's solution was to use a pattern matching solution and that this was fastest, but I do not believe that Date.parse('Monitoring') should return Monday. and wonder if @matz (Yukihiro Matsumoto) agrees? Those new to Ruby will use this method thinking that it will work properly, so it would be more helpful if the method were either called Date.guess('Monitoring') or if instead Date.parse were deprecated or flagged compiler warning and in the deprecation or warning message tell people to use strptime instead because Date.parse is too lenient.
Thanks in advance again for considering this change! You guys are awesome!
Gary
There is an existing equivalence to the lenient pattern matching:
'1xy'.to_i #=> 1
However in the case of converting strings to integers, we have the
option of a validating conversion ..
Integer('1') #=> 1
Integer('1xy') #=> exception
.. or it's trivial to write our own validation rule (i.e. /^\d+$/ )
Dates, however, have much more complex patterns, and I'm unaware of
any existing validating/exception-throwing parser.
If I were to request anything, it would be the option of invoking such
a validating converter that doesn't require a template pattern (as
strptime does), parses and converts the string as Date#parse does, but
tests the entire string, throwing an exception if it is not a
valid/understandable date.
I think we've been spoiled by PHP's strtotime()
http://php.net/manual/en/function.strtotime.php
Matthew Kerwin