Time Parse Documentation Incorrect - Undefined method getlocal
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
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
DateTime do not). Or of course the documentation should be updated to specify that a time object must be passed as the now parameter.
Updated by nobu (Nobuyoshi Nakada) almost 2 years 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
Time.parsemay be a non-
Timeobject which does not have
getlocalmethod, 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) firstname.lastname@example.org