Example usage for java.util Calendar FEBRUARY

List of usage examples for java.util Calendar FEBRUARY

Introduction

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

Prototype

int FEBRUARY

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

Click Source Link

Document

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

Usage

From source file:eu.europa.fisheries.uvms.rules.service.AbstractFactTest.java

@Test
public void testDateComparison() {
    Date date1 = new GregorianCalendar(2017, Calendar.FEBRUARY, 10).getTime();
    Date date2 = new GregorianCalendar(2017, Calendar.FEBRUARY, 11).getTime();
    Date date3 = new GregorianCalendar(2017, Calendar.FEBRUARY, 11).getTime();
    Date date4 = new GregorianCalendar(2017, Calendar.FEBRUARY, 14).getTime();
    final boolean contains1 = fact.containsSameDayMoreTheOnce(Arrays.asList(date1, date2, date3, date4));
    System.out.println("List contains sameDate [true]: " + contains1);
    assertTrue(contains1);/* w w  w  .  j av a2  s  . c o  m*/

    date1 = new GregorianCalendar(2017, Calendar.FEBRUARY, 10).getTime();
    date2 = new GregorianCalendar(2017, Calendar.FEBRUARY, 12).getTime();
    date3 = new GregorianCalendar(2017, Calendar.FEBRUARY, 11).getTime();
    date4 = new GregorianCalendar(2017, Calendar.FEBRUARY, 14).getTime();
    final boolean contains2 = fact.containsSameDayMoreTheOnce(Arrays.asList(date1, date2, date3, date4));
    System.out.println("List contains sameDate [false]: " + contains2);
    assertFalse(contains2);

}

From source file:org.sakaiproject.sitestats.impl.chart.ChartServiceImpl.java

private Map<Integer, String> getMonthNamesMap() {
    monthNamesMap = new HashMap<Integer, String>();
    monthNamesMap.put(Calendar.JANUARY, msgs.getString("mo_jan"));
    monthNamesMap.put(Calendar.FEBRUARY, msgs.getString("mo_feb"));
    monthNamesMap.put(Calendar.MARCH, msgs.getString("mo_mar"));
    monthNamesMap.put(Calendar.APRIL, msgs.getString("mo_apr"));
    monthNamesMap.put(Calendar.MAY, msgs.getString("mo_may"));
    monthNamesMap.put(Calendar.JUNE, msgs.getString("mo_jun"));
    monthNamesMap.put(Calendar.JULY, msgs.getString("mo_jul"));
    monthNamesMap.put(Calendar.AUGUST, msgs.getString("mo_ago"));
    monthNamesMap.put(Calendar.SEPTEMBER, msgs.getString("mo_sep"));
    monthNamesMap.put(Calendar.OCTOBER, msgs.getString("mo_oct"));
    monthNamesMap.put(Calendar.NOVEMBER, msgs.getString("mo_nov"));
    monthNamesMap.put(Calendar.DECEMBER, msgs.getString("mo_dec"));
    return monthNamesMap;
}

From source file:org.apache.myfaces.custom.calendar.HtmlCalendarRenderer.java

public static String[] mapMonths(DateFormatSymbols symbols) {
    String[] months = new String[12];

    String[] localeMonths = symbols.getMonths();

    months[0] = localeMonths[Calendar.JANUARY];
    months[1] = localeMonths[Calendar.FEBRUARY];
    months[2] = localeMonths[Calendar.MARCH];
    months[3] = localeMonths[Calendar.APRIL];
    months[4] = localeMonths[Calendar.MAY];
    months[5] = localeMonths[Calendar.JUNE];
    months[6] = localeMonths[Calendar.JULY];
    months[7] = localeMonths[Calendar.AUGUST];
    months[8] = localeMonths[Calendar.SEPTEMBER];
    months[9] = localeMonths[Calendar.OCTOBER];
    months[10] = localeMonths[Calendar.NOVEMBER];
    months[11] = localeMonths[Calendar.DECEMBER];

    return months;
}

From source file:org.apache.myfaces.custom.calendar.HtmlCalendarRenderer.java

public static String[] mapShortMonths(DateFormatSymbols symbols) {
    String[] months = new String[12];

    String[] localeMonths = symbols.getShortMonths();

    months[0] = localeMonths[Calendar.JANUARY];
    months[1] = localeMonths[Calendar.FEBRUARY];
    months[2] = localeMonths[Calendar.MARCH];
    months[3] = localeMonths[Calendar.APRIL];
    months[4] = localeMonths[Calendar.MAY];
    months[5] = localeMonths[Calendar.JUNE];
    months[6] = localeMonths[Calendar.JULY];
    months[7] = localeMonths[Calendar.AUGUST];
    months[8] = localeMonths[Calendar.SEPTEMBER];
    months[9] = localeMonths[Calendar.OCTOBER];
    months[10] = localeMonths[Calendar.NOVEMBER];
    months[11] = localeMonths[Calendar.DECEMBER];

    return months;
}

