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 1 year ago. Updated over 1 year ago.

[ruby-core:47226]
Status:Closed
Priority:Normal
Assignee:tadayoshi funaba
Category:-
Target version:2.0.0
ruby -v:ruby 2.0.0dev (2012-08-16) [x86_64-darwin11.4.0] Backport:

Description

I have written an mspec on the rubyspec project to demonstrate the existing behaviour:
https://github.com/markburns/rubyspec/commit/2ef354d4bdb41688ff84b65402faeb7b4e9a3844#L0R73e

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
DateTime.parse("2012-12-31T24:43:59")

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
minutes.

Technically it should allow values of 60 according to ISO8601.
http://en.wikipedia.org/wiki/ISO_8601
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
=> #

History

#1 Updated by Yui NARUSE over 1 year ago

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

#2 Updated by tadayoshi funaba over 1 year ago

  • Status changed from Assigned to Closed

Also available in: Atom PDF