Hi,
I was looking for if I can use Date::strptime method to check if a
string
can be validate as valid month or not, Thus I tested it with few
random
strings. It was meeting my expectation too.
Date::strptime(“January”,’%B’)
=> #<Date: 2014-01-01 ((2456659j,0s,0n),+0s,2299161j)>
Date::strptime(“JaNuary”,’%B’)
=> #<Date: 2014-01-01 ((2456659j,0s,0n),+0s,2299161j)>
Date::strptime(“JaNua”,’%B’)
=> #<Date: 2014-01-01 ((2456659j,0s,0n),+0s,2299161j)>
2.0.0-p451 :005 > Date::strptime(“Foo”,’%B’)
ArgumentError: invalid date
Date::strptime(“Jan”,’%B’)
=> #<Date: 2014-01-01 ((2456659j,0s,0n),+0s,2299161j)>
Date::strptime(“Janu”,’%B’)
=> #<Date: 2014-01-01 ((2456659j,0s,0n),+0s,2299161j)>
Now all are going above my head.
Date::strptime(“Marche”,’%B’)
=> #<Date: 2014-03-01 ((2456718j,0s,0n),+0s,2299161j)>
Date::strptime(“Marcheee”,’%B’)
#=> #<Date: 2014-03-01 ((2456718j,0s,0n),+0s,2299161j)>
Date::strptime(“Mayil”,’%B’)
=> #<Date: 2014-05-01 ((2456779j,0s,0n),+0s,2299161j)>
Date::strptime(“Juneixyt”,’%B’)
=> #<Date: 2014-06-01 ((2456810j,0s,0n),+0s,2299161j)>
Does that mean valid English month name checking this way is not safe ?
–
Regards,
Arup R.
Debugging is twice as hard as writing the code in the first place.
Therefore,
if you write the code as cleverly as possible, you are, by definition,
not
smart enough to debug it.
–Brian Kernighan