/** * Returns a timestamp relative to this one by the given number of years. * The day field may be adjusted to account for leap days. For example, * adding one year to {@code 2012-02-29} results in {@code 2013-02-28}. * * @param amount a (positive or negative) number of hours. */ public final Timestamp addYear(int amount) { if (amount == 0) return this; Calendar cal = calendarValue(); cal.add(Calendar.YEAR, amount); return new Timestamp(cal, _precision, _fraction, _offset); }
/** * Returns a timestamp relative to this one by the given number of months. * The day field may be adjusted to account for different month length and * leap days. For example, adding one month to {@code 2011-01-31} * results in {@code 2011-02-28}. * * @param amount a (positive or negative) number of hours. */ public final Timestamp addMonth(int amount) { if (amount == 0) return this; Calendar cal = calendarValue(); cal.add(Calendar.MONTH, amount); return new Timestamp(cal, _precision, _fraction, _offset); }
/** * Returns a timestamp relative to this one by the given number of years. * The day field may be adjusted to account for leap days. For example, * adding one year to {@code 2012-02-29} results in {@code 2013-02-28}. * * @param amount a (positive or negative) number of hours. */ public final Timestamp addYear(int amount) { if (amount == 0) return this; Calendar cal = calendarValue(); cal.add(Calendar.YEAR, amount); return new Timestamp(cal, _precision, _fraction, _offset); }
/** * Returns a timestamp relative to this one by the given number of months. * The day field may be adjusted to account for different month length and * leap days. For example, adding one month to {@code 2011-01-31} * results in {@code 2011-02-28}. * * @param amount a (positive or negative) number of hours. */ public final Timestamp addMonth(int amount) { if (amount == 0) return this; Calendar cal = calendarValue(); cal.add(Calendar.MONTH, amount); return new Timestamp(cal, _precision, _fraction, _offset); }