Example usage for java.util Calendar MAY

List of usage examples for java.util Calendar MAY

Introduction

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

Prototype

int MAY

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

Click Source Link

Document

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

Usage

From source file:Main.java

public static int getDaysInMonth(int month, int year) {
    switch (month) {
    case Calendar.JANUARY:
    case Calendar.MARCH:
    case Calendar.MAY:
    case Calendar.JULY:
    case Calendar.AUGUST:
    case Calendar.OCTOBER:
    case Calendar.DECEMBER:
        return 31;
    case Calendar.APRIL:
    case Calendar.JUNE:
    case Calendar.SEPTEMBER:
    case Calendar.NOVEMBER:
        return 30;
    case Calendar.FEBRUARY:
        return (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) ? 29 : 28;
    default://from ww w .  ja  v  a  2s  . co m
        throw new IllegalArgumentException("Invalid Month");
    }
}

From source file:Main.java

public static boolean is1erMai(Calendar calendar) {
    return calendar.get(Calendar.MONTH) == Calendar.MAY && calendar.get(Calendar.DATE) == 1;
}

From source file:Main.java

public static int stringMonthToInt(@NonNull final String month) {
    switch (month) {
    case "Jan":
        return Calendar.JANUARY;

    case "Feb":
        return Calendar.FEBRUARY;

    case "Mar":
        return Calendar.MARCH;

    case "Apr":
        return Calendar.APRIL;

    case "May":
        return Calendar.MAY;

    case "Jun":
        return Calendar.JUNE;

    case "Jul":
        return Calendar.JULY;

    case "Aug":
        return Calendar.AUGUST;

    case "Sep":
        return Calendar.SEPTEMBER;

    case "Oct":
        return Calendar.OCTOBER;

    case "Nov":
        return Calendar.NOVEMBER;

    case "Dec":
        return Calendar.DECEMBER;

    default:/*from   w w  w  .  j a  va  2 s  . c  om*/
        return 0;
    }
}

From source file:Util.java

private static int getMonthLastDate(int month, int year) {
    switch (month) {
    case Calendar.JANUARY:
    case Calendar.MARCH:
    case Calendar.MAY:
    case Calendar.JULY:
    case Calendar.AUGUST:
    case Calendar.OCTOBER:
    case Calendar.DECEMBER:
        return 31;

    case Calendar.APRIL:
    case Calendar.JUNE:
    case Calendar.SEPTEMBER:
    case Calendar.NOVEMBER:
        return 30;

    default: //  Calendar.FEBRUARY
        return year % 4 == 0 ? 29 : 28;
    }/*from   ww  w.  j  av  a  2s.  c  o m*/
}

From source file:Main.java

public static int getMonth(String str) {
    if (str.equals("jan"))
        return Calendar.JANUARY;
    if (str.equals("feb"))
        return Calendar.FEBRUARY;
    if (str.equals("mar"))
        return Calendar.MARCH;
    if (str.equals("apr"))
        return Calendar.APRIL;
    if (str.equals("may"))
        return Calendar.MAY;
    if (str.equals("jun"))
        return Calendar.JUNE;
    if (str.equals("jul"))
        return Calendar.JULY;
    if (str.equals("aug"))
        return Calendar.AUGUST;
    if (str.equals("sep"))
        return Calendar.SEPTEMBER;
    if (str.equals("oct"))
        return Calendar.OCTOBER;
    if (str.equals("nov"))
        return Calendar.NOVEMBER;
    if (str.equals("dec"))
        return Calendar.DECEMBER;

    return -1;/*w  w w  .ja  v  a2  s .co  m*/
}

From source file:Main.java

public static String getDateString() {
    String stringDate = "";
    Calendar calendar = Calendar.getInstance();
    int day = calendar.get(Calendar.DAY_OF_WEEK);
    int month = calendar.get(Calendar.MONTH);
    int dayInt = calendar.get(Calendar.DAY_OF_MONTH);
    switch (day) {
    case Calendar.SUNDAY:
        stringDate += "Sunday";
        break;/* w w w .  j  a  v  a  2 s .com*/

    case Calendar.MONDAY:
        stringDate += "Monday";
        break;

    case Calendar.TUESDAY:
        stringDate += "Tuesday";
        break;

    case Calendar.WEDNESDAY:
        stringDate += "Wednesday";
        break;

    case Calendar.THURSDAY:
        stringDate += "Thursday";
        break;

    case Calendar.FRIDAY:
        stringDate += "Friday";
        break;

    case Calendar.SATURDAY:
        stringDate += "Saturday";
        break;

    }
    switch (month) {
    case Calendar.JANUARY:
        stringDate += ", January";
        break;

    case Calendar.FEBRUARY:
        stringDate += ", February";
        break;

    case Calendar.MARCH:
        stringDate += ", March";
        break;

    case Calendar.APRIL:
        stringDate += ", April";
        break;

    case Calendar.MAY:
        stringDate += ", May";
        break;

    case Calendar.JUNE:
        stringDate += ", June";
        break;

    case Calendar.JULY:
        stringDate += ", July";
        break;

    case Calendar.AUGUST:
        stringDate += ", August";
        break;

    case Calendar.SEPTEMBER:
        stringDate += ", September";
        break;

    case Calendar.OCTOBER:
        stringDate += ", October";
        break;

    case Calendar.NOVEMBER:
        stringDate += ", November";
        break;

    case Calendar.DECEMBER:
        stringDate += ", December";
        break;

    }

    stringDate += (" " + dayInt);

    return stringDate;
}

