method
+
Related methods
- Class methods (100)
- ajd_to_amjd (<= v1_8_7_330)
- ajd_to_jd (<= v1_8_7_330)
- amjd_to_ajd (<= v1_8_7_330)
- civil
- civil_to_jd (<= v1_8_7_330)
- commercial
- commercial_to_jd (<= v1_8_7_330)
- complete_frags (<= v1_9_2_180)
- day_fraction_to_time (<= v1_8_7_330)
- deprecated_alias (<= v1_8_7_330)
- deprecated_class_method_alias (<= v1_8_7_330)
- fix_style (<= v1_8_7_330)
- gregorian? (<= v1_8_7_330)
- gregorian_leap?
- httpdate
- _httpdate
- iso8601
- _iso8601
- jd
- jd_to_ajd (<= v1_8_7_330)
- jd_to_civil (<= v1_8_7_330)
- jd_to_commercial (<= v1_8_7_330)
- jd_to_ld (<= v1_8_7_330)
- jd_to_mjd (<= v1_8_7_330)
- jd_to_ordinal (<= v1_8_7_330)
- jd_to_wday (<= v1_8_7_330)
- jd_to_weeknum (<= v1_8_7_330)
- jisx0301
- _jisx0301
- json_create
- julian? (<= v1_8_7_330)
- julian_leap?
- ld_to_jd (<= v1_8_7_330)
- leap?
- _load
- mjd_to_jd (<= v1_8_7_330)
- new
- new! (>= v1_9_1_378)
- new_by_frags (<= v1_9_2_180)
- now (<= v1_9_2_180)
- nth_kday (>= v1_9_1_378)
- num_pattern? (<= v1_9_2_180)
- once (<= v1_9_2_180)
- ordinal
- ordinal_to_jd (<= v1_8_7_330)
- parse
- _parse
- _parse_beat (<= v1_8_6_287)
- _parse_day (<= v1_9_2_180)
- _parse_ddd (<= v1_9_2_180)
- _parse_dot (<= v1_9_2_180)
- _parse_eu (<= v1_9_2_180)
- _parse_iso (<= v1_9_2_180)
- _parse_iso2 (<= v1_9_2_180)
- _parse_jis (<= v1_9_2_180)
- _parse_mday (<= v1_9_2_180)
- _parse_mon (<= v1_9_2_180)
- _parse_sla (<= v1_9_2_180)
- _parse_sla_eu (<= v1_8_6_287)
- _parse_sla_ja (<= v1_8_6_287)
- _parse_sla_us (<= v1_8_6_287)
- _parse_time (<= v1_9_2_180)
- _parse_us (<= v1_9_2_180)
- _parse_vms (<= v1_9_2_180)
- _parse_year (<= v1_9_2_180)
- rewrite_frags (<= v1_9_2_180)
- rfc2822
- _rfc2822
- rfc3339
- _rfc3339
- rfc822
- _rfc822
- s3e (<= v1_9_2_180)
- strptime
- _strptime
- _strptime_i (<= v1_9_2_180)
- test_all (>= v2_6_3)
- test_civil (>= v2_6_3)
- test_commercial (>= v2_6_3)
- test_nth_kday (>= v2_6_3)
- test_ordinal (>= v2_6_3)
- test_unit_conv (>= v2_6_3)
- test_weeknum (>= v2_6_3)
- time_to_day_fraction (<= v1_8_7_330)
- today
- valid_civil?
- valid_commercial?
- valid_date?
- valid_date_frags? (<= v1_9_2_180)
- valid_jd?
- valid_nth_kday? (<= v1_9_2_180)
- valid_ordinal?
- valid_time? (<= v1_9_2_180)
- valid_time_frags? (<= v1_9_2_180)
- valid_weeknum? (<= v1_9_2_180)
- weeknum (>= v1_8_6_287)
- weeknum_to_jd (<= v1_8_7_330)
- xmlschema
- _xmlschema
- zone_to_diff (<= v1_8_7_330)
- Instance methods (167)
- <<
- <=>
- == (<= v1_9_2_180)
- ===
- >>
- -
- -@ (<= v1_9_2_180)
- / (<= v1_9_2_180)
- * (<= v1_9_2_180)
- ** (<= v1_9_2_180)
- % (<= v1_9_2_180)
- +
- +@ (<= v1_9_2_180)
- abs (<= v1_9_2_180)
- ajd
- ajd_to_amjd (<= v1_9_2_180)
- ajd_to_jd (<= v1_9_2_180)
- amjd
- amjd_to_ajd (<= v1_9_2_180)
- asctime
- as_json
- ceil (<= v1_9_2_180)
- civil (<= v1_9_2_180)
- civil_to_jd (<= v1_9_2_180)
- coerce (<= v1_9_2_180)
- commercial (<= v1_9_2_180)
- commercial_to_jd (<= v1_9_2_180)
- ctime
- cwday
- cweek
- cwyear
- day
- day_fraction
- day_fraction_to_time (<= v1_9_2_180)
- div (<= v1_9_2_180)
- divmod (<= v1_9_2_180)
- downto
- _dump (<= v1_8_7_330)
- dx_addsub (<= v1_9_2_180)
- dx_conv0 (<= v1_9_2_180)
- dx_conv1 (<= v1_9_2_180)
- dx_muldiv (<= v1_9_2_180)
- emit (<= v1_9_2_180)
- emit_a (<= v1_9_2_180)
- emit_ad (<= v1_9_2_180)
- emit_au (<= v1_9_2_180)
- emit_n (<= v1_9_2_180)
- emit_sn (<= v1_9_2_180)
- emit_w (<= v1_9_2_180)
- emit_z (<= v1_9_2_180)
- england
- eql?
- fill (>= v2_6_3)
- find_fdom (<= v1_9_2_180)
- find_fdoy (<= v1_9_2_180)
- find_ldom (<= v1_9_2_180)
- find_ldoy (<= v1_9_2_180)
- fix_style (<= v1_9_2_180)
- floor (<= v1_9_2_180)
- friday?
- gregorian
- gregorian?
- hash
- hour
- httpdate
- initialize_copy
- inspect
- inspect_raw (>= v2_6_3)
- integer? (<= v1_9_2_180)
- iso8601
- italy
- jd
- jd_to_ajd (<= v1_9_2_180)
- jd_to_civil (<= v1_9_2_180)
- jd_to_commercial (<= v1_9_2_180)
- jd_to_ld (<= v1_9_2_180)
- jd_to_mjd (<= v1_9_2_180)
- jd_to_nth_kday (<= v1_9_2_180)
- jd_to_ordinal (<= v1_9_2_180)
- jd_to_wday (<= v1_9_2_180)
- jd_to_weeknum (<= v1_9_2_180)
- jisx0301
- julian
- julian?
- ld
- ld_to_jd (<= v1_9_2_180)
- leap?
- marshal_dump
- marshal_dump_old (>= v2_6_3)
- marshal_load
- mday
- min
- minute
- mjd
- mjd_to_jd (<= v1_9_2_180)
- modulo (<= v1_9_2_180)
- mon
- monday?
- month
- new_offset
- new_start
- next
- next_day
- next_month
- next_year
- nth_kday? (>= v1_9_1_378)
- nth_kday_to_jd (<= v1_9_2_180)
- offset
- ordinal (<= v1_9_2_180)
- ordinal_to_jd (<= v1_9_2_180)
- prev_day
- prev_month
- prev_year
- quo (<= v1_9_2_180)
- quotient (<= v1_9_2_180)
- quotrem (<= v1_9_2_180)
- remainder (<= v1_9_2_180)
- rfc2822
- rfc3339
- rfc822
- round (<= v1_9_2_180)
- saturday?
- sec
- sec_fraction
- second
- second_fraction
- start
- step
- strftime
- succ
- sunday?
- thursday?
- time (<= v1_9_2_180)
- time_to_day_fraction (<= v1_9_2_180)
- to_c (<= v1_9_2_180)
- to_date
- to_datetime
- to_f (<= v1_9_2_180)
- to_i (<= v1_9_2_180)
- to_int (<= v1_9_2_180)
- to_json
- to_r (<= v1_9_2_180)
- to_s
- to_time
- to_yaml (<= v1_9_1_378)
- truncate (<= v1_9_2_180)
- tuesday?
- upto
- _valid_civil? (<= v1_9_2_180)
- _valid_commercial? (<= v1_9_2_180)
- _valid_jd? (<= v1_9_2_180)
- _valid_nth_kday? (<= v1_9_2_180)
- _valid_ordinal? (<= v1_9_2_180)
- _valid_time? (<= v1_9_2_180)
- _valid_weeknum? (<= v1_9_2_180)
- wday
- wednesday?
- weeknum0 (<= v1_9_2_180)
- weeknum1 (<= v1_9_2_180)
- weeknum_to_jd (<= v1_9_2_180)
- wnum0 (>= v1_8_6_287)
- wnum1 (>= v1_8_6_287)
- xmlschema
- yday
- year
- zone
- zone_to_diff (<= v1_9_2_180)
= private
= protected
+(p1)
public
Returns a date object pointing other days after self. The other should be a numeric value. If the other is a fractional number, assumes its precision is at most nanosecond.
Date.new(2001,2,3) + 1 #=> #<Date: 2001-02-04 ...> DateTime.new(2001,2,3) + Rational(1,2) #=> #<DateTime: 2001-02-03T12:00:00+00:00 ...> DateTime.new(2001,2,3) + Rational(-1,2) #=> #<DateTime: 2001-02-02T12:00:00+00:00 ...> DateTime.jd(0,12) + DateTime.new(2001,2,3).ajd #=> #<DateTime: 2001-02-03T00:00:00+00:00 ...>
Show source
static VALUE d_lite_plus(VALUE self, VALUE other) { get_d1(self); switch (TYPE(other)) { case T_FIXNUM: { VALUE nth; long t; int jd; nth = m_nth(dat); t = FIX2LONG(other); if (DIV(t, CM_PERIOD)) { nth = f_add(nth, INT2FIX(DIV(t, CM_PERIOD))); t = MOD(t, CM_PERIOD); } if (!t) jd = m_jd(dat); else { jd = m_jd(dat) + (int)t; canonicalize_jd(nth, jd); } if (simple_dat_p(dat)) return d_simple_new_internal(rb_obj_class(self), nth, jd, dat->s.sg, 0, 0, 0, (dat->s.flags | HAVE_JD) & ~HAVE_CIVIL); else return d_complex_new_internal(rb_obj_class(self), nth, jd, dat->c.df, dat->c.sf, dat->c.of, dat->c.sg, 0, 0, 0, #ifndef USE_PACK dat->c.hour, dat->c.min, dat->c.sec, #else EX_HOUR(dat->c.pc), EX_MIN(dat->c.pc), EX_SEC(dat->c.pc), #endif (dat->c.flags | HAVE_JD) & ~HAVE_CIVIL); } break; case T_BIGNUM: { VALUE nth; int jd, s; if (f_positive_p(other)) s = +1; else { s = -1; other = f_negate(other); } nth = f_idiv(other, INT2FIX(CM_PERIOD)); jd = FIX2INT(f_mod(other, INT2FIX(CM_PERIOD))); if (s < 0) { nth = f_negate(nth); jd = -jd; } if (!jd) jd = m_jd(dat); else { jd = m_jd(dat) + jd; canonicalize_jd(nth, jd); } if (f_zero_p(nth)) nth = m_nth(dat); else nth = f_add(m_nth(dat), nth); if (simple_dat_p(dat)) return d_simple_new_internal(rb_obj_class(self), nth, jd, dat->s.sg, 0, 0, 0, (dat->s.flags | HAVE_JD) & ~HAVE_CIVIL); else return d_complex_new_internal(rb_obj_class(self), nth, jd, dat->c.df, dat->c.sf, dat->c.of, dat->c.sg, 0, 0, 0, #ifndef USE_PACK dat->c.hour, dat->c.min, dat->c.sec, #else EX_HOUR(dat->c.pc), EX_MIN(dat->c.pc), EX_SEC(dat->c.pc), #endif (dat->c.flags | HAVE_JD) & ~HAVE_CIVIL); } break; case T_FLOAT: { double jd, o, tmp; int s, df; VALUE nth, sf; o = RFLOAT_VALUE(other); if (o > 0) s = +1; else { s = -1; o = -o; } o = modf(o, &tmp); if (!floor(tmp / CM_PERIOD)) { nth = INT2FIX(0); jd = (int)tmp; } else { double i, f; f = modf(tmp / CM_PERIOD, &i); nth = f_floor(DBL2NUM(i)); jd = (int)(f * CM_PERIOD); } o *= DAY_IN_SECONDS; o = modf(o, &tmp); df = (int)tmp; o *= SECOND_IN_NANOSECONDS; sf = INT2FIX((int)round(o)); if (s < 0) { jd = -jd; df = -df; sf = f_negate(sf); } if (f_zero_p(sf)) sf = m_sf(dat); else { sf = f_add(m_sf(dat), sf); if (f_lt_p(sf, INT2FIX(0))) { df -= 1; sf = f_add(sf, INT2FIX(SECOND_IN_NANOSECONDS)); } else if (f_ge_p(sf, INT2FIX(SECOND_IN_NANOSECONDS))) { df += 1; sf = f_sub(sf, INT2FIX(SECOND_IN_NANOSECONDS)); } } if (!df) df = m_df(dat); else { df = m_df(dat) + df; if (df < 0) { jd -= 1; df += DAY_IN_SECONDS; } else if (df >= DAY_IN_SECONDS) { jd += 1; df -= DAY_IN_SECONDS; } } if (!jd) jd = m_jd(dat); else { jd = m_jd(dat) + jd; canonicalize_jd(nth, jd); } if (f_zero_p(nth)) nth = m_nth(dat); else nth = f_add(m_nth(dat), nth); if (!df && f_zero_p(sf) && !m_of(dat)) return d_simple_new_internal(rb_obj_class(self), nth, (int)jd, m_sg(dat), 0, 0, 0, (dat->s.flags | HAVE_JD) & ~(HAVE_CIVIL | HAVE_TIME | COMPLEX_DAT)); else return d_complex_new_internal(rb_obj_class(self), nth, (int)jd, df, sf, m_of(dat), m_sg(dat), 0, 0, 0, 0, 0, 0, (dat->c.flags | HAVE_JD | HAVE_DF) & ~(HAVE_CIVIL | HAVE_TIME)); } break; default: expect_numeric(other); other = f_to_r(other); #ifdef CANONICALIZATION_FOR_MATHN if (!k_rational_p(other)) return d_lite_plus(self, other); #endif /* fall through */ case T_RATIONAL: { VALUE nth, sf, t; int jd, df, s; if (wholenum_p(other)) return d_lite_plus(self, rb_rational_num(other)); if (f_positive_p(other)) s = +1; else { s = -1; other = f_negate(other); } nth = f_idiv(other, INT2FIX(CM_PERIOD)); t = f_mod(other, INT2FIX(CM_PERIOD)); jd = FIX2INT(f_idiv(t, INT2FIX(1))); t = f_mod(t, INT2FIX(1)); t = f_mul(t, INT2FIX(DAY_IN_SECONDS)); df = FIX2INT(f_idiv(t, INT2FIX(1))); t = f_mod(t, INT2FIX(1)); sf = f_mul(t, INT2FIX(SECOND_IN_NANOSECONDS)); if (s < 0) { nth = f_negate(nth); jd = -jd; df = -df; sf = f_negate(sf); } if (f_zero_p(sf)) sf = m_sf(dat); else { sf = f_add(m_sf(dat), sf); if (f_lt_p(sf, INT2FIX(0))) { df -= 1; sf = f_add(sf, INT2FIX(SECOND_IN_NANOSECONDS)); } else if (f_ge_p(sf, INT2FIX(SECOND_IN_NANOSECONDS))) { df += 1; sf = f_sub(sf, INT2FIX(SECOND_IN_NANOSECONDS)); } } if (!df) df = m_df(dat); else { df = m_df(dat) + df; if (df < 0) { jd -= 1; df += DAY_IN_SECONDS; } else if (df >= DAY_IN_SECONDS) { jd += 1; df -= DAY_IN_SECONDS; } } if (!jd) jd = m_jd(dat); else { jd = m_jd(dat) + jd; canonicalize_jd(nth, jd); } if (f_zero_p(nth)) nth = m_nth(dat); else nth = f_add(m_nth(dat), nth); if (!df && f_zero_p(sf) && !m_of(dat)) return d_simple_new_internal(rb_obj_class(self), nth, jd, m_sg(dat), 0, 0, 0, (dat->s.flags | HAVE_JD) & ~(HAVE_CIVIL | HAVE_TIME | COMPLEX_DAT)); else return d_complex_new_internal(rb_obj_class(self), nth, jd, df, sf, m_of(dat), m_sg(dat), 0, 0, 0, 0, 0, 0, (dat->c.flags | HAVE_JD | HAVE_DF) & ~(HAVE_CIVIL | HAVE_TIME)); } break; } }