End of Life Ruby 3.1 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
instance method
Date#<<
d << n → date
ext/date/date_core.c
View on GitHub ↗
static VALUE
d_lite_lshift(VALUE self, VALUE other)
{
expect_numeric(other);
return d_lite_rshift(self, f_negate(other));
}
Returns a date object pointing n months before self. The argument n should be a numeric value.
Example
Date.new(2001,2,3) << 1 #=> #<Date: 2001-01-03 ...> Date.new(2001,2,3) << -2 #=> #<Date: 2001-04-03 ...>
When the same day does not exist for the corresponding month, the last day of the month is used instead:
Example
Date.new(2001,3,28) << 1 #=> #<Date: 2001-02-28 ...> Date.new(2001,3,31) << 1 #=> #<Date: 2001-02-28 ...>
This also results in the following, possibly unexpected, behavior:
Example
Date.new(2001,3,31) << 2 #=> #<Date: 2001-01-31 ...> Date.new(2001,3,31) << 1 << 1 #=> #<Date: 2001-01-28 ...> Date.new(2001,3,31) << 1 << -1 #=> #<Date: 2001-03-28 ...>