Bug #4848

DateTime.jd raises 'invalid fraction' when called with more than one argument

Added by Phil   almost 3 years ago. Updated almost 3 years ago.

[ruby-core:36802]
Status:Rejected
Priority:Normal
Assignee:tadayoshi funaba
Category:-
Target version:1.9.3
ruby -v:ruby 1.9.3dev (2011-06-07 trunk 31946) [i686-linux] Backport:

Description

Since trunk revision 31862, the DateTime.jd function raises an ArgumentError with message 'invalid fraction' when it is called with more than one argument. For example,

DateTime.jd(Rational(39014323, 16), 0)
ArgumentError: invalid fraction
from (irb):2:in jd'
from (irb):2
from /home/psr/ruby/build/bin/irb:12:in
'

Calling DateTime.jd without the second parameter (and relying on the default value) works as expected:

DateTime.jd(Rational(39014323, 16))
=> #

I think the problem may be the 'argc > n' tests in the num2numwithfrac and num2intwithfrac #defines in ext/date/date_core.c. The attached patch changes the tests to 'argc < n'. This makes jd function properly again with more than one argument.

date_core_num2_argc_tests.diff Magnifier - Patch to change 'argc > n' to 'argc < n' in num2num_with_frac and num2int_with_frac (573 Bytes) Phil  , 06/07/2011 06:01 AM

History

#1 Updated by Phil   almost 3 years ago

=begin
The second example has gone partially missing above (because RedMine doesn't appear to be escaping the < and >). It should have read:

DateTime.jd(Rational(39014323, 16))
#
=end

#2 Updated by tadayoshi funaba almost 3 years ago

  • Status changed from Open to Rejected
  • Assignee set to tadayoshi funaba

i've never seen such a nonsense patch.

this is not a bug.

you cannot specify both fraction and hour.

DateTime.new(2001,2,28.5,12) should mean 2001-03-31??

we have to be cautious about such a abuse.

Also available in: Atom PDF