From source file:com.icesoft.faces.component.selectinputdate.SelectInputDateRenderer.java

/**
 * @param symbols/* w w w. j av a  2 s .co m*/
 * @return months - String[] containing localized month names
 */
public static String[] mapMonths(DateFormatSymbols symbols) {
    String[] months = new String[12];

    String[] localeMonths = symbols.getMonths();

    months[0] = localeMonths[Calendar.JANUARY];
    months[1] = localeMonths[Calendar.FEBRUARY];
    months[2] = localeMonths[Calendar.MARCH];
    months[3] = localeMonths[Calendar.APRIL];
    months[4] = localeMonths[Calendar.MAY];
    months[5] = localeMonths[Calendar.JUNE];
    months[6] = localeMonths[Calendar.JULY];
    months[7] = localeMonths[Calendar.AUGUST];
    months[8] = localeMonths[Calendar.SEPTEMBER];
    months[9] = localeMonths[Calendar.OCTOBER];
    months[10] = localeMonths[Calendar.NOVEMBER];
    months[11] = localeMonths[Calendar.DECEMBER];

    return months;
}

From source file:org.celllife.idart.gui.patient.AddPatient.java

/**
 * checks if the given date is valid/*  w w  w.j  a  v a 2 s  . c o m*/
 * 
 * @param strDay
 *            String
 * @param strMonth
 *            String
 * @param strYear
 *            String
 * @return true if the date is valid else false
 */
public boolean dateOkay(String strDay, String strMonth, String strYear) {

    boolean result = false;

    try {

        int day = Integer.parseInt(strDay);

        // check the year
        if (strYear.length() != 4)
            return result;
        int year = Integer.parseInt(strYear);

        // get the int value for the string month (e.g. January)
        // int month = Integer.parseInt(strMonth);
        int month = -1;
        for (int i = 0; i < cmbDOBMonth.getItemCount(); i++) {
            if (strMonth.equals(cmbDOBMonth.getItem(i))) {
                month = i;
            }
        }

        switch (month) {
        case -1:
            result = false;
            break;
        case Calendar.FEBRUARY:
            if (day <= 29) {
                GregorianCalendar greg = new GregorianCalendar();
                if (day == 29 & greg.isLeapYear(year)) {
                    result = true;
                } else {
                    if (day == 29) {
                        result = false;
                    } else {
                        result = true;
                    }
                }
            } else {
                result = false;
            }
            break;
        case Calendar.JANUARY | Calendar.MARCH | Calendar.MAY | Calendar.JULY | Calendar.AUGUST
                | Calendar.OCTOBER | Calendar.DECEMBER:
            if (day <= 31) {
                result = true;
            } else {
                result = false;
            }
            break;
        default:
            result = true;
            break;
        }
    } catch (RuntimeException e) {
        e.printStackTrace();
    }

    return result;

}

From source file:com.l2jfree.gameserver.gameobjects.L2Player.java

/** @return true if birthday is on Feb 29th, false otherwise */
public final boolean isBirthdayIllegal() {
    return (getCreationDate().get(Calendar.MONTH) == Calendar.FEBRUARY
            && getCreationDate().get(Calendar.DAY_OF_MONTH) == 29);
}

From source file:com.clark.func.Functions.java

/**
 * <p>/*from  w  ww . j a v  a2s  .  co  m*/
 * Formats the time gap as a string, using the specified format. Padding the
 * left hand side of numbers with zeroes is optional and the timezone may be
 * specified.
 * </p>
 * 
 * <p>
 * When calculating the difference between months/days, it chooses to
 * calculate months first. So when working out the number of months and days
 * between January 15th and March 10th, it choose 1 month and 23 days gained
 * by choosing January->February = 1 month and then calculating days
 * forwards, and not the 1 month and 26 days gained by choosing March ->
 * February = 1 month and then calculating days backwards.
 * </p>
 * 
 * <p>
 * For more control, the <a href="http://joda-time.sf.net/">Joda-Time</a>
 * library is recommended.
 * </p>
 * 
 * @param startMillis
 *            the start of the duration
 * @param endMillis
 *            the end of the duration
 * @param format
 *            the way in which to format the duration
 * @param padWithZeros
 *            whether to pad the left hand side of numbers with 0's
 * @param timezone
 *            the millis are defined in
 * @return the time as a String
 */