From source file:Main.java

public static int getDaysInMonth(int month, int year) {
    switch (month) {
    case Calendar.JANUARY:
    case Calendar.MARCH:
    case Calendar.MAY:
    case Calendar.JULY:
    case Calendar.AUGUST:
    case Calendar.OCTOBER:
    case Calendar.DECEMBER:
        return 31;
    case Calendar.APRIL:
    case Calendar.JUNE:
    case Calendar.SEPTEMBER:
    case Calendar.NOVEMBER:
        return 30;
    case Calendar.FEBRUARY:
        return ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) ? 29 : 28;
    default://  w ww .ja v  a  2s  .c om
        throw new IllegalArgumentException("Invalid Month");
    }
}

From source file:Main.java

public static int getDaysInMonth(int month, int year) {
    switch (month) {
    case Calendar.JANUARY:
    case Calendar.MARCH:
    case Calendar.MAY:
    case Calendar.JULY:
    case Calendar.AUGUST:
    case Calendar.OCTOBER:
    case Calendar.DECEMBER:
        return 31;
    case Calendar.APRIL:
    case Calendar.JUNE:
    case Calendar.SEPTEMBER:
    case Calendar.NOVEMBER:
        return 30;
    case Calendar.FEBRUARY:
        return ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) ? 28 : 29;
    default://w ww  .j  a  v a2  s.co  m
        throw new IllegalArgumentException("Invalid Month");
    }
}

From source file:is.idega.idegaweb.egov.gumbo.licenses.SetDraganotveidiValidPeriod.java

public void execute(ExecutionContext executionContext) throws Exception {

    final Interval period;

    final Calendar now = Calendar.getInstance();
    now.set(Calendar.HOUR, 0);/*  w  w w  .  j  av a  2 s  .c  om*/
    now.set(Calendar.MINUTE, 0);
    now.set(Calendar.SECOND, 0);
    now.set(Calendar.MILLISECOND, 0);

    final Calendar mayStart = Calendar.getInstance();
    mayStart.set(now.get(Calendar.YEAR), Calendar.MAY, 1, 0, 0, 0);

    final Calendar augEnd = Calendar.getInstance();
    augEnd.set(now.get(Calendar.YEAR), Calendar.AUGUST, 31, 0, 0, 0);

    if (now.after(mayStart) && now.before(augEnd)) {

        period = new Interval(now.getTime(), augEnd.getTime());

    } else {

        period = findNearestPeriod(now);
    }

    executionContext.setVariable("date_validityFrom", period.getFrom());
    executionContext.setVariable("date_validityTo", period.getTo());
}

From source file:Main.java

/**
 * Get a set of holidays for a given year.
 *
 * @param year/*  w  ww .  ja v a  2 s  . c o  m*/
 *            The year to get holidays for.
 * @return The set of dates.
 */
private static Set<Date> getHolidaySet(int year) {
    if (holidays == null) {
        holidays = new HashMap<Integer, Set<Date>>();
    }
    if (!holidays.containsKey(year)) {
        Set<Date> yearSet = new HashSet<Date>();

        // Add set holidays.
        yearSet.add(getDate(1, Calendar.JANUARY, year));
        yearSet.add(getDate(1, Calendar.MAY, year));
        yearSet.add(getDate(17, Calendar.MAY, year));
        yearSet.add(getDate(25, Calendar.DECEMBER, year));
        yearSet.add(getDate(26, Calendar.DECEMBER, year));

        // Add movable holidays - based on easter day.
        Calendar easterDay = dateToCalendar(getEasterDay(year));

        // Sunday before easter.
        yearSet.add(rollGetDate(easterDay, -7));

        // Thurday before easter.
        yearSet.add(rollGetDate(easterDay, -3));

        // Friday before easter.
        yearSet.add(rollGetDate(easterDay, -2));

        // Easter day.
        yearSet.add(easterDay.getTime());

        // Second easter day.
        yearSet.add(rollGetDate(easterDay, 1));

        // "Kristi himmelfart" day.
        yearSet.add(rollGetDate(easterDay, 39));

        // "Pinse" day.
        yearSet.add(rollGetDate(easterDay, 49));

        // Second "Pinse" day.
        yearSet.add(rollGetDate(easterDay, 50));

        holidays.put(year, yearSet);
    }
    return holidays.get(year);
}