summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitrii Zudin <[email protected]>2024-09-21 23:37:07 +0300
committergit <[email protected]>2024-11-05 03:38:13 +0000
commitee4599dbe7e49a242a1e8170b0439cfb0130ad98 (patch)
treef984017e48902a80ef2f644115a5e556712121cc
parente0611ebd9a4c05a9c16a1da8e5c3081f7890ea8c (diff)
[ruby/date] Fix incorrect argc2 decrement in datetime_s_iso8601 function
Replace the decrement (argc2--) with an increment (argc2++) for the correct number of arguments when opt is provided. https://github.com/ruby/date/commit/b6974b00d8
-rw-r--r--ext/date/date_core.c2
-rw-r--r--test/date/test_date_strftime.rb8
2 files changed, 9 insertions, 1 deletions
diff --git a/ext/date/date_core.c b/ext/date/date_core.c
index 823c0bc2a5..5d9fe4ff98 100644
--- a/ext/date/date_core.c
+++ b/ext/date/date_core.c
@@ -8485,7 +8485,7 @@ datetime_s_iso8601(int argc, VALUE *argv, VALUE klass)
VALUE argv2[2], hash;
argv2[0] = str;
argv2[1] = opt;
- if (!NIL_P(opt)) argc2--;
+ if (!NIL_P(opt)) argc2++;
hash = date_s__iso8601(argc2, argv2, klass);
return dt_new_by_frags(klass, hash, sg);
}
diff --git a/test/date/test_date_strftime.rb b/test/date/test_date_strftime.rb
index dd04c0d9a4..976e48f517 100644
--- a/test/date/test_date_strftime.rb
+++ b/test/date/test_date_strftime.rb
@@ -412,6 +412,14 @@ class TestDateStrftime < Test::Unit::TestCase
assert_equal('H31.04.30', Date.parse('2019-04-30').jisx0301)
assert_equal('R01.05.01', Date.parse('2019-05-01').jisx0301)
+ assert_equal(d2, DateTime.iso8601('2001-02-03T04:05:06.123456+00:00', limit: 64))
+ assert_equal(d2, DateTime.rfc3339('2001-02-03T04:05:06.123456+00:00', limit: 64))
+ assert_equal(d2, DateTime.jisx0301('H13.02.03T04:05:06.123456+00:00', limit: 64))
+
+ assert_raise(ArgumentError) { DateTime.iso8601('2001-02-03T04:05:06.123456+00:00', limit: 1) }
+ assert_raise(ArgumentError) { DateTime.rfc3339('2001-02-03T04:05:06.123456+00:00', limit: 1) }
+ assert_raise(ArgumentError) { DateTime.jisx0301('H13.02.03T04:05:06.123456+00:00', limit: 1) }
+
%w(M06.01.01
M45.07.29
T01.07.30