Project

General

Profile

Actions

Bug #6885

closed

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

Added by markburns (Mark Burns) over 11 years ago. Updated over 11 years ago.

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

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
=> #<DateTime: 2012-12-12T14:59:59+00:00 ((2456274j,53999s,0n),+0s,2299161j)>

Updated by naruse (Yui NARUSE) over 11 years ago

  • Status changed from Open to Assigned
  • Assignee set to tadf (tadayoshi funaba)

Updated by tadf (tadayoshi funaba) over 11 years ago

  • Status changed from Assigned to Closed
Actions

Also available in: Atom PDF

Like0
Like0Like0