Method: DateTime#prev_year
- Defined in:
- ext/date_ext/datetime.c
#prev_year(*args) ⇒ Object
prev_year(n=1) -> DateTime
Returns a DateTime
n
years before the receiver. If n
is negative, returns a DateTime
after the receiver. The new DateTime
is returned with the same fractional part and offset as the receiver.
DateTime.civil(2009, 1, 2, 12).prev_year
# => #<DateTime 2008-01-02T12:00:00+00:00>
DateTime.civil(2009, 1, 2, 12).prev_year(2)
# => #<DateTime 2007-01-02T12:00:00+00:00>
2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 |
# File 'ext/date_ext/datetime.c', line 2542
static VALUE rhrdt_prev_year(int argc, VALUE *argv, VALUE self) {
long i;
switch(argc) {
case 0:
i = -1;
break;
case 1:
i = -NUM2LONG(argv[0]);
break;
default:
rb_raise(rb_eArgError, "wrong number of arguments: %d for 1", argc);
break;
}
return rhrdt__add_years(self, i);
}
|