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:org.kuali.kfs.module.endow.document.service.impl.CurrentTaxLotServiceImpl.java

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

    int calendarMonth = 1;

    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:com.silverpeas.mailinglist.service.model.dao.TestMessageDao.java

@Test
public void testListMessagesOfMailingList() throws Exception {
    MessageDao messageDao = getMessageDAO();
    Calendar sentDate = Calendar.getInstance();
    sentDate.set(Calendar.YEAR, 2008);
    sentDate.set(Calendar.MONTH, Calendar.MARCH);
    sentDate.set(Calendar.DAY_OF_MONTH, 15);
    sentDate.set(Calendar.HOUR_OF_DAY, 9);
    sentDate.set(Calendar.MINUTE, 0);
    sentDate.set(Calendar.SECOND, 0);
    sentDate.set(Calendar.MILLISECOND, 0);
    Message message = new Message();
    message.setBody(textEmailContent);/*from  w w w .j a v a 2  s.co  m*/
    message.setComponentId("componentId");
    message.setModerated(true);
    message.setSummary(textEmailContent.substring(0, 200));
    message.setSender("bart.simpson@ilverpeas.com");
    message.setMessageId("0000001747b40c16");
    message.setSentDate(sentDate.getTime());
    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(false);
    message.setSummary(textEmailContent.substring(0, 200));
    message.setSender("bart.simpson@ilverpeas.com");
    message.setMessageId("0000001747b40c17");
    message.setSentDate(sentDate.getTime());
    message.setTitle("Simple text message 2");
    messageDao.saveMessage(message);

    sentDate.set(Calendar.YEAR, 2008);
    sentDate.set(Calendar.MONTH, Calendar.FEBRUARY);
    sentDate.set(Calendar.DAY_OF_MONTH, 17);
    sentDate.set(Calendar.HOUR_OF_DAY, 9);
    sentDate.set(Calendar.MINUTE, 0);
    sentDate.set(Calendar.SECOND, 0);
    sentDate.set(Calendar.MILLISECOND, 0);
    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("0000001747b40c18");
    message.setSentDate(sentDate.getTime());
    message.setTitle("Simple text message 3");
    messageDao.saveMessage(message);
    List messages = messageDao.listAllMessagesOfMailingList("componentId", 0, 10, orderByDate);
    assertNotNull(messages);
    assertEquals(3, messages.size());
    assertEquals(3, countRowsInTable("SC_MAILINGLIST_MESSAGE"));
    assertEquals(2, countRowsInTable("SC_MAILINGLIST_ATTACHMENT"));
    messages = messageDao.listAllMessagesOfMailingList("componentId", 0, 2, orderByDate);
    assertNotNull(messages);
    assertEquals(2, messages.size());
    messages = messageDao.listAllMessagesOfMailingList("componentId", 1, 2, orderByDate);
    assertNotNull(messages);
    assertEquals(1, messages.size());

    messages = messageDao.listDisplayableMessagesOfMailingList("componentId", -1, -1, 0, 10, orderByDate);
    assertNotNull(messages);
    assertEquals(2, messages.size());
    messages = messageDao.listDisplayableMessagesOfMailingList("componentId", -1, 2008, 0, 10, orderByDate);
    assertNotNull(messages);
    assertEquals(2, messages.size());
    messages = messageDao.listDisplayableMessagesOfMailingList("componentId", -1, 2007, 0, 10, orderByDate);
    assertNotNull(messages);
    assertEquals(0, messages.size());
    messages = messageDao.listDisplayableMessagesOfMailingList("componentId", Calendar.MARCH, 2008, 0, 10,
            orderByDate);
    assertNotNull(messages);
    assertEquals(1, messages.size());
    messages = messageDao.listDisplayableMessagesOfMailingList("componentId", Calendar.FEBRUARY, 2008, 0, 10,
            orderByDate);
    assertNotNull(messages);
    assertEquals(1, messages.size());
    messages = messageDao.listDisplayableMessagesOfMailingList("componentId", -1, -1, 0, 1, orderByDate);
    assertNotNull(messages);
    assertEquals(1, messages.size());
    messages = messageDao.listDisplayableMessagesOfMailingList("componentId", -1, -1, 1, 1, orderByDate);
    assertNotNull(messages);
    assertEquals(1, messages.size());

    messages = messageDao.listUnmoderatedMessagesOfMailingList("componentId", 0, 10, orderByDate);
    assertNotNull(messages);
    assertEquals(1, messages.size());
    messages = messageDao.listUnmoderatedMessagesOfMailingList("componentId", 0, 1, orderByDate);
    assertNotNull(messages);
    assertEquals(1, messages.size());
    messages = messageDao.listUnmoderatedMessagesOfMailingList("componentId", 1, 1, orderByDate);
    assertNotNull(messages);
    assertEquals(0, messages.size());

    assertEquals(3, countRowsInTable("SC_MAILINGLIST_MESSAGE"));
    assertEquals(2, countRowsInTable("SC_MAILINGLIST_ATTACHMENT"));

    long unmoderatedMessages = messageDao.listTotalNumberOfUnmoderatedMessages("componentId");
    assertEquals(1, unmoderatedMessages);
    long displayabledMessages = messageDao.listTotalNumberOfDisplayableMessages("componentId");
    assertEquals(2, displayabledMessages);
    long totalMessages = messageDao.listTotalNumberOfMessages("componentId");
    assertEquals(3, totalMessages);

}

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

