private boolean isLastDayOfMonth(Calendar cal) {
    int maxDd = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
    int dd = cal.get(Calendar.DAY_OF_MONTH);
    return dd == maxDd;
  }
GenericUDFAddMonths.

Add a number of months to the date. The time part of the string will be
ignored.
ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFAddMonths.java