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:util.MyUtils.java

public static String getMonthString(int month) {
    switch (month - 1) {
    case Calendar.JANUARY:
        return "Jan";
    case Calendar.FEBRUARY:
        return "Feb";
    case Calendar.MARCH:
        return "Mar";
    case Calendar.APRIL:
        return "Apr";
    case Calendar.MAY:
        return "May";
    case Calendar.JUNE:
        return "Jun";
    case Calendar.JULY:
        return "Jul";
    case Calendar.AUGUST:
        return "Aug";
    case Calendar.SEPTEMBER:
        return "Sep";
    case Calendar.OCTOBER:
        return "Oct";
    case Calendar.NOVEMBER:
        return "Nov";
    case Calendar.DECEMBER:
        return "Dec";
    }// w ww  .  j  a v a  2 s  .co  m
    return "";
}

From source file:net.orpiske.dcd.collector.dataset.impl.MBoxDataSetTest.java

@Test
public void testOneDigitDateWithoutTZ() {
    Data data = dataList.get(2);//from   ww  w .j  a  v a2  s  . com

    Date date = data.getDate();
    Calendar cal = Calendar.getInstance();
    cal.setTime(date);

    assertEquals("The year is incorrect", 2013, cal.get(Calendar.YEAR));
    assertEquals("The month is incorrect", Calendar.MAY, cal.get(Calendar.MONTH));
    assertEquals("The day is incorrect", 1, cal.get(Calendar.DAY_OF_MONTH));
}

From source file:org.metawidget.swing.widgetprocessor.binding.beanutils.BeanUtilsBindingProcessorTest.java

public void testScalaBinding() throws Exception {

    // Model/*from  w  w w.  ja  va 2  s. com*/

    Date dateFirst = new GregorianCalendar(1975, Calendar.APRIL, 9).getTime();

    ScalaFoo scalaFoo = new ScalaFoo();
    scalaFoo.bar_$eq(dateFirst);
    ScalaFoo scalaFoo2 = new ScalaFoo();
    scalaFoo.nestedFoo = scalaFoo2;
    ScalaFoo scalaFoo3 = new ScalaFoo();
    scalaFoo2.nestedFoo = scalaFoo3;
    scalaFoo3.bar_$eq(new GregorianCalendar(1976, Calendar.MAY, 16).getTime());

    // BeanUtilsBinding

    ConvertUtils.register(new DateConverter(DATE_FORMAT), Date.class);

    // Inspect

    SwingMetawidget metawidget = new SwingMetawidget();
    metawidget.addWidgetProcessor(new BeanUtilsBindingProcessor(
            new BeanUtilsBindingProcessorConfig().setPropertyStyle(new ScalaPropertyStyle())));
    BaseObjectInspectorConfig config = new BaseObjectInspectorConfig()
            .setPropertyStyle(new ScalaPropertyStyle());
    metawidget.setInspector(new PropertyTypeInspector(config));
    metawidget.setToInspect(scalaFoo);

    // Loading

    JTextField textField = (JTextField) metawidget.getComponent(1);
    DateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT);
    assertEquals(dateFormat.format(dateFirst), textField.getText());
    JLabel label = (JLabel) metawidget.getComponent(5);
    assertEquals("Not settable", label.getText());

    JTextField nestedTextField = (JTextField) ((SwingMetawidget) metawidget.getComponent(3)).getComponent(1);
    assertEquals("", nestedTextField.getText());

    JTextField nestedNestedTextField = (JTextField) ((SwingMetawidget) ((SwingMetawidget) metawidget
            .getComponent(3)).getComponent(3)).getComponent(1);
    assertEquals(dateFormat.format(scalaFoo3.bar()), nestedNestedTextField.getText());

    // Saving

    Date dateSecond = new GregorianCalendar(1976, Calendar.MAY, 10).getTime();
    textField.setText(dateFormat.format(dateSecond));
    nestedNestedTextField.setText(dateFormat.format(new GregorianCalendar(1977, Calendar.JUNE, 17).getTime()));
    metawidget.getWidgetProcessor(BeanUtilsBindingProcessor.class).save(metawidget);

    GregorianCalendar calendar = new GregorianCalendar();
    calendar.setTime(scalaFoo.bar());
    assertEquals(1976, calendar.get(Calendar.YEAR));
    assertEquals(null, scalaFoo2.bar());
    calendar.setTime(scalaFoo3.bar());
    assertEquals(1977, calendar.get(Calendar.YEAR));

    // Rebinding

    textField = (JTextField) metawidget.getComponent(1);
    assertEquals(dateFormat.format(dateSecond), textField.getText());

    scalaFoo.bar_$eq(dateFirst);
    metawidget.getWidgetProcessor(BeanUtilsBindingProcessor.class).rebind(scalaFoo, metawidget);

    textField = (JTextField) metawidget.getComponent(1);
    assertEquals(dateFormat.format(dateFirst), textField.getText());
}