@Test
public void testListMessagesOfMailingList() throws Exception {
    MessageDao messageDao = getMessageDAO();
    Calendar sentDate = Calendar.getInstance();
    Transaction.performInOne(() -> {//from ww  w.j  a va2 s .  c  om

        sentDate.set(Calendar.YEAR, 2008);
        sentDate.set(Calendar.MONTH, Calendar.MARCH);
        sentDate.set(Calendar.DAY_OF_MONTH, 15);
        sentDate.set(Calendar.HOUR_OF_DAY, 9);
        sentDate.set(Calendar.MINUTE, 0);
        sentDate.set(Calendar.SECOND, 0);
        sentDate.set(Calendar.MILLISECOND, 0);
        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("0000001747b40c16");
        message.setSentDate(sentDate.getTime());
        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(false);
        message.setSummary(textEmailContent.substring(0, 200));
        message.setSender("bart.simpson@ilverpeas.com");
        message.setMessageId("0000001747b40c17");
        message.setSentDate(sentDate.getTime());
        message.setTitle("Simple text message 2");
        messageDao.saveMessage(message);

        sentDate.set(Calendar.YEAR, 2008);
        sentDate.set(Calendar.MONTH, Calendar.FEBRUARY);
        sentDate.set(Calendar.DAY_OF_MONTH, 17);
        sentDate.set(Calendar.HOUR_OF_DAY, 9);
        sentDate.set(Calendar.MINUTE, 0);
        sentDate.set(Calendar.SECOND, 0);
        sentDate.set(Calendar.MILLISECOND, 0);
        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("0000001747b40c18");
        message.setSentDate(sentDate.getTime());
        message.setTitle("Simple text message 3");
        messageDao.saveMessage(message);
        return null;
    });
    List messages = messageDao.listAllMessagesOfMailingList("componentId", 0, 10, orderByDate);
    assertNotNull(messages);
    assertEquals(3, messages.size());
    assertEquals(3, countRowsInTable("SC_MAILINGLIST_MESSAGE"));
    assertEquals(2, countRowsInTable("SC_MAILINGLIST_ATTACHMENT"));
    messages = messageDao.listAllMessagesOfMailingList("componentId", 0, 2, orderByDate);
    assertNotNull(messages);
    assertEquals(2, messages.size());
    messages = messageDao.listAllMessagesOfMailingList("componentId", 1, 2, orderByDate);
    assertNotNull(messages);
    assertEquals(1, messages.size());

    messages = messageDao.listDisplayableMessagesOfMailingList("componentId", -1, -1, 0, 10, orderByDate);
    assertNotNull(messages);
    assertEquals(2, messages.size());
    messages = messageDao.listDisplayableMessagesOfMailingList("componentId", -1, 2008, 0, 10, orderByDate);
    assertNotNull(messages);
    assertEquals(2, messages.size());
    messages = messageDao.listDisplayableMessagesOfMailingList("componentId", -1, 2007, 0, 10, orderByDate);
    assertNotNull(messages);
    assertEquals(0, messages.size());
    messages = messageDao.listDisplayableMessagesOfMailingList("componentId", Calendar.MARCH, 2008, 0, 10,
            orderByDate);
    assertNotNull(messages);
    assertEquals(1, messages.size());
    messages = messageDao.listDisplayableMessagesOfMailingList("componentId", Calendar.FEBRUARY, 2008, 0, 10,
            orderByDate);
    assertNotNull(messages);
    assertEquals(1, messages.size());
    messages = messageDao.listDisplayableMessagesOfMailingList("componentId", -1, -1, 0, 1, orderByDate);
    assertNotNull(messages);
    assertEquals(1, messages.size());
    messages = messageDao.listDisplayableMessagesOfMailingList("componentId", -1, -1, 1, 1, orderByDate);
    assertNotNull(messages);
    assertEquals(1, messages.size());

    messages = messageDao.listUnmoderatedMessagesOfMailingList("componentId", 0, 10, orderByDate);
    assertNotNull(messages);
    assertEquals(1, messages.size());
    messages = messageDao.listUnmoderatedMessagesOfMailingList("componentId", 0, 1, orderByDate);
    assertNotNull(messages);
    assertEquals(1, messages.size());
    messages = messageDao.listUnmoderatedMessagesOfMailingList("componentId", 1, 1, orderByDate);
    assertNotNull(messages);
    assertEquals(0, messages.size());

    assertEquals(3, countRowsInTable("SC_MAILINGLIST_MESSAGE"));
    assertEquals(2, countRowsInTable("SC_MAILINGLIST_ATTACHMENT"));

    long unmoderatedMessages = messageDao.listTotalNumberOfUnmoderatedMessages("componentId");
    assertEquals(1, unmoderatedMessages);
    long displayabledMessages = messageDao.listTotalNumberOfDisplayableMessages("componentId");
    assertEquals(2, displayabledMessages);
    long totalMessages = messageDao.listTotalNumberOfMessages("componentId");
    assertEquals(3, totalMessages);

}

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

/**
 * This method will check the current month and set the calendar to that month
 * //from w  w  w.ja v  a  2s .  co m
 * @param month, dayOfMonth month to set the calendar, dayOfMonth day of the month to set to
 * @return calendar calendar is set to the month selected
 */
protected void setCalendarWithDays(Calendar calendar, String dayOfMonth) {
    int dayInMonthToSet;
    int calendarMonth = calendar.get(Calendar.MONTH);

    if (StringUtils.equalsIgnoreCase(dayOfMonth, EndowConstants.FrequencyMonthly.MONTH_END)) { // month end for the month so
        // need to get max days...
        dayInMonthToSet = checkMaximumDaysInMonth(calendar.get(Calendar.MONTH));
    } else {
        dayInMonthToSet = Integer.parseInt(dayOfMonth);

        if (dayInMonthToSet > 29 && calendarMonth == Calendar.FEBRUARY) {
            dayInMonthToSet = checkMaximumDaysInFebruary();
        } else if (dayInMonthToSet > 30 && (calendarMonth == Calendar.APRIL || calendarMonth == Calendar.JUNE
                || calendarMonth == Calendar.SEPTEMBER || calendarMonth == Calendar.NOVEMBER)) {
            dayInMonthToSet = 30;
            dayInMonthToSet = checkMaximumDaysInMonth(calendarMonth);
        }
    }

    calendar.set(Calendar.DAY_OF_MONTH, dayInMonthToSet);
}

From source file:com.frey.repo.DateUtil.java

/**
 * ?//from   w  ww  .j av a2s.  c o  m
 */
public static int getPassDayOfSeason(Date date) {
    int day = 0;

    Date[] seasonDates = getSeasonDate(date);

    Calendar c = Calendar.getInstance();
    c.setTime(date);
    int month = c.get(Calendar.MONTH);

    if (month == Calendar.JANUARY || month == Calendar.APRIL || month == Calendar.JULY
            || month == Calendar.OCTOBER) {//
        day = getPassDayOfMonth(seasonDates[0]);
    } else if (month == Calendar.FEBRUARY || month == Calendar.MAY || month == Calendar.AUGUST
            || month == Calendar.NOVEMBER) {//
        day = getDayOfMonth(seasonDates[0]) + getPassDayOfMonth(seasonDates[1]);
    } else if (month == Calendar.MARCH || month == Calendar.JUNE || month == Calendar.SEPTEMBER
            || month == Calendar.DECEMBER) {//
        day = getDayOfMonth(seasonDates[0]) + getDayOfMonth(seasonDates[1]) + getPassDayOfMonth(seasonDates[2]);
    }
    return day;
}

From source file:com.frey.repo.DateUtil.java

/**
 * ?//  ww w  .ja v a2  s.c om
 */
public static Date[] getSeasonDate(Date date) {
    Date[] season = new Date[3];

    Calendar c = Calendar.getInstance();
    c.setTime(date);

    int nSeason = getSeason(date);
    if (nSeason == 1) {//
        c.set(Calendar.MONTH, Calendar.JANUARY);
        season[0] = c.getTime();
        c.set(Calendar.MONTH, Calendar.FEBRUARY);
        season[1] = c.getTime();
        c.set(Calendar.MONTH, Calendar.MARCH);
        season[2] = c.getTime();
    } else if (nSeason == 2) {//
        c.set(Calendar.MONTH, Calendar.APRIL);
        season[0] = c.getTime();
        c.set(Calendar.MONTH, Calendar.MAY);
        season[1] = c.getTime();
        c.set(Calendar.MONTH, Calendar.JUNE);
        season[2] = c.getTime();
    } else if (nSeason == 3) {//
        c.set(Calendar.MONTH, Calendar.JULY);
        season[0] = c.getTime();
        c.set(Calendar.MONTH, Calendar.AUGUST);
        season[1] = c.getTime();
        c.set(Calendar.MONTH, Calendar.SEPTEMBER);
        season[2] = c.getTime();
    } else if (nSeason == 4) {//
        c.set(Calendar.MONTH, Calendar.OCTOBER);
        season[0] = c.getTime();
        c.set(Calendar.MONTH, Calendar.NOVEMBER);
        season[1] = c.getTime();
        c.set(Calendar.MONTH, Calendar.DECEMBER);
        season[2] = c.getTime();
    }
    return season;
}

From source file:com.silverpeas.mailinglist.service.model.dao.TestMessageDao.java

@Test
public void testListActivities() {
    MessageDao messageDao = getMessageDAO();
    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);/*ww  w  . j a v  a2  s  .  co m*/
    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");
    messageDao.saveMessage(message);
    List activities = messageDao.listActivity("componentId");
    assertNotNull(activities);
    assertEquals(2, activities.size());
    Iterator iter = activities.iterator();
    while (iter.hasNext()) {
        Activity activity = (Activity) iter.next();
        assertEquals(activity.getYear(), 2008);
        if (activity.getMonth() == Calendar.FEBRUARY) {
            assertEquals(1, activity.getNbMessages());
        } else {
            assertEquals(Calendar.JANUARY, activity.getMonth());
            assertEquals(2, activity.getNbMessages());
        }
    }
}

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

@Test
public void testFindValueRange2() {
    TimeZone tzone = TimeZone.getTimeZone("Europe/London");
    Calendar calendar = new GregorianCalendar(tzone, Locale.UK);
    calendar.clear();/*from w w w . j  a  va 2s . c  om*/
    calendar.set(2014, Calendar.FEBRUARY, 23, 6, 0);
    long start = calendar.getTimeInMillis();
    calendar.clear();
    calendar.set(2014, Calendar.FEBRUARY, 24, 18, 0);
    long end = calendar.getTimeInMillis();
    Range range = new Range(start, end);

    TimeSeries ts = new TimeSeries("Time Series");
    assertNull(ts.findValueRange(range, TimePeriodAnchor.START, tzone));
    assertNull(ts.findValueRange(range, TimePeriodAnchor.MIDDLE, tzone));
    assertNull(ts.findValueRange(range, TimePeriodAnchor.END, tzone));

    ts.add(new Day(23, 2, 2014), 5.0);
    assertTrue(ts.findValueRange(range, TimePeriodAnchor.START, tzone).isNaNRange());
    assertEquals(new Range(5.0, 5.0), ts.findValueRange(range, TimePeriodAnchor.MIDDLE, tzone));
    assertEquals(new Range(5.0, 5.0), ts.findValueRange(range, TimePeriodAnchor.END, tzone));

    ts.add(new Day(24, 2, 2014), 6.0);
    assertEquals(new Range(6.0, 6.0), ts.findValueRange(range, TimePeriodAnchor.START, tzone));
    assertEquals(new Range(5.0, 6.0), ts.findValueRange(range, TimePeriodAnchor.MIDDLE, tzone));
    assertEquals(new Range(5.0, 5.0), ts.findValueRange(range, TimePeriodAnchor.END, tzone));

    ts.clear();
    ts.add(new Day(24, 2, 2014), null);
    assertTrue(ts.findValueRange(range, TimePeriodAnchor.START, tzone).isNaNRange());
    assertTrue(ts.findValueRange(range, TimePeriodAnchor.MIDDLE, tzone).isNaNRange());
    assertTrue(ts.findValueRange(range, TimePeriodAnchor.END, tzone).isNaNRange());
}

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

@Test
public void testListActivities() {
    MessageDao messageDao = getMessageDAO();
    Transaction.performInOne(() -> {/*from  w w w  .j  a  v  a2s  .  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
 *///from ww w.j av  a 2s. com
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;
}