instance method
Date#<<
(::Integer month) -> ::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 new Date object representing the date n months earlier; n should be a numeric:
Example
(Date.new(2001, 2, 3) << 1).to_s # => "2001-01-03" (Date.new(2001, 2, 3) << -2).to_s # => "2001-04-03"
When the same day does not exist for the new month, the last day of that month is used instead:
Example
(Date.new(2001, 3, 31) << 1).to_s # => "2001-02-28" (Date.new(2001, 3, 31) << -6).to_s # => "2001-09-30"
This results in the following, possibly unexpected, behaviors:
Example
d0 = Date.new(2001, 3, 31) d0 << 2 # => #<Date: 2001-01-31> d0 << 1 << 1 # => #<Date: 2001-01-28> d0 = Date.new(2001, 3, 31) d1 = d0 << 1 # => #<Date: 2001-02-28> d2 = d1 << -1 # => #<Date: 2001-03-28>