From: "tadf (tadayoshi funaba)" Date: 2012-08-22T19:43:22+09:00 Subject: [ruby-core:47273] [ruby-trunk - Bug #6885][Closed] Unexpected behaviour of DateTime.parse (this issue can be reproduced in Ruby 1.8/1.9 as well) 英語で書いてるけど日本語も分かります。 Issue #6885 has been updated by tadf (tadayoshi funaba). Status changed from Assigned to Closed ---------------------------------------- Bug #6885: Unexpected behaviour of DateTime.parse (this issue can be reproduced in Ruby 1.8/1.9 as well) ��������������������������������������������������������� https://bugs.ruby-lang.org/issues/6885#change-28974 Author: markburns (Mark Burns) Status: Closed Priority: Normal Assignee: tadf (tadayoshi funaba) Category: Target version: 2.0.0 ruby -v: ruby 2.0.0dev (2012-08-16) [x86_64-darwin11.4.0] 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 => # -- http://bugs.ruby-lang.org/