Convert time component strings to integers more strictly
https://bugs.ruby-lang.org/issues/17485#change-89871
This commit is contained in:
parent
b017848f8a
commit
1eb8eb55c2
@ -46,6 +46,7 @@ class TestTime < Test::Unit::TestCase
|
|||||||
t = Time.new(*tm, "-12:00")
|
t = Time.new(*tm, "-12:00")
|
||||||
assert_equal([2001,2,28,23,59,30,-43200], [t.year, t.month, t.mday, t.hour, t.min, t.sec, t.gmt_offset], bug4090)
|
assert_equal([2001,2,28,23,59,30,-43200], [t.year, t.month, t.mday, t.hour, t.min, t.sec, t.gmt_offset], bug4090)
|
||||||
assert_raise(ArgumentError) { Time.new(2000,1,1, 0,0,0, "+01:60") }
|
assert_raise(ArgumentError) { Time.new(2000,1,1, 0,0,0, "+01:60") }
|
||||||
|
assert_raise(ArgumentError) { Time.new(2021, 1, 1, "+09:99") }
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_time_add()
|
def test_time_add()
|
||||||
|
8
time.c
8
time.c
@ -2793,7 +2793,7 @@ static int
|
|||||||
obj2int(VALUE obj)
|
obj2int(VALUE obj)
|
||||||
{
|
{
|
||||||
if (RB_TYPE_P(obj, T_STRING)) {
|
if (RB_TYPE_P(obj, T_STRING)) {
|
||||||
obj = rb_str_to_inum(obj, 10, FALSE);
|
obj = rb_str_to_inum(obj, 10, TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
return NUM2INT(obj);
|
return NUM2INT(obj);
|
||||||
@ -2815,7 +2815,7 @@ static VALUE
|
|||||||
obj2vint(VALUE obj)
|
obj2vint(VALUE obj)
|
||||||
{
|
{
|
||||||
if (RB_TYPE_P(obj, T_STRING)) {
|
if (RB_TYPE_P(obj, T_STRING)) {
|
||||||
obj = rb_str_to_inum(obj, 10, FALSE);
|
obj = rb_str_to_inum(obj, 10, TRUE);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
obj = rb_to_int(obj);
|
obj = rb_to_int(obj);
|
||||||
@ -2830,7 +2830,7 @@ obj2subsecx(VALUE obj, VALUE *subsecx)
|
|||||||
VALUE subsec;
|
VALUE subsec;
|
||||||
|
|
||||||
if (RB_TYPE_P(obj, T_STRING)) {
|
if (RB_TYPE_P(obj, T_STRING)) {
|
||||||
obj = rb_str_to_inum(obj, 10, FALSE);
|
obj = rb_str_to_inum(obj, 10, TRUE);
|
||||||
*subsecx = INT2FIX(0);
|
*subsecx = INT2FIX(0);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -2844,7 +2844,7 @@ static VALUE
|
|||||||
usec2subsecx(VALUE obj)
|
usec2subsecx(VALUE obj)
|
||||||
{
|
{
|
||||||
if (RB_TYPE_P(obj, T_STRING)) {
|
if (RB_TYPE_P(obj, T_STRING)) {
|
||||||
obj = rb_str_to_inum(obj, 10, FALSE);
|
obj = rb_str_to_inum(obj, 10, TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
return mulquov(num_exact(obj), INT2FIX(TIME_SCALE), INT2FIX(1000000));
|
return mulquov(num_exact(obj), INT2FIX(TIME_SCALE), INT2FIX(1000000));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user