Project

General

Profile

Actions

Bug #6193

closed

Time.new does not accept seconds as a String

Added by john_firebaugh (John Firebaugh) over 12 years ago. Updated over 12 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 1.9.3p125 (2012-02-16 revision 34643) [x86_64-darwin11.3.0]
Backport:
[ruby-core:43569]

Description

Time.new accepts any or all of the year, month, day, hour, or minute specified as a String, but does not accept a String value for seconds:

Time.new("2012", "3", "22", "8", "19", 30)
=> 2012-03-22 08:19:30 -0700
Time.new("2012", "3", "22", "8", "19", "30")
TypeError: can't convert String into an exact number
from (irb):222:in initialize' from (irb):222:in new'
from (irb):222
from /Users/john/.rvm/rubies/ruby-1.9.3-p125/bin/irb:16:in `'

Since all other arguments can be strings, and since Time.utc and Time.local accept String seconds, I believe the expected behavior is that Time.new does as well.


Files

ruby-time-sec-str.patch (1.38 KB) ruby-time-sec-str.patch ssuda (Sambasiva Suda), 03/23/2012 11:53 PM
ruby-time-sec-str2.patch (1.57 KB) ruby-time-sec-str2.patch ssuda (Sambasiva Suda), 03/24/2012 06:48 AM

Updated by ssuda (Sambasiva Suda) over 12 years ago

Here is the patch which will fix the problem with the seconds. There is also pull request for github.

Actions #2

Updated by john_firebaugh (John Firebaugh) over 12 years ago

I think you want to use the obj2subsecx helper, not obj2vint, so that fractional seconds are still supported.

Updated by ssuda (Sambasiva Suda) over 12 years ago

Here is the updated patch using obj2subsecx.

Actions #4

Updated by nobu (Nobuyoshi Nakada) over 12 years ago

  • Status changed from Open to Closed
  • % Done changed from 0 to 100

This issue was solved with changeset r35122.
John, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0