Unexpected behaviour of DateTime.parse (this issue can be reproduced in Ruby 1.8/1.9 as well) 英語で書いてるけど日本語も分かります。
I have written an mspec on the rubyspec project to demonstrate the existing behaviour:
d = DateTime.parse("2012-11-08T15:43:61")
expected ArgumentError but the following is true¶
d == DateTime.civil(2012, 11, 8, 15, 43, 59)
This raises an ArgumentError with values for hours greater than 23
I think the principle of least surprise would be to raise an ArgumentError if
the value for seconds is over 59, consistent with the months, days, hours, and
Technically it should allow values of 60 according to ISO8601.
But in order not to complicate things more with leap seconds, it may
be better to tackle the issue just considering seconds over 59.
Steps to reproduce¶
ruby 2.0.0dev (2012-08-16) [x86_64-darwin11.4.0]
2.0.0dev :001 > require 'date'
2.0.0dev :002 > DateTime.parse("2012-12-31T24:43:59") #expected ArgumentError when hours > 23
ArgumentError: invalid date
2.0.0dev :003 > DateTime.parse '2012-12-12T14:59:61' #unexpected