Example usage for java.util Calendar JANUARY

List of usage examples for java.util Calendar JANUARY

Introduction

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

Prototype

int JANUARY

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

Click Source Link

Document

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

Usage

From source file:org.silverpeas.components.mailinglist.service.model.dao.MessageDaoIT.java

@Test
public void testListActivities() {
    MessageDao messageDao = getMessageDAO();
    Transaction.performInOne(() -> {/*ww  w . ja v a2 s .c o  m*/
        Calendar sentDate = Calendar.getInstance();
        sentDate.set(Calendar.MILLISECOND, 0);
        sentDate.set(Calendar.SECOND, 10);
        sentDate.set(Calendar.MINUTE, 3);
        sentDate.set(Calendar.HOUR, 10);
        sentDate.set(Calendar.DAY_OF_MONTH, 22);
        sentDate.set(Calendar.MONTH, Calendar.FEBRUARY);
        sentDate.set(Calendar.YEAR, 2008);
        Message message = new Message();
        message.setBody(textEmailContent);
        message.setComponentId("componentId");
        message.setModerated(true);
        message.setSummary(textEmailContent.substring(0, 200));
        message.setSender("bart.simpson@ilverpeas.com");
        message.setMessageId("0000001747b40c22");
        Date message1SentDate = sentDate.getTime();
        message.setSentDate(message1SentDate);
        message.setTitle("Simple text message");
        Attachment attachment = new Attachment();
        attachment.setPath(attachmentPath + "lemonde.html");
        attachment.setFileName("lemonde.html");
        attachment.setSize(10000);
        message.getAttachments().add(attachment);
        attachment = new Attachment();
        attachment.setPath(attachmentPath + "lemonde2.html");
        attachment.setFileName("lemonde2.html");
        attachment.setSize(20000);
        message.getAttachments().add(attachment);
        messageDao.saveMessage(message);
        message = new Message();
        message.setBody(textEmailContent);
        message.setComponentId("componentId");
        message.setModerated(true);
        message.setSummary(textEmailContent.substring(0, 200));
        message.setSender("bart.simpson@ilverpeas.com");
        message.setMessageId("0000001747b40c23");
        sentDate.add(Calendar.MONTH, -1);
        Date message2SentDate = sentDate.getTime();
        message.setSentDate(message2SentDate);
        message.setTitle("Simple text message 2");
        messageDao.saveMessage(message);

        message = new Message();
        message.setBody(textEmailContent);
        message.setComponentId("componentId");
        message.setModerated(true);
        message.setSummary(textEmailContent.substring(0, 200));
        message.setSender("bart.simpson@ilverpeas.com");
        message.setMessageId("0000001747b40c24");
        sentDate.add(Calendar.DAY_OF_MONTH, -1);
        Date message3SentDate = sentDate.getTime();
        message.setSentDate(message3SentDate);
        message.setTitle("Simple text message 3");
        messageDao.saveMessage(message);

        message = new Message();
        message.setBody(textEmailContent);
        message.setComponentId("componentId");
        message.setModerated(false);
        message.setSummary(textEmailContent.substring(0, 200));
        message.setSender("bart.simpson@ilverpeas.com");
        message.setMessageId("0000001747b40c25");
        sentDate.add(Calendar.DAY_OF_MONTH, -1);
        message.setSentDate(message3SentDate);
        message.setTitle("Simple text message 4");
        return messageDao.saveMessage(message);
    });

    List<Activity> activities = messageDao.listActivity("componentId");
    assertNotNull(activities);
    assertEquals(2, activities.size());
    for (final Activity activity : activities) {
        assertEquals(2008, activity.getYear());
        if (activity.getMonth() == Calendar.FEBRUARY) {
            assertEquals(1, activity.getNbMessages());
        } else {
            assertEquals(Calendar.JANUARY, activity.getMonth());
            assertEquals(2, activity.getNbMessages());
        }
    }
}

From source file:org.exist.xquery.modules.mail.SendEmailFunction.java

/**
 * Returns the current date and time in an RFC822 format, suitable for an email Date Header
 *
 * @return      RFC822 formated date and time as a String
 *///ww w  .ja  v  a2s  .  c o m