From source file:org.openmrs.module.kenyaui.KenyaUiUtilsTest.java

/**
 * @see KenyaUiUtils#formatDate(java.util.Date)
 * @verifies format date as a string without time information
 *///from w  ww.  j av  a  2  s  . c  o m
@Test
public void formatDate_shouldFormatDateWithoutTime() throws Exception {
    GregorianCalendar cal = new GregorianCalendar();
    cal.set(Calendar.YEAR, 1981);
    cal.set(Calendar.MONTH, Calendar.MAY);
    cal.set(Calendar.DAY_OF_MONTH, 28);
    cal.set(Calendar.HOUR, 7);
    cal.set(Calendar.MINUTE, 30);
    cal.set(Calendar.SECOND, 12);

    Assert.assertThat(kenyaUi.formatDate(cal.getTime()), is("28-May-1981"));
}

From source file:org.pivotal.gemfire.cache.CacheRegionQueryUsingToDateTest.java

@Before
public void setupPeople() {
    Region<Long, Person> localPeople = gemfireCache.getRegion("/People");

    put(localPeople, createPerson("Jon", "Doe", createDate(1979, Calendar.MAY, 15)));
    put(localPeople, createPerson("Jane", "Doe", createDate(1981, Calendar.APRIL, 21)));
    put(localPeople, createPerson("Pie", "Doe", createDate(1997, Calendar.NOVEMBER, 22)));
    put(localPeople, createPerson("Cookie", "Doe", createDate(2008, Calendar.AUGUST, 16)));
    put(localPeople, createPerson("Sour", "Doe", createDate(2012, Calendar.DECEMBER, 1)));
    put(localPeople, createPerson("Jack", "Handy", createDate(1977, Calendar.MAY, 10)));
    put(localPeople, createPerson("Sandy", "Handy", createDate(1977, Calendar.MARCH, 3)));
    put(localPeople, createPerson("Jack", "Black", createDate(1972, Calendar.JUNE, 26)));
    put(localPeople, createPerson("Ben", "Dover", createDate(1969, Calendar.MAY, 5)));
    put(localPeople, createPerson("Ima", "Pigg", createDate(1975, Calendar.JULY, 17)));

    assertThat(localPeople.size(), is(equalTo(10)));
}

From source file:net.orpiske.dcd.collector.dataset.impl.MBoxDataSetTest.java

@Test
public void testTwoDigitDateWithoutTZ() {
    Data data = dataList.get(3);/*from  ww w.  j  a va 2 s.c o m*/

    Date date = data.getDate();
    Calendar cal = Calendar.getInstance();
    cal.setTime(date);

    assertEquals("The year is incorrect", 2013, cal.get(Calendar.YEAR));
    assertEquals("The month is incorrect", Calendar.MAY, cal.get(Calendar.MONTH));
    assertEquals("The day is incorrect", 10, cal.get(Calendar.DAY_OF_MONTH));
}

From source file:Negocio.Produccion.Planificacion.GanttDemo.java

/**
 * Creates a sample dataset for a Gantt chart.
 *
 * @return The dataset./*from   w w w. j  a v  a  2s . c  o  m*/
 */
public static IntervalCategoryDataset createDataset() {

    final TaskSeries s1 = new TaskSeries("Scheduled");
    s1.add(new Task("Write Proposal",
            new SimpleTimePeriod(date(1, Calendar.APRIL, 2001), date(5, Calendar.APRIL, 2001))));
    s1.add(new Task("Obtain Approval",
            new SimpleTimePeriod(date(9, Calendar.APRIL, 2001), date(9, Calendar.APRIL, 2001))));
    s1.add(new Task("Requirements Analysis",
            new SimpleTimePeriod(date(10, Calendar.APRIL, 2001), date(5, Calendar.MAY, 2001))));
    s1.add(new Task("Design Phase",
            new SimpleTimePeriod(date(6, Calendar.MAY, 2001), date(30, Calendar.MAY, 2001))));
    s1.add(new Task("Design Signoff",
            new SimpleTimePeriod(date(2, Calendar.JUNE, 2001), date(2, Calendar.JUNE, 2001))));
    s1.add(new Task("Alpha Implementation",
            new SimpleTimePeriod(date(3, Calendar.JUNE, 2001), date(31, Calendar.JULY, 2001))));
    s1.add(new Task("Design Review",
            new SimpleTimePeriod(date(1, Calendar.AUGUST, 2001), date(8, Calendar.AUGUST, 2001))));
    s1.add(new Task("Revised Design Signoff",
            new SimpleTimePeriod(date(10, Calendar.AUGUST, 2001), date(10, Calendar.AUGUST, 2001))));
    s1.add(new Task("Beta Implementation",
            new SimpleTimePeriod(date(12, Calendar.AUGUST, 2001), date(12, Calendar.SEPTEMBER, 2001))));
    s1.add(new Task("Testing",
            new SimpleTimePeriod(date(13, Calendar.SEPTEMBER, 2001), date(31, Calendar.OCTOBER, 2001))));
    s1.add(new Task("Final Implementation",
            new SimpleTimePeriod(date(1, Calendar.NOVEMBER, 2001), date(15, Calendar.NOVEMBER, 2001))));
    s1.add(new Task("Signoff",
            new SimpleTimePeriod(date(28, Calendar.NOVEMBER, 2001), date(30, Calendar.NOVEMBER, 2001))));

    final TaskSeries s2 = new TaskSeries("Actual");
    s2.add(new Task("Write Proposal",
            new SimpleTimePeriod(date(1, Calendar.APRIL, 2001), date(5, Calendar.APRIL, 2001))));
    s2.add(new Task("Obtain Approval",
            new SimpleTimePeriod(date(9, Calendar.APRIL, 2001), date(9, Calendar.APRIL, 2001))));
    s2.add(new Task("Requirements Analysis",
            new SimpleTimePeriod(date(10, Calendar.APRIL, 2001), date(15, Calendar.MAY, 2001))));
    s2.add(new Task("Design Phase",
            new SimpleTimePeriod(date(15, Calendar.MAY, 2001), date(17, Calendar.JUNE, 2001))));
    s2.add(new Task("Design Signoff",
            new SimpleTimePeriod(date(30, Calendar.JUNE, 2001), date(30, Calendar.JUNE, 2001))));
    s2.add(new Task("Alpha Implementation",
            new SimpleTimePeriod(date(1, Calendar.JULY, 2001), date(12, Calendar.SEPTEMBER, 2001))));
    s2.add(new Task("Design Review",
            new SimpleTimePeriod(date(12, Calendar.SEPTEMBER, 2001), date(22, Calendar.SEPTEMBER, 2001))));
    s2.add(new Task("Revised Design Signoff",
            new SimpleTimePeriod(date(25, Calendar.SEPTEMBER, 2001), date(27, Calendar.SEPTEMBER, 2001))));
    s2.add(new Task("Beta Implementation",
            new SimpleTimePeriod(date(27, Calendar.SEPTEMBER, 2001), date(30, Calendar.OCTOBER, 2001))));
    s2.add(new Task("Testing",
            new SimpleTimePeriod(date(31, Calendar.OCTOBER, 2001), date(17, Calendar.NOVEMBER, 2001))));
    s2.add(new Task("Final Implementation",
            new SimpleTimePeriod(date(18, Calendar.NOVEMBER, 2001), date(5, Calendar.DECEMBER, 2001))));
    s2.add(new Task("Signoff",
            new SimpleTimePeriod(date(10, Calendar.DECEMBER, 2001), date(11, Calendar.DECEMBER, 2001))));

    final TaskSeriesCollection collection = new TaskSeriesCollection();
    collection.add(s1);
    collection.add(s2);

    return collection;
}

From source file:org.openmrs.module.kenyaui.KenyaUiUtilsTest.java

/**
 * @see KenyaUiUtils#formatDateParam(java.util.Date)
 * @verifies format null date as empty string
 *///from   ww  w . j a v  a  2  s.co m
@Test
public void formatDateParam_shouldFormatDateAsISO8601() throws Exception {
    GregorianCalendar cal = new GregorianCalendar();
    cal.set(Calendar.YEAR, 1981);
    cal.set(Calendar.MONTH, Calendar.MAY);
    cal.set(Calendar.DAY_OF_MONTH, 28);
    cal.set(Calendar.HOUR, 7);
    cal.set(Calendar.MINUTE, 30);
    cal.set(Calendar.SECOND, 12);

    Assert.assertThat(kenyaUi.formatDateParam(cal.getTime()), is("1981-05-28"));
}

From source file:com.mycompany.CRMFly.serviceLayer.ClientsServiceImpl.java

@Transactional
public Map<Date, Double> getSumsFotDates(Clients client) {
    Long id = client.getId();//from  ww  w. ja v  a  2 s  . com

    Calendar calendar = new GregorianCalendar();
    Integer monthDifference = 0;
    if (calendar.get(Calendar.MONTH) == Calendar.JANUARY || calendar.get(Calendar.MONTH) == Calendar.APRIL
            || calendar.get(Calendar.MONTH) == Calendar.JULY
            || calendar.get(Calendar.MONTH) == Calendar.OCTOBER) {
        monthDifference = 0;
    } else if (calendar.get(Calendar.MONTH) == Calendar.FEBRUARY || calendar.get(Calendar.MONTH) == Calendar.MAY
            || calendar.get(Calendar.MONTH) == Calendar.AUGUST
            || calendar.get(Calendar.MONTH) == Calendar.NOVEMBER) {
        monthDifference = -1;
    } else if (calendar.get(Calendar.MONTH) == Calendar.MARCH || calendar.get(Calendar.MONTH) == Calendar.JUNE
            || calendar.get(Calendar.MONTH) == Calendar.SEPTEMBER
            || calendar.get(Calendar.MONTH) == Calendar.DECEMBER)
        monthDifference = -2;
    //     Integer dayDifference = -calendar.get(Calendar.DAY_OF_MONTH);
    calendar.add(Calendar.MONTH, monthDifference);
    calendar.set(Calendar.DAY_OF_MONTH, 1);
    calendar.set(Calendar.HOUR, 0);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);
    calendar.set(Calendar.MILLISECOND, 0);
    //      calendar.add(Calendar.DAY_OF_MONTH, dayDifference-1);

    Date beginningOfQuarter = calendar.getTime();
    Double thisQuarterSum = 0.0;
    calendar.add(Calendar.MONTH, -3);
    Date QuarterBackOne = calendar.getTime();
    Double QuarterBackOneSum = 0.0;
    calendar.add(Calendar.MONTH, -3);
    Date QuarterBackTwo = calendar.getTime();
    Double QuarterBackTwoSum = 0.0;
    calendar.add(Calendar.MONTH, -3);
    Date QuarterBackThree = calendar.getTime();
    Double QuarterBackThreeSum = 0.0;

    List<Contracts> contracts = clientsDAO.getContractsForClient(id);
    HashMap<Date, Double> sums = new HashMap<Date, Double>();
    for (Contracts contract : contracts) {
        Date date = contract.getBegin_date();
        if (date.after(beginningOfQuarter))
            thisQuarterSum += contract.getTotalSum();
        else if (date.after(QuarterBackOne))
            QuarterBackOneSum += contract.getTotalSum();
        else if (date.after(QuarterBackTwo))
            QuarterBackTwoSum += contract.getTotalSum();
        else if (date.after(QuarterBackThree))
            QuarterBackThreeSum += contract.getTotalSum();
    }
    sums.put(beginningOfQuarter, thisQuarterSum);
    sums.put(QuarterBackOne, QuarterBackOneSum);
    sums.put(QuarterBackTwo, QuarterBackTwoSum);
    sums.put(QuarterBackThree, QuarterBackThreeSum);
    return sums;
}

From source file:org.apache.any23.extractor.microdata.MicrodataParserTest.java

@Test
public void testGetDateConcurrent() throws Exception {
    final Date expectedDate = new GregorianCalendar(2009, Calendar.MAY, 10).getTime(); // 2009-05-10
    final byte[] content = IOUtils
            .toByteArray(getClass().getResourceAsStream("/microdata/microdata-basic.html"));
    final int threadCount = 10;
    final int attemptCount = 100;
    final List<Thread> threads = new ArrayList<Thread>();
    final CountDownLatch beforeLatch = new CountDownLatch(1);
    final CountDownLatch afterLatch = new CountDownLatch(threadCount);
    final AtomicBoolean foundFailure = new AtomicBoolean(false);
    for (int i = 0; i < threadCount; i++) {
        threads.add(new Thread("Test-thread-" + i) {
            @Override/*from ww  w.ja v  a 2 s. co  m*/
            public void run() {
                try {
                    beforeLatch.await();
                    int counter = 0;
                    while (counter++ < attemptCount && !foundFailure.get()) {
                        final Document document = getDom(content);
                        final MicrodataParserReport report = MicrodataParser.getMicrodata(document);
                        final ItemScope target = report.getDetectedItemScopes()[4];
                        Date actualDate = target.getProperties().get("birthday").get(0).getValue().getAsDate();
                        if (!expectedDate.equals(actualDate)) {
                            foundFailure.set(true);
                        }
                    }
                } catch (Exception ex) {
                    ex.printStackTrace();
                    foundFailure.set(true);
                } finally {
                    afterLatch.countDown();
                }
            }
        });
    }
    for (Thread thread : threads) {
        thread.start();
    }
    // Let threads start computation
    beforeLatch.countDown();
    // Wait for all threads to complete
    afterLatch.await();
    assertFalse(foundFailure.get());
}