mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Removed deprecated Time#succ
This commit is contained in:
parent
20d53dad47
commit
7817a438eb
Notes:
git
2020-12-07 18:39:24 +09:00
6 changed files with 33 additions and 67 deletions
|
@ -391,7 +391,6 @@ tests = [
|
|||
[ 'opt_succ',%Q{ #{ $FIXNUM_MAX }.succ == #{ $FIXNUM_MAX + 1 } }, ]
|
||||
end,
|
||||
[ 'opt_succ', %q{ '1'.succ == '2' }, ],
|
||||
[ 'opt_succ', %q{ x = Time.at(0); x.succ == Time.at(1) }, ],
|
||||
|
||||
[ 'opt_not', %q{ ! false }, ],
|
||||
[ 'opt_neq', <<-'},', ], # {
|
||||
|
|
|
@ -45,7 +45,6 @@ struct timeval rb_time_timeval(VALUE time);
|
|||
struct timespec rb_time_timespec(VALUE time);
|
||||
struct timespec rb_time_timespec_interval(VALUE num);
|
||||
VALUE rb_time_utc_offset(VALUE time);
|
||||
VALUE rb_time_succ(VALUE);
|
||||
|
||||
RBIMPL_SYMBOL_EXPORT_END()
|
||||
|
||||
|
|
|
@ -1,38 +1,40 @@
|
|||
require_relative '../../spec_helper'
|
||||
require_relative 'fixtures/classes'
|
||||
ruby_version_is ""..."3.0" do
|
||||
require_relative '../../spec_helper'
|
||||
require_relative 'fixtures/classes'
|
||||
|
||||
describe "Time#succ" do
|
||||
it "returns a new time one second later than time" do
|
||||
suppress_warning {
|
||||
@result = Time.at(100).succ
|
||||
}
|
||||
describe "Time#succ" do
|
||||
it "returns a new time one second later than time" do
|
||||
suppress_warning {
|
||||
@result = Time.at(100).succ
|
||||
}
|
||||
|
||||
@result.should == Time.at(101)
|
||||
end
|
||||
@result.should == Time.at(101)
|
||||
end
|
||||
|
||||
it "returns a new instance" do
|
||||
time = Time.at(100)
|
||||
it "returns a new instance" do
|
||||
time = Time.at(100)
|
||||
|
||||
suppress_warning {
|
||||
@result = time.succ
|
||||
}
|
||||
suppress_warning {
|
||||
@result = time.succ
|
||||
}
|
||||
|
||||
@result.should_not equal time
|
||||
end
|
||||
@result.should_not equal time
|
||||
end
|
||||
|
||||
it "is obsolete" do
|
||||
-> {
|
||||
Time.at(100).succ
|
||||
}.should complain(/Time#succ is obsolete/)
|
||||
end
|
||||
it "is obsolete" do
|
||||
-> {
|
||||
Time.at(100).succ
|
||||
}.should complain(/Time#succ is obsolete/)
|
||||
end
|
||||
|
||||
ruby_version_is "2.6" do
|
||||
context "zone is a timezone object" do
|
||||
it "preserves time zone" do
|
||||
zone = TimeSpecs::Timezone.new(offset: (5*3600+30*60))
|
||||
time = Time.new(2012, 1, 1, 12, 0, 0, zone) - 1
|
||||
ruby_version_is "2.6" do
|
||||
context "zone is a timezone object" do
|
||||
it "preserves time zone" do
|
||||
zone = TimeSpecs::Timezone.new(offset: (5*3600+30*60))
|
||||
time = Time.new(2012, 1, 1, 12, 0, 0, zone) - 1
|
||||
|
||||
time.zone.should == zone
|
||||
time.zone.should == zone
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -604,13 +604,12 @@ class TestTime < Test::Unit::TestCase
|
|||
assert_nil(t.getlocal("+02:00").zone)
|
||||
end
|
||||
|
||||
def test_plus_minus_succ
|
||||
def test_plus_minus
|
||||
t2000 = get_t2000
|
||||
# assert_raise(RangeError) { t2000 + 10000000000 }
|
||||
# assert_raise(RangeError) t2000 - 3094168449 }
|
||||
# assert_raise(RangeError) { t2000 + 1200798848 }
|
||||
assert_raise(TypeError) { t2000 + Time.now }
|
||||
assert_equal(t2000 + 1, t2000.succ)
|
||||
end
|
||||
|
||||
def test_plus_type
|
||||
|
|
35
time.c
35
time.c
|
@ -4260,40 +4260,6 @@ time_minus(VALUE time1, VALUE time2)
|
|||
return time_add(tobj, time1, time2, -1);
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* time.succ -> new_time
|
||||
*
|
||||
* Returns a new Time object, one second later than _time_.
|
||||
* Time#succ is obsolete since 1.9.2 for time is not a discrete value.
|
||||
*
|
||||
* t = Time.now #=> 2007-11-19 08:23:57 -0600
|
||||
* t.succ #=> 2007-11-19 08:23:58 -0600
|
||||
*
|
||||
* Use instead <code>time + 1</code>
|
||||
*
|
||||
* t + 1 #=> 2007-11-19 08:23:58 -0600
|
||||
*/
|
||||
|
||||
VALUE
|
||||
rb_time_succ(VALUE time)
|
||||
{
|
||||
struct time_object *tobj;
|
||||
struct time_object *tobj2;
|
||||
|
||||
rb_warn("Time#succ is obsolete; use time + 1");
|
||||
GetTimeval(time, tobj);
|
||||
time = time_new_timew(rb_cTime, wadd(tobj->timew, WINT2FIXWV(TIME_SCALE)));
|
||||
GetTimeval(time, tobj2);
|
||||
TZMODE_COPY(tobj2, tobj);
|
||||
if (TZMODE_LOCALTIME_P(tobj2) && maybe_tzobj_p(tobj2->vtm.zone)) {
|
||||
zone_localtime(tobj2->vtm.zone, time);
|
||||
}
|
||||
return time;
|
||||
}
|
||||
|
||||
#define time_succ rb_time_succ
|
||||
|
||||
static VALUE
|
||||
ndigits_denominator(VALUE ndigits)
|
||||
{
|
||||
|
@ -5923,7 +5889,6 @@ Init_Time(void)
|
|||
rb_define_method(rb_cTime, "+", time_plus, 1);
|
||||
rb_define_method(rb_cTime, "-", time_minus, 1);
|
||||
|
||||
rb_define_method(rb_cTime, "succ", time_succ, 0);
|
||||
rb_define_method(rb_cTime, "round", time_round, -1);
|
||||
rb_define_method(rb_cTime, "floor", time_floor, -1);
|
||||
rb_define_method(rb_cTime, "ceil", time_ceil, -1);
|
||||
|
|
4
vm.c
4
vm.c
|
@ -1810,7 +1810,9 @@ vm_redefinition_check_flag(VALUE klass)
|
|||
if (klass == rb_cArray) return ARRAY_REDEFINED_OP_FLAG;
|
||||
if (klass == rb_cHash) return HASH_REDEFINED_OP_FLAG;
|
||||
if (klass == rb_cSymbol) return SYMBOL_REDEFINED_OP_FLAG;
|
||||
#if 0
|
||||
if (klass == rb_cTime) return TIME_REDEFINED_OP_FLAG;
|
||||
#endif
|
||||
if (klass == rb_cRegexp) return REGEXP_REDEFINED_OP_FLAG;
|
||||
if (klass == rb_cNilClass) return NIL_REDEFINED_OP_FLAG;
|
||||
if (klass == rb_cTrueClass) return TRUE_REDEFINED_OP_FLAG;
|
||||
|
@ -1920,7 +1922,7 @@ vm_init_redefined_flag(void)
|
|||
OP(Length, LENGTH), (C(Array), C(String), C(Hash));
|
||||
OP(Size, SIZE), (C(Array), C(String), C(Hash));
|
||||
OP(EmptyP, EMPTY_P), (C(Array), C(String), C(Hash));
|
||||
OP(Succ, SUCC), (C(Integer), C(String), C(Time));
|
||||
OP(Succ, SUCC), (C(Integer), C(String));
|
||||
OP(EqTilde, MATCH), (C(Regexp), C(String));
|
||||
OP(Freeze, FREEZE), (C(String));
|
||||
OP(UMinus, UMINUS), (C(String));
|
||||
|
|
Loading…
Add table
Reference in a new issue