Project

General

Profile

Feature #14091 ยป remove-time-succ.diff

pixeltrix (Andrew White), 11/07/2017 02:44 PM

View differences:

bootstraptest/test_insns.rb
366 366
    [ 'opt_succ',%Q{ #{ $FIXNUM_MAX }.succ == #{ $FIXNUM_MAX + 1 } }, ]
367 367
  end,
368 368
  [ 'opt_succ',  %q{ '1'.succ == '2' }, ],
369
  [ 'opt_succ',  %q{ x = Time.at(0); x.succ == Time.at(1) }, ],
370 369

  
371 370
  [ 'opt_not',  %q{ ! false }, ],
372 371
  [ 'opt_neq', <<~'},', ],       # {
include/ruby/intern.h
943 943

  
944 944
ID rb_frame_callee(void);
945 945
VALUE rb_str_succ(VALUE);
946
VALUE rb_time_succ(VALUE);
947 946
VALUE rb_make_backtrace(void);
948 947
VALUE rb_make_exception(int, const VALUE*);
949 948

  
range.c
297 297
static int
298 298
discrete_object_p(VALUE obj)
299 299
{
300
    if (rb_obj_is_kind_of(obj, rb_cTime)) return FALSE; /* until Time#succ removed */
301 300
    return rb_respond_to(obj, id_succ);
302 301
}
303 302

  
spec/ruby/core/time/succ_spec.rb
1 1
require File.expand_path('../../../spec_helper', __FILE__)
2 2

  
3 3
describe "Time#succ" do
4
  it "returns a new time one second later than time" do
4
  it "raises a NoMethodError" do
5 5
    -> {
6 6
      @result = Time.at(100).succ
7
    }.should complain(/Time#succ is obsolete/)
8
    @result.should == Time.at(101)
9
  end
10

  
11
  it "returns a new instance" do
12
    t1 = Time.at(100)
13
    t2 = nil
14
    -> {
15
      t2 = t1.succ
16
    }.should complain(/Time#succ is obsolete/)
17
    t1.object_id.should_not == t2.object_id
7
    }.should raise_error(NoMethodError, /undefined method `succ'/)
18 8
  end
19 9
end
time.c
3701 3701

  
3702 3702
/*
3703 3703
 * call-seq:
3704
 *   time.succ   -> new_time
3705
 *
3706
 * Returns a new Time object, one second later than _time_.
3707
 * Time#succ is obsolete since 1.9.2 for time is not a discrete value.
3708
 *
3709
 *     t = Time.now       #=> 2007-11-19 08:23:57 -0600
3710
 *     t.succ             #=> 2007-11-19 08:23:58 -0600
3711
 *
3712
 * Use instead <code>time + 1</code>
3713
 *
3714
 *     t + 1              #=> 2007-11-19 08:23:58 -0600
3715
 */
3716

  
3717
VALUE
3718
rb_time_succ(VALUE time)
3719
{
3720
    struct time_object *tobj;
3721
    struct time_object *tobj2;
3722

  
3723
    rb_warn("Time#succ is obsolete; use time + 1");
3724
    GetTimeval(time, tobj);
3725
    time = time_new_timew(rb_cTime, wadd(tobj->timew, WINT2FIXWV(TIME_SCALE)));
3726
    GetTimeval(time, tobj2);
3727
    TIME_COPY_GMT(tobj2, tobj);
3728
    return time;
3729
}
3730

  
3731
#define time_succ rb_time_succ
3732

  
3733
/*
3734
 * call-seq:
3735 3704
 *   time.round([ndigits])   -> new_time
3736 3705
 *
3737 3706
 * Rounds sub seconds to a given precision in decimal digits (0 digits by default).
......
4885 4854
    rb_define_method(rb_cTime, "+", time_plus, 1);
4886 4855
    rb_define_method(rb_cTime, "-", time_minus, 1);
4887 4856

  
4888
    rb_define_method(rb_cTime, "succ", time_succ, 0);
4889 4857
    rb_define_method(rb_cTime, "round", time_round, -1);
4890 4858

  
4891 4859
    rb_define_method(rb_cTime, "sec", time_sec, 0);
vm.c
1597 1597
    OP(Length, LENGTH), (C(Array), C(String), C(Hash));
1598 1598
    OP(Size, SIZE), (C(Array), C(String), C(Hash));
1599 1599
    OP(EmptyP, EMPTY_P), (C(Array), C(String), C(Hash));
1600
    OP(Succ, SUCC), (C(Integer), C(String), C(Time));
1600
    OP(Succ, SUCC), (C(Integer), C(String));
1601 1601
    OP(EqTilde, MATCH), (C(Regexp), C(String));
1602 1602
    OP(Freeze, FREEZE), (C(String));
1603 1603
    OP(UMinus, UMINUS), (C(String));