public static String formatPeriod(long startMillis, long endMillis, String format, boolean padWithZeros,
        TimeZone timezone) {

    // Used to optimise for differences under 28 days and
    // called formatDuration(millis, format); however this did not work
    // over leap years.
    // TODO: Compare performance to see if anything was lost by
    // losing this optimisation.

    DurationToken[] tokens = lexx(format);

    // timezones get funky around 0, so normalizing everything to GMT
    // stops the hours being off
    Calendar start = Calendar.getInstance(timezone);
    start.setTime(new Date(startMillis));
    Calendar end = Calendar.getInstance(timezone);
    end.setTime(new Date(endMillis));

    // initial estimates
    int milliseconds = end.get(Calendar.MILLISECOND) - start.get(Calendar.MILLISECOND);
    int seconds = end.get(Calendar.SECOND) - start.get(Calendar.SECOND);
    int minutes = end.get(Calendar.MINUTE) - start.get(Calendar.MINUTE);
    int hours = end.get(Calendar.HOUR_OF_DAY) - start.get(Calendar.HOUR_OF_DAY);
    int days = end.get(Calendar.DAY_OF_MONTH) - start.get(Calendar.DAY_OF_MONTH);
    int months = end.get(Calendar.MONTH) - start.get(Calendar.MONTH);
    int years = end.get(Calendar.YEAR) - start.get(Calendar.YEAR);

    // each initial estimate is adjusted in case it is under 0
    while (milliseconds < 0) {
        milliseconds += 1000;
        seconds -= 1;
    }
    while (seconds < 0) {
        seconds += 60;
        minutes -= 1;
    }
    while (minutes < 0) {
        minutes += 60;
        hours -= 1;
    }
    while (hours < 0) {
        hours += 24;
        days -= 1;
    }

    if (DurationToken.containsTokenWithValue(tokens, DATE_M)) {
        while (days < 0) {
            days += start.getActualMaximum(Calendar.DAY_OF_MONTH);
            months -= 1;
            start.add(Calendar.MONTH, 1);
        }

        while (months < 0) {
            months += 12;
            years -= 1;
        }

        if (!DurationToken.containsTokenWithValue(tokens, DATE_y) && years != 0) {
            while (years != 0) {
                months += 12 * years;
                years = 0;
            }
        }
    } else {
        // there are no M's in the format string

        if (!DurationToken.containsTokenWithValue(tokens, DATE_y)) {
            int target = end.get(Calendar.YEAR);
            if (months < 0) {
                // target is end-year -1
                target -= 1;
            }

            while ((start.get(Calendar.YEAR) != target)) {
                days += start.getActualMaximum(Calendar.DAY_OF_YEAR) - start.get(Calendar.DAY_OF_YEAR);

                // Not sure I grok why this is needed, but the brutal tests
                // show it is
                if (start instanceof GregorianCalendar) {
                    if ((start.get(Calendar.MONTH) == Calendar.FEBRUARY)
                            && (start.get(Calendar.DAY_OF_MONTH) == 29)) {
                        days += 1;
                    }
                }

                start.add(Calendar.YEAR, 1);

                days += start.get(Calendar.DAY_OF_YEAR);
            }

            years = 0;
        }

        while (start.get(Calendar.MONTH) != end.get(Calendar.MONTH)) {
            days += start.getActualMaximum(Calendar.DAY_OF_MONTH);
            start.add(Calendar.MONTH, 1);
        }

        months = 0;

        while (days < 0) {
            days += start.getActualMaximum(Calendar.DAY_OF_MONTH);
            months -= 1;
            start.add(Calendar.MONTH, 1);
        }

    }

    // The rest of this code adds in values that
    // aren't requested. This allows the user to ask for the
    // number of months and get the real count and not just 0->11.

    if (!DurationToken.containsTokenWithValue(tokens, DATE_d)) {
        hours += 24 * days;
        days = 0;
    }
    if (!DurationToken.containsTokenWithValue(tokens, DATE_H)) {
        minutes += 60 * hours;
        hours = 0;
    }
    if (!DurationToken.containsTokenWithValue(tokens, DATE_m)) {
        seconds += 60 * minutes;
        minutes = 0;
    }
    if (!DurationToken.containsTokenWithValue(tokens, DATE_s)) {
        milliseconds += 1000 * seconds;
        seconds = 0;
    }

    return formatPeriodTime(tokens, years, months, days, hours, minutes, seconds, milliseconds, padWithZeros);
}