From: "M. Edward (Ed) Borasky" Date: 2006-08-07T00:28:07+09:00 Subject: Re: [ ruby-Bugs-5263 ] strptime fails to properly parse certain inputs nobu@ruby-lang.org wrote: > Hi, > > At Wed, 2 Aug 2006 17:40:13 +0900, > Yukihiro Matsumoto wrote in [ruby-core:08485]: > >> |Date.strptime and DateTime.strptime do not properly parse >> |certain forms of input in which there are no non-numeric >> |separators between the fields. >> | >> |For example, the following code fails: >> | >> |Date.strptime("20060401", "%Y%m%d") >> >> Just because strptime() %Y parsed 20060401 as a year of 20,060,401 >> (year twenty million sixty thousand four hundred and one a.d.), and >> did not find month and day. >> > > How about to accept an optional width? > The name "strptime" is used in other programming languages for this functionality. For example, in R, it returns an object of class "POSIXlt". > t <- strptime("20060401", format="%Y%m%d") > t [1] "2006-04-01" > class(t) [1] "POSIXt" "POSIXlt" > $ ruby -ve 'Date.strptime("20060401", "%Y%m%d")' ruby 1.8.5 (2006-06-22) [i686-linux] -e:1: undefined method `strptime' for Date:Class (NoMethodError) So: 1. Where is the "strptime" method to be found? 2. IF you're going to change the behavior of "strptime" (string parse time) please come up with a new name or an optional parameter. Don't change the behavior of "strptime" itself from what it does in other languages (parse a date/time string using a standard list of format designators.) The same goes for "strftime" (string format time), it's inverse.