private String getDateRFC822() {

    String dateString = new String();
    final Calendar rightNow = Calendar.getInstance();

    //Day of the week
    switch (rightNow.get(Calendar.DAY_OF_WEEK)) {
    case Calendar.MONDAY:
        dateString = "Mon";
        break;

    case Calendar.TUESDAY:
        dateString = "Tue";
        break;

    case Calendar.WEDNESDAY:
        dateString = "Wed";
        break;

    case Calendar.THURSDAY:
        dateString = "Thu";
        break;

    case Calendar.FRIDAY:
        dateString = "Fri";
        break;

    case Calendar.SATURDAY:
        dateString = "Sat";
        break;

    case Calendar.SUNDAY:
        dateString = "Sun";
        break;
    }

    dateString += ", ";

    //Date
    dateString += rightNow.get(Calendar.DAY_OF_MONTH);
    dateString += " ";

    //Month
    switch (rightNow.get(Calendar.MONTH)) {
    case Calendar.JANUARY:
        dateString += "Jan";
        break;

    case Calendar.FEBRUARY:
        dateString += "Feb";
        break;

    case Calendar.MARCH:
        dateString += "Mar";
        break;

    case Calendar.APRIL:
        dateString += "Apr";
        break;

    case Calendar.MAY:
        dateString += "May";
        break;

    case Calendar.JUNE:
        dateString += "Jun";
        break;

    case Calendar.JULY:
        dateString += "Jul";
        break;

    case Calendar.AUGUST:
        dateString += "Aug";
        break;

    case Calendar.SEPTEMBER:
        dateString += "Sep";
        break;

    case Calendar.OCTOBER:
        dateString += "Oct";
        break;

    case Calendar.NOVEMBER:
        dateString += "Nov";
        break;

    case Calendar.DECEMBER:
        dateString += "Dec";
        break;
    }
    dateString += " ";

    //Year
    dateString += rightNow.get(Calendar.YEAR);
    dateString += " ";

    //Time
    String tHour = Integer.toString(rightNow.get(Calendar.HOUR_OF_DAY));
    if (tHour.length() == 1) {
        tHour = "0" + tHour;
    }

    String tMinute = Integer.toString(rightNow.get(Calendar.MINUTE));
    if (tMinute.length() == 1) {
        tMinute = "0" + tMinute;
    }

    String tSecond = Integer.toString(rightNow.get(Calendar.SECOND));
    if (tSecond.length() == 1) {
        tSecond = "0" + tSecond;
    }

    dateString += tHour + ":" + tMinute + ":" + tSecond + " ";

    //TimeZone Correction
    String tzSign = new String();
    String tzHours = new String();
    String tzMinutes = new String();

    final TimeZone thisTZ = rightNow.getTimeZone();
    int tzOffset = thisTZ.getOffset(rightNow.getTime().getTime()); //get timezone offset in milliseconds
    tzOffset = (tzOffset / 1000); //convert to seconds
    tzOffset = (tzOffset / 60); //convert to minutes

    //Sign
    if (tzOffset > 1) {
        tzSign = "+";
    } else {
        tzSign = "-";
        tzOffset *= -1;
    }

    //Calc Hours and Minutes?
    if (tzOffset >= 60) {
        //Minutes and Hours
        tzHours += (tzOffset / 60); //hours

        // do we need to prepend a 0
        if (tzHours.length() == 1) {
            tzHours = "0" + tzHours;
        }

        tzMinutes += (tzOffset % 60); //minutes

        // do we need to prepend a 0
        if (tzMinutes.length() == 1) {
            tzMinutes = "0" + tzMinutes;
        }
    } else {
        //Just Minutes
        tzHours = "00";
        tzMinutes += tzOffset;
        // do we need to prepend a 0
        if (tzMinutes.length() == 1) {
            tzMinutes = "0" + tzMinutes;
        }
    }

    dateString += tzSign + tzHours + tzMinutes;

    return dateString;
}

From source file:ec.gob.ceaaces.controller.FuncionarioController.java

/**
 * @return the fechaMin//from  w  w  w .  j  a  va  2s  .  c o m
 */
public Date getFechaMin() {
    Calendar cal = Calendar.getInstance();
    int anio = Calendar.getInstance().get(Calendar.YEAR) - 75;
    cal.set(anio, Calendar.JANUARY, 1);
    fechaMin = new Date(cal.getTimeInMillis());
    return fechaMin;
}

From source file:ec.gob.ceaaces.controller.FuncionarioController.java

/**
 * @return the fechaMax/*  ww  w . ja v  a 2 s .c  o m*/
 */

public Date getFechaMax() {
    Calendar cal = Calendar.getInstance();
    int anio = Calendar.getInstance().get(Calendar.YEAR) - 21;
    cal.set(anio, Calendar.JANUARY, 365);
    fechaMax = new Date(cal.getTimeInMillis());
    return fechaMax;
}

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:com.eleybourn.bookcatalogue.utils.Utils.java

public static String getMonthName(int month) {
    if (mMonthNameFormatter == null)
        mMonthNameFormatter = new SimpleDateFormat("MMMM");
    // Create static calendar if necessary
    if (mCalendar == null)
        mCalendar = Calendar.getInstance();
    // Assumes months are integers and in sequence...which everyone seems to assume
    mCalendar.set(Calendar.MONTH, month - 1 + java.util.Calendar.JANUARY);
    return mMonthNameFormatter.format(mCalendar.getTime());
}

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/*from   w ww  . j av  a 2  s  . c o 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//ww w .j  ava2  s .  co 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;

}