Bug #6885

Unexpected behaviour of DateTime.parse (this issue can be reproduced in Ruby 1.8/1.9 as well) 英語で書いてるけど日本語も分かります。

Added by Mark Burns over 3 years ago. Updated over 3 years ago.

Assignee:tadayoshi funaba
ruby -v:ruby 2.0.0dev (2012-08-16) [x86_64-darwin11.4.0] Backport:


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 version
ruby -v
ruby 2.0.0dev (2012-08-16) [x86_64-darwin11.4.0]

2.0.0dev :001 > require 'date'
=> true
2.0.0dev :002 > DateTime.parse("2012-12-31T24:43:59") #expected ArgumentError when hours > 23
ArgumentError: invalid date
from (irb):2:in parse'
from (irb):2
from /Users/markburns/.rvm/rubies/ruby-head/bin/irb:16:in
2.0.0dev :003 > DateTime.parse '2012-12-12T14:59:61' #unexpected
=> #


#1 Updated by Yui NARUSE over 3 years ago

  • Status changed from Open to Assigned
  • Assignee set to tadayoshi funaba

#2 Updated by tadayoshi funaba over 3 years ago

  • Status changed from Assigned to Closed

Also available in: Atom PDF