Skip to content

Commit

Permalink
Updated the error messages on date when nil args
Browse files Browse the repository at this point in the history
Closes: ruby#2272
  • Loading branch information
dannyd4315 authored and nobu committed Jul 4, 2019
1 parent 6c2b59f commit 6d6495f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
11 changes: 10 additions & 1 deletion ext/date/date_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -3398,14 +3398,23 @@ date_initialize(int argc, VALUE *argv, VALUE self)
rb_raise(rb_eTypeError, "Date expected");
}

rb_scan_args(argc, argv, "04", &vy, &vm, &vd, &vsg);
int i = rb_scan_args(argc, argv, "04", &vy, &vm, &vd, &vsg);

y = INT2FIX(-4712);
m = 1;
d = 1;
fr2 = INT2FIX(0);
sg = DEFAULT_SG;

if (i >= 1 && NIL_P(vy))
rb_raise(rb_eArgError, "invalid date");

if (i >= 2 && NIL_P(vm))
rb_raise(rb_eArgError, "invalid date");

if (i >= 3 && NIL_P(vd))
rb_raise(rb_eArgError, "invalid date");

switch (argc) {
case 4:
val2sg(vsg, sg);
Expand Down
9 changes: 9 additions & 0 deletions test/date/test_date_new.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,15 @@ def test_civil__ex
assert_raise(ArgumentError) do
Date.civil(2001,2,29)
end
assert_raise(ArgumentError) do
Date.civil(nil,12,12)
end
assert_raise(ArgumentError) do
Date.civil(2001,nil,12)
end
assert_raise(ArgumentError) do
Date.civil(2001,12,nil)
end
assert_raise(ArgumentError) do
DateTime.civil(2001,2,28, 23,59,60, 0)
end
Expand Down

0 comments on commit 6d6495f

Please sign in to comment.