Example usage for java.util Calendar DECEMBER

List of usage examples for java.util Calendar DECEMBER

Introduction

In this page you can find the example usage for java.util Calendar DECEMBER.

Prototype

int DECEMBER

To view the source code for java.util Calendar DECEMBER.

Click Source Link

Document

Value of the #MONTH field indicating the twelfth month of the year in the Gregorian and Julian calendars.

Usage

From source file:helper.lang.DateHelperTest.java

@Test
public void testDiffAndConversionsDifferentDate() {
    Calendar cal1 = new GregorianCalendar(1998, Calendar.DECEMBER, 25);
    Calendar cal2 = new GregorianCalendar(1999, Calendar.JANUARY, 1);
    long diffMillis = DateHelper.diffInMillis(cal1.getTimeInMillis(), cal2.getTimeInMillis());

    assertEquals(604800000L, diffMillis);
    assertEquals(604800L, DateHelper.millisToSeconds(diffMillis));
    assertEquals(10080, DateHelper.millisToMinutes(diffMillis));
    assertEquals(168, DateHelper.millisToHours(diffMillis));
    assertEquals(7, DateHelper.millisToDays(diffMillis));
}

From source file:br.msf.commons.util.AbstractDateUtils.java

public static Integer getLastDayOfMonth(final Integer month, final Integer year) {
    ArgumentUtils.rejectIfAnyNull(month, year);
    ArgumentUtils.rejectIfOutOfBounds(month, Calendar.JANUARY, Calendar.DECEMBER);
    return getLastDayOfMonth(new GregorianCalendar(year, month, 1));
}

From source file:org.jfree.data.time.YearTest.java

/**
 * Some checks for the getEnd() method./*from w ww . ja va2  s .c  o m*/
 */
@Test
public void testGetEnd() {
    Locale saved = Locale.getDefault();
    Locale.setDefault(Locale.ITALY);
    Calendar cal = Calendar.getInstance(Locale.ITALY);
    cal.set(2006, Calendar.DECEMBER, 31, 23, 59, 59);
    cal.set(Calendar.MILLISECOND, 999);
    Year y = new Year(2006);
    assertEquals(cal.getTime(), y.getEnd());
    Locale.setDefault(saved);
}

From source file:net.sourceforge.fenixedu.presentationTier.TagLib.sop.examsMapNew.renderers.ExamsMapContentRenderer.java

private String monthToString(int month, Locale locale) {
    switch (month) {

    case Calendar.JANUARY:
        if (locale.getLanguage().equals("pt")) {
            return "Janeiro";
        }//  www .  j a va 2s . c o  m
        return "January";
    case Calendar.FEBRUARY:
        if (locale.getLanguage().equals("pt")) {
            return "Fevereiro";
        }
        return "February";
    case Calendar.MARCH:
        if (locale.getLanguage().equals("pt")) {
            return "Maro";
        }
        return "March";
    case Calendar.APRIL:
        if (locale.getLanguage().equals("pt")) {
            return "Abril";
        }
        return "April";
    case Calendar.MAY:
        if (locale.getLanguage().equals("pt")) {
            return "Maio";
        }
        return "May";
    case Calendar.JUNE:
        if (locale.getLanguage().equals("pt")) {
            return "Junho";
        }
        return "June";
    case Calendar.JULY:
        if (locale.getLanguage().equals("pt")) {
            return "Julho";
        }
        return "July";
    case Calendar.AUGUST:
        if (locale.getLanguage().equals("pt")) {
            return "Agosto";
        }
        return "August";
    case Calendar.SEPTEMBER:
        if (locale.getLanguage().equals("pt")) {
            return "Setembro";
        }
        return "September";
    case Calendar.OCTOBER:
        if (locale.getLanguage().equals("pt")) {
            return "Outubro";
        }
        return "October";
    case Calendar.NOVEMBER:
        if (locale.getLanguage().equals("pt")) {
            return "Novembro";
        }
        return "November";
    case Calendar.DECEMBER:
        if (locale.getLanguage().equals("pt")) {
            return "Dezembro";
        }
        return "December";
    case Calendar.UNDECIMBER:
        return "Undecember";
    default:
        return "Error";
    }
}

From source file:org.kuali.kfs.module.endow.document.service.impl.FrequencyDatesServiceImpl.java

/**
 * This method will check the current month and set the calendar to that month
 * @param month month to set the calendar
 * @return calendar calendar is set to the month selected
 *///from w w w.  j av  a 2s  .  co  m
protected Calendar setCalendarWithMonth(String month, Date currentDate) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(currentDate);
    int calendarMonth = Calendar.JANUARY;

    if (EndowConstants.FrequencyMonths.JANUARY.equalsIgnoreCase(month)) {
        calendarMonth = Calendar.JANUARY;
    } else if (EndowConstants.FrequencyMonths.FEBRUARY.equalsIgnoreCase(month)) {
        calendarMonth = Calendar.FEBRUARY;
    } else if (EndowConstants.FrequencyMonths.MARCH.equalsIgnoreCase(month)) {
        calendarMonth = Calendar.MARCH;
    } else if (EndowConstants.FrequencyMonths.APRIL.equalsIgnoreCase(month)) {
        calendarMonth = Calendar.APRIL;
    } else if (EndowConstants.FrequencyMonths.MAY.equalsIgnoreCase(month)) {
        calendarMonth = Calendar.MAY;
    } else if (EndowConstants.FrequencyMonths.JUNE.equalsIgnoreCase(month)) {
        calendarMonth = Calendar.JUNE;
    } else if (EndowConstants.FrequencyMonths.JULY.equalsIgnoreCase(month)) {
        calendarMonth = Calendar.JULY;
    } else if (EndowConstants.FrequencyMonths.AUGUST.equalsIgnoreCase(month)) {
        calendarMonth = Calendar.AUGUST;
    } else if (EndowConstants.FrequencyMonths.SEPTEMBER.equalsIgnoreCase(month)) {
        calendarMonth = Calendar.SEPTEMBER;
    } else if (EndowConstants.FrequencyMonths.OCTOBER.equalsIgnoreCase(month)) {
        calendarMonth = Calendar.OCTOBER;
    } else if (EndowConstants.FrequencyMonths.NOVEMBER.equalsIgnoreCase(month)) {
        calendarMonth = Calendar.NOVEMBER;
    } else if (EndowConstants.FrequencyMonths.DECEMBER.equalsIgnoreCase(month)) {
        calendarMonth = Calendar.DECEMBER;
    }

    calendar.set(Calendar.MONTH, calendarMonth);

    return calendar;
}

From source file:eionet.util.Util.java

/**
 * A method for calculating time difference in MILLISECONDS, between a date-time specified in input parameters and the current
 * date-time. <BR>//from w ww  .  j  a  v a 2 s .  c  om
 * This should be useful for calculating sleep time for code that has a certain schedule for execution.
 *
 * @param hour
 *            An integer from 0 to 23. If less than 0 or more than 23, then the closest next hour to current hour is taken.
 * @param date
 *            An integer from 1 to 31. If less than 1 or more than 31, then the closest next date to current date is taken.
 * @param month
 *            An integer from Calendar.JANUARY to Calendar.DECEMBER. If out of those bounds, the closest next month to current
 *            month is taken.
 * @param wday
 *            An integer from 1 to 7. If out of those bounds, the closest next weekday to weekday month is taken.
 * @param zone
 *            A String specifying the time-zone in which the calculations should be done. Please see Java documentation an
 *            allowable time-zones and formats.
 * @return Time difference in milliseconds.
 */
public static long timeDiff(int hour, int date, int month, int wday, String zone) {

    GregorianCalendar cal = new GregorianCalendar(TimeZone.getTimeZone(zone));
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);

    cal.setFirstDayOfWeek(Calendar.MONDAY);

    /*
     * here we force the hour to be one of the defualts if (hour < 0) hour = 0; if (hour > 23) hour = 23;
     */
    int cur_hour = cal.get(Calendar.HOUR);

    if (cal.get(Calendar.AM_PM) == Calendar.PM) {
        cur_hour = 12 + cur_hour;
    }

    // here we assume that every full hour is accepted
    /*
     * if (hour < 0 || hour > 23) { hour = cur_hour>=23 ? 0 : cur_hour + 1; }
     */

    if (wday >= 1 && wday <= 7) {

        int cur_wday = cal.get(Calendar.DAY_OF_WEEK);
        if (hour < 0 || hour > 23) {
            if (cur_wday != wday) {
                hour = 0;
            } else {
                hour = cur_hour >= 23 ? 0 : cur_hour + 1;
            }
        }

        int amount = wday - cur_wday;
        if (amount < 0) {
            amount = 7 + amount;
        }
        if (amount == 0 && cur_hour >= hour) {
            amount = 7;
        }
        cal.add(Calendar.DAY_OF_WEEK, amount);
    } else if (month >= Calendar.JANUARY && month <= Calendar.DECEMBER) { // do something about when every date is accepted
        if (date < 1) {
            date = 1;
        }
        if (date > 31) {
            date = 31;
        }
        int cur_month = cal.get(Calendar.MONTH);
        int amount = month - cur_month;
        if (amount < 0) {
            amount = 12 + amount;
        }
        if (amount == 0) {
            if (cal.get(Calendar.DATE) > date) {
                amount = 12;
            } else if (cal.get(Calendar.DATE) == date) {
                if (cur_hour >= hour) {
                    amount = 12;
                }
            }
        }
        // cal.set(Calendar.DATE, date);
        cal.add(Calendar.MONTH, amount);
        if (date > cal.getActualMaximum(Calendar.DATE)) {
            date = cal.getActualMaximum(Calendar.DATE);
        }
        cal.set(Calendar.DATE, date);
    } else if (date >= 1 && date <= 31) {
        int cur_date = cal.get(Calendar.DATE);
        if (cur_date > date) {
            cal.add(Calendar.MONTH, 1);
        } else if (cur_date == date) {
            if (cur_hour >= hour) {
                cal.add(Calendar.MONTH, 1);
            }
        }
        cal.set(Calendar.DATE, date);
    } else {
        if (hour < 0 || hour > 23) {
            hour = cur_hour >= 23 ? 0 : cur_hour + 1;
        }
        if (cur_hour >= hour) {
            cal.add(Calendar.DATE, 1);
        }
    }

    if (hour >= 12) {
        cal.set(Calendar.HOUR, hour - 12);
        cal.set(Calendar.AM_PM, Calendar.PM);
    } else {
        cal.set(Calendar.HOUR, hour);
        cal.set(Calendar.AM_PM, Calendar.AM);
    }

    Date nextDate = cal.getTime();
    Date currDate = new Date();

    long nextTime = cal.getTime().getTime();
    long currTime = (new Date()).getTime();

    return nextTime - currTime;
}

From source file:org.jfree.data.time.Week.java

/**
 * Returns the week preceding this one.  This method will return
 * <code>null</code> for some lower limit on the range of weeks (currently
 * week 1, 1900).  For week 1 of any year, the previous week is always week
 * 53, but week 53 may not contain any days (you should check for this).
 *
 * @return The preceding week (possibly <code>null</code>).
 *//*from ww w .j  a va  2 s .  c  o m*/
@Override
public RegularTimePeriod previous() {

    Week result;
    if (this.week != FIRST_WEEK_IN_YEAR) {
        result = new Week(this.week - 1, this.year);
    } else {
        // we need to work out if the previous year has 52 or 53 weeks...
        if (this.year > 1900) {
            int yy = this.year - 1;
            Calendar prevYearCalendar = Calendar.getInstance();
            prevYearCalendar.set(yy, Calendar.DECEMBER, 31);
            result = new Week(prevYearCalendar.getActualMaximum(Calendar.WEEK_OF_YEAR), yy);
        } else {
            result = null;
        }
    }
    return result;

}

From source file:gov.nih.nci.firebird.selenium2.tests.profile.credentials.TrainingCertificateCredentialsTest.java

private void checkForExpirationBeforeEffectiveDateError(final EditTrainingCertificateDialog certificateDialog)
        throws IOException {
    certificateDialog.getHelper().enterTrainingCertificateData(certificateWithExistingIssuer, certificateFile,
            false);/*from  w w  w  .  j  a  v a 2  s .  c o m*/
    Date today = new Date();
    certificateDialog.getHelper().setEffectiveDate(DateUtils.setMonths(today, Calendar.DECEMBER));
    certificateDialog.getHelper().setExpirationDate(DateUtils.setMonths(today, Calendar.OCTOBER));
    ExpectedValidationFailure expectedValidationFailure = new ExpectedValidationFailure(
            "error.expiration.date.before.effective");
    expectedValidationFailure.assertFailureOccurs(new FailingAction() {
        @Override
        public void perform() {
            certificateDialog.clickSave();
        }
    });
}

From source file:org.projectforge.common.DateHolder.java

/**
 * Sets the date to the beginning of the year (first day of year) and calls setBeginOfDay.
 * @see #setBeginOfDay()//from  ww w .  j a v a2s. c om
 */
public DateHolder setEndOfYear() {
    calendar.set(Calendar.MONTH, Calendar.DECEMBER);
    setEndOfMonth();
    return this;
}

From source file:edu.virginia.iath.snac.helpers.datastructures.SNACDate.java

/**
 * Gets the season dates for the given season and year.  Since the season dates only change
 * +/- 2 days across most of time, we store a lookup table and calculate them directly.
 * Winter starts in December of the previous year and ends in the given year.
 * /* ww  w . jav a 2  s . c o m*/
 * @param seasonStr Season to lookup (summer, spring, fall, autumn, winter)
 * @param year 4-digit year.
 * @return Array of Java Calendar objects containing the beginning and end dates of the season.
 */
private Calendar[] getSeasonDates(String seasonStr, int year) {
    Calendar[] seasonDates = new Calendar[2];
    String season = seasonStr.toLowerCase().trim();

    seasonDates[0] = Calendar.getInstance();
    seasonDates[1] = Calendar.getInstance();

    // Note: Java is WEIRD:  0 = JANUARY, 1 = FEBRUARY, ...
    if (season.equals("winter")) {
        seasonDates[0].set(year - 1, Calendar.DECEMBER, 21);
        seasonDates[1].set(year, Calendar.MARCH, 19);

    } else if (season.equals("spring")) {
        seasonDates[0].set(year, Calendar.MARCH, 20);
        seasonDates[1].set(year, Calendar.JUNE, 20);

    } else if (season.equals("fall") || season.equals("autumn")) {
        seasonDates[0].set(year, Calendar.SEPTEMBER, 22);
        seasonDates[1].set(year, Calendar.DECEMBER, 20);

    } else if (season.equals("summer")) {
        seasonDates[0].set(year, Calendar.JUNE, 21);
        seasonDates[1].set(year, Calendar.SEPTEMBER, 21);

    }

    return seasonDates;
}