The parse method tries to find the appropriate date or date and time formats, then parse string to return the values ββused to create the new date or date. There are many different formats that it supports, which is convenient, but the scan process for matching slows down the parsing time.
In addition, some of the formats used are not necessarily βsuitable.β Think about what is going on here:
Date.parse '31/01/2001' =>
Parsing a date string in the format '%d/%m/%Y' (day, month, year), although it is not common in the USA, since Ruby is not a US-oriented language. The inversion of the first two fields leads to:
Date.parse '01/31/2001' ArgumentError: invalid date from (irb):4:in `parse' from (irb):4 from /Users/greg/.rbenv/versions/2.1.5/bin/irb:11:in `<main>' irb(main):005:0> Date.parse '31/01/2001'
source share