/** * Returns the last millisecond of the month, evaluated using the supplied * calendar (which determines the time zone). * * @param calendar the calendar (<code>null</code> not permitted). * * @return The last millisecond of the month. * * @throws NullPointerException if <code>calendar</code> is * <code>null</code>. */ public long getLastMillisecond(Calendar calendar) { int eom = SerialDate.lastDayOfMonth(this.month, this.year); calendar.set(this.year, this.month - 1, eom, 23, 59, 59); calendar.set(Calendar.MILLISECOND, 999); // in the following line, we'd rather call calendar.getTimeInMillis() // to avoid object creation, but that isn't supported in Java 1.3.1 return calendar.getTime().getTime(); }
/** * Returns the last millisecond of the Quarter, evaluated using the * supplied calendar (which determines the time zone). * * @param calendar the calendar (<code>null</code> not permitted). * * @return The last millisecond of the Quarter. * * @throws NullPointerException if <code>calendar</code> is * <code>null</code>. */ public long getLastMillisecond(Calendar calendar) { int month = Quarter.LAST_MONTH_IN_QUARTER[this.quarter]; int eom = SerialDate.lastDayOfMonth(month, this.year); calendar.set(this.year, month - 1, eom, 23, 59, 59); calendar.set(Calendar.MILLISECOND, 999); // in the following line, we'd rather call calendar.getTimeInMillis() // to avoid object creation, but that isn't supported in Java 1.3.1 return calendar.getTime().getTime(); }
if ((day >= 1) && (day <= SerialDate.lastDayOfMonth(month, year))) { this.day = day;
if ((day >= 1) && (day <= SerialDate.lastDayOfMonth(month, year))) { this.day = day;
if ((day >= 1) && (day <= SerialDate.lastDayOfMonth(month, year))) { this.day = day;
/** * Creates a new date by adding the specified number of years to the base * date. * * @param years the number of years to add (can be negative). * @param base the base date. * * @return A new date. */ public static SerialDate addYears(final int years, final SerialDate base) { final int baseY = base.getYYYY(); final int baseM = base.getMonth(); final int baseD = base.getDayOfMonth(); final int targetY = baseY + years; final int targetD = Math.min( baseD, SerialDate.lastDayOfMonth(baseM, targetY) ); return SerialDate.createInstance(targetD, baseM, targetY); }
/** * Creates a new date by adding the specified number of years to the base * date. * * @param years the number of years to add (can be negative). * @param base the base date. * * @return A new date. */ public static SerialDate addYears(final int years, final SerialDate base) { final int baseY = base.getYYYY(); final int baseM = base.getMonth(); final int baseD = base.getDayOfMonth(); final int targetY = baseY + years; final int targetD = Math.min( baseD, SerialDate.lastDayOfMonth(baseM, targetY) ); return SerialDate.createInstance(targetD, baseM, targetY); }
/** * Creates a new date by adding the specified number of years to the base * date. * * @param years the number of years to add (can be negative). * @param base the base date. * * @return A new date. */ public static SerialDate addYears(final int years, final SerialDate base) { final int baseY = base.getYYYY(); final int baseM = base.getMonth(); final int baseD = base.getDayOfMonth(); final int targetY = baseY + years; final int targetD = Math.min( baseD, SerialDate.lastDayOfMonth(baseM, targetY) ); return SerialDate.createInstance(targetD, baseM, targetY); }
/** * Rolls the date forward to the last day of the month. * * @param base the base date. * * @return a new serial date. */ public SerialDate getEndOfCurrentMonth(final SerialDate base) { final int last = SerialDate.lastDayOfMonth( base.getMonth(), base.getYYYY() ); return SerialDate.createInstance(last, base.getMonth(), base.getYYYY()); }
/** * Rolls the date forward to the last day of the month. * * @param base the base date. * * @return a new serial date. */ public SerialDate getEndOfCurrentMonth(final SerialDate base) { final int last = SerialDate.lastDayOfMonth( base.getMonth(), base.getYYYY() ); return SerialDate.createInstance(last, base.getMonth(), base.getYYYY()); }
/** * Rolls the date forward to the last day of the month. * * @param base the base date. * * @return a new serial date. */ public SerialDate getEndOfCurrentMonth(final SerialDate base) { final int last = SerialDate.lastDayOfMonth( base.getMonth(), base.getYYYY() ); return SerialDate.createInstance(last, base.getMonth(), base.getYYYY()); }
/** * Creates a new date by adding the specified number of months to the base * date. * <P> * If the base date is close to the end of the month, the day on the result * may be adjusted slightly: 31 May + 1 month = 30 June. * * @param months the number of months to add (can be negative). * @param base the base date. * * @return a new date. */ public static SerialDate addMonths(final int months, final SerialDate base) { final int yy = (12 * base.getYYYY() + base.getMonth() + months - 1) / 12; final int mm = (12 * base.getYYYY() + base.getMonth() + months - 1) % 12 + 1; final int dd = Math.min( base.getDayOfMonth(), SerialDate.lastDayOfMonth(mm, yy) ); return SerialDate.createInstance(dd, mm, yy); }
/** * Creates a new date by adding the specified number of months to the base * date. * <P> * If the base date is close to the end of the month, the day on the result * may be adjusted slightly: 31 May + 1 month = 30 June. * * @param months the number of months to add (can be negative). * @param base the base date. * * @return a new date. */ public static SerialDate addMonths(final int months, final SerialDate base) { final int yy = (12 * base.getYYYY() + base.getMonth() + months - 1) / 12; final int mm = (12 * base.getYYYY() + base.getMonth() + months - 1) % 12 + 1; final int dd = Math.min( base.getDayOfMonth(), SerialDate.lastDayOfMonth(mm, yy) ); return SerialDate.createInstance(dd, mm, yy); }
/** * Creates a new date by adding the specified number of months to the base * date. * <P> * If the base date is close to the end of the month, the day on the result * may be adjusted slightly: 31 May + 1 month = 30 June. * * @param months the number of months to add (can be negative). * @param base the base date. * * @return a new date. */ public static SerialDate addMonths(final int months, final SerialDate base) { final int yy = (12 * base.getYYYY() + base.getMonth() + months - 1) / 12; final int mm = (12 * base.getYYYY() + base.getMonth() + months - 1) % 12 + 1; final int dd = Math.min( base.getDayOfMonth(), SerialDate.lastDayOfMonth(mm, yy) ); return SerialDate.createInstance(dd, mm, yy); }