Project

General

Profile

Bug #11037

Time Parse Documentation Incorrect - Undefined method getlocal

Added by cfis (Charlie Savage) over 4 years ago. Updated about 1 year ago.

Status:
Closed
Priority:
Normal
Target version:
-
ruby -v:
ruby 2.2.1p85 (2015-02-26 revision 49769) [x64-mingw32]
[ruby-core:<unknown>]

Description

According to:

http://ruby-doc.org/stdlib-2.2.1/libdoc/time/rdoc/Time.html

Time#parse can take a 2nd parameter:

We can change the date used to infer our missing elements by passing a second object that responds to mon, day and year, such as Date, Time or DateTime. We can also use our own object.

However, that is not correct:

irb(main):010:0> Time.parse('12:30 AM', Date.today)
NoMethodError: undefined method `getlocal' for #<Date: 2015-04-07 ((2457120j,0s,0n),+0s,2299161j)>
        from C:/mingw64/mingw64/local/ruby/lib/ruby/2.2.0/time.rb:262:in `make_time'
        from C:/mingw64/mingw64/local/ruby/lib/ruby/2.2.0/time.rb:364:in `parse'
        from (irb):10
        from C:/mingw64/mingw64/local/ruby/bin/irb:11:in `<main>'

The problem is in Time#make_time, lines 259 through 263:

  if off
    now = now.getlocal(off) if now.utc_offset != off
  else
    now = now.getlocal
  end

The behavior the documentation does seem desirable, so the code above should check if the now parameter responds to getlocal or not (only Time does, Date and DateTime do not). Or of course the documentation should be updated to specify that a time object must be passed as the now parameter.


Files

time_parse.patch (1.3 KB) time_parse.patch nkmrya (Yasuhiro Nakamura), 09/06/2015 01:56 AM

Associated revisions

Revision 7f9089a1
Added by nobu (Nobuyoshi Nakada) about 1 year ago

Time.parse based from non-Time object

  • lib/time.rb (Time.make_time): as the document states, the second argument of Time.parse may be a non-Time object which does not have getlocal method, assume it is in the local time in the case. based on the patch by nkmrya (Yasuhiro Nakamura) at [ruby-core:68775]. [ruby-core:68775] [Bug #11037]

Co-authored-by: nkmrya (Yasuhiro Nakamura) yasuhiro6194@gmail.com

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64975 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 64975
Added by nobu (Nobuyoshi Nakada) about 1 year ago

Time.parse based from non-Time object

  • lib/time.rb (Time.make_time): as the document states, the second argument of Time.parse may be a non-Time object which does not have getlocal method, assume it is in the local time in the case. based on the patch by nkmrya (Yasuhiro Nakamura) at [ruby-core:68775]. [ruby-core:68775] [Bug #11037]

Co-authored-by: nkmrya (Yasuhiro Nakamura) yasuhiro6194@gmail.com

Revision 64975
Added by nobu (Nobuyoshi Nakada) about 1 year ago

Time.parse based from non-Time object

  • lib/time.rb (Time.make_time): as the document states, the second argument of Time.parse may be a non-Time object which does not have getlocal method, assume it is in the local time in the case. based on the patch by nkmrya (Yasuhiro Nakamura) at [ruby-core:68775]. [ruby-core:68775] [Bug #11037]

Co-authored-by: nkmrya (Yasuhiro Nakamura) yasuhiro6194@gmail.com

History

Updated by nkmrya (Yasuhiro Nakamura) over 4 years ago

  • File time_parse.patch added

Hi,

I think it is useful Time.parse specifications on the document.
This patch is fix operation to along specifications.

#2

Updated by nobu (Nobuyoshi Nakada) over 4 years ago

    md = MyDate.new(28, 10, 2010)

I don't believe that 2010/28/10 is a valid date.

#3

Updated by nobu (Nobuyoshi Nakada) over 4 years ago

  • Description updated (diff)
#4

Updated by nkmrya (Yasuhiro Nakamura) over 4 years ago

  • File time_parse.patch added

Sory my careless mistake.
I correct mistake in test case.

#5

Updated by nkmrya (Yasuhiro Nakamura) over 4 years ago

  • File deleted (time_parse.patch)
#6

Updated by nkmrya (Yasuhiro Nakamura) over 4 years ago

  • File deleted (time_parse.patch)
#7

Updated by nkmrya (Yasuhiro Nakamura) over 4 years ago

The new patch has passed tests.
Could you review the patch again?

#8

Updated by hsbt (Hiroshi SHIBATA) over 4 years ago

  • Status changed from Open to Assigned
  • Assignee set to akr (Akira Tanaka)

Updated by citrusmoose (Matt Rice) about 1 year ago

What is the status of this?

#10

Updated by nobu (Nobuyoshi Nakada) about 1 year ago

  • Status changed from Assigned to Closed

Applied in changeset trunk|r64975.


Time.parse based from non-Time object

  • lib/time.rb (Time.make_time): as the document states, the second argument of Time.parse may be a non-Time object which does not have getlocal method, assume it is in the local time in the case. based on the patch by nkmrya (Yasuhiro Nakamura) at [ruby-core:68775]. [ruby-core:68775] [Bug #11037]

Co-authored-by: nkmrya (Yasuhiro Nakamura) yasuhiro6194@gmail.com

Also available in: Atom PDF