Example usage for java.util Calendar DAY_OF_MONTH

List of usage examples for java.util Calendar DAY_OF_MONTH

Introduction

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

Prototype

int DAY_OF_MONTH

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

Click Source Link

Document

Field number for get and set indicating the day of the month.

Usage

From source file:Dates.java

/**
 * Put the day to the date. <p>/*from  w w w.j a  va  2s.  c o m*/
 * 
 * If date is null it has no effect (but no exception is thrown)
 */
public static void setDay(Date date, int day) {
    if (date == null)
        return;
    Calendar cal = Calendar.getInstance();
    cal.setTime(date);
    cal.set(Calendar.DAY_OF_MONTH, day);
}

From source file:Main.java

/**
 * Parse a date from ISO-8601 formatted string. It expects a format yyyy-MM-ddThh:mm:ss[.sss][Z|[+-]hh:mm]
 *
 * @param date ISO string to parse in the appropriate format.
 * @return the parsed date//from w ww  . j  av a  2s  .  co m
 * @throws IllegalArgumentException if the date is not in the appropriate format
 */
public static Date parse(String date) {
    try {
        int offset = 0;

        // extract year
        int year = parseInt(date, offset, offset += 4);
        checkOffset(date, offset, '-');

        // extract month
        int month = parseInt(date, offset += 1, offset += 2);
        checkOffset(date, offset, '-');

        // extract day
        int day = parseInt(date, offset += 1, offset += 2);
        checkOffset(date, offset, 'T');

        // extract hours, minutes, seconds and milliseconds
        int hour = parseInt(date, offset += 1, offset += 2);
        checkOffset(date, offset, ':');

        int minutes = parseInt(date, offset += 1, offset += 2);
        checkOffset(date, offset, ':');

        int seconds = parseInt(date, offset += 1, offset += 2);
        // milliseconds can be optional in the format
        int milliseconds = 0; // always use 0 otherwise returned date will include millis of current time
        if (date.charAt(offset) == '.') {
            checkOffset(date, offset, '.');
            milliseconds = parseInt(date, offset += 1, offset += 3);
        }

        // extract timezone
        String timezoneId;
        char timezoneIndicator = date.charAt(offset);
        if (timezoneIndicator == '+' || timezoneIndicator == '-') {
            timezoneId = GMT_ID + date.substring(offset);
        } else if (timezoneIndicator == 'Z') {
            timezoneId = GMT_ID;
        } else {
            throw new IndexOutOfBoundsException("Invalid time zone indicator " + timezoneIndicator);
        }
        TimeZone timezone = TimeZone.getTimeZone(timezoneId);
        if (!timezone.getID().equals(timezoneId)) {
            throw new IndexOutOfBoundsException();
        }

        Calendar calendar = new GregorianCalendar(timezone);
        calendar.setLenient(false);
        calendar.set(Calendar.YEAR, year);
        calendar.set(Calendar.MONTH, month - 1);
        calendar.set(Calendar.DAY_OF_MONTH, day);
        calendar.set(Calendar.HOUR_OF_DAY, hour);
        calendar.set(Calendar.MINUTE, minutes);
        calendar.set(Calendar.SECOND, seconds);
        calendar.set(Calendar.MILLISECOND, milliseconds);

        return calendar.getTime();
    } catch (IndexOutOfBoundsException e) {
        throw new IllegalArgumentException("Failed to parse date " + date, e);
    } catch (NumberFormatException e) {
        throw new IllegalArgumentException("Failed to parse date " + date, e);
    } catch (IllegalArgumentException e) {
        throw new IllegalArgumentException("Failed to parse date " + date, e);
    }
}

From source file:ch.cyberduck.core.ftp.parser.vsFTPdEntryParserTest.java

@Test
public void testParse() throws Exception {
    FTPFile parsed;//from w ww .  j av a 2  s.c  o m

    // #5437
    parsed = parser.parseFTPEntry("-rw-r--r--    1 3642     3643          106 Nov 15 22:20 index.html");
    assertNotNull(parsed);
    assertEquals("index.html", parsed.getName());
    assertEquals(FTPFile.FILE_TYPE, parsed.getType());
    assertEquals(106, parsed.getSize());
    assertEquals(Calendar.NOVEMBER, parsed.getTimestamp().get(Calendar.MONTH));
    assertEquals(15, parsed.getTimestamp().get(Calendar.DAY_OF_MONTH));
    assertTrue(parsed.hasPermission(FTPFile.USER_ACCESS, FTPFile.READ_PERMISSION));
    assertTrue(parsed.hasPermission(FTPFile.GROUP_ACCESS, FTPFile.READ_PERMISSION));
    assertTrue(parsed.hasPermission(FTPFile.WORLD_ACCESS, FTPFile.READ_PERMISSION));
    assertTrue(parsed.hasPermission(FTPFile.USER_ACCESS, FTPFile.WRITE_PERMISSION));
}

From source file:org.openmrs.module.pharmacyapi.api.service.prescriptionservice.PrescriptionGeneratorTest.java

@Test
public void shouldGenerateNonArvPrescriptionWithActiveStatus() throws Exception {
    this.executeDataSet("prescriptionservice/shouldGenerateNonArvPrescriptionWithActiveStatus-dataset.xml");

    final Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.YEAR, 2017);
    calendar.set(Calendar.MONTH, 10);
    calendar.set(Calendar.DAY_OF_MONTH, 8);
    final Date date = calendar.getTime();

    final List<DrugOrder> drugOrders = new ArrayList<>();
    drugOrders.add((DrugOrder) Context.getOrderService().getOrder(100));
    drugOrders.add((DrugOrder) Context.getOrderService().getOrder(101));

    final List<Prescription> prescriptions = this.prescriptionGenerator.generatePrescriptions(drugOrders, date);

    Assert.assertEquals(1, prescriptions.size());
    final Prescription prescription = prescriptions.get(0);
    Assert.assertEquals(PrescriptionStatus.ACTIVE, prescription.getPrescriptionStatus());
    Assert.assertFalse(prescription.isArv());
    Assert.assertEquals(2, prescription.getPrescriptionItems().size());
}

From source file:cr.ac.siua.tec.utils.impl.ConstancyPDFGenerator.java

/**
 * Fills the PDF file (constancia.pdf) with the ticket values and returns base64 encoded string.
 *//*from w ww.ja v a  2s. c om*/
@Override
public String generate(HashMap<String, String> formValues) {
    String originalPdf = PDFGenerator.RESOURCES_PATH + "constancia.pdf";
    try {
        PDDocument _pdfDocument = PDDocument.load(originalPdf);
        PDDocumentCatalog docCatalog = _pdfDocument.getDocumentCatalog();
        PDAcroForm acroForm = docCatalog.getAcroForm();

        //Set some fields manually.
        Calendar cal = Calendar.getInstance();
        int day = cal.get(Calendar.DAY_OF_MONTH);
        int year = cal.get(Calendar.YEAR);
        int month = cal.get(Calendar.MONTH);
        String date = String.valueOf(day) + " de " + monthsMap.get(month) + " del ao " + String.valueOf(year)
                + ".";
        acroForm.getField("Fecha").setValue(date);

        formValues.remove("Queue");
        formValues.remove("Motivo");
        formValues.remove("Requestors");

        //Iterates through remaining custom fields.
        for (Map.Entry<String, String> entry : formValues.entrySet()) {
            acroForm.getField(entry.getKey()).setValue(entry.getValue());
        }
        return encodePDF(_pdfDocument);
    } catch (IOException e) {
        e.printStackTrace();
        System.out.println("Excepcin al llenar el PDF.");
        return null;
    }
}

From source file:com.bellman.bible.service.readingplan.OneDaysReadingsDto.java

/**
 * get a string representing the date this reading is planned for
 *///from  w  ww.java  2 s.  co  m
public String getReadingDateString() {
    String dateString = "";
    Date startDate = mReadingPlanInfoDto.getStartdate();
    if (startDate != null) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(startDate);
        cal.add(Calendar.DAY_OF_MONTH, mDay - 1);
        dateString = SimpleDateFormat.getDateInstance().format(cal.getTime());
    }
    return dateString;
}

From source file:ch.cyberduck.core.ftp.parser.StingrayFTPEntryParserTest.java

/**
 * http://trac.cyberduck.ch/ticket/1198/*from  w w w.j a v  a2 s .co  m*/
 */
@Test
public void testFile() {
    FTPFile parsed;

    parsed = parser.parseFTPEntry("-r--r--r--          0     165100     165100 Aug  1 10:24 grau2.tif");
    assertNotNull(parsed);
    assertEquals("grau2.tif", parsed.getName());
    assertEquals(FTPFile.FILE_TYPE, parsed.getType());
    assertEquals(Calendar.AUGUST, parsed.getTimestamp().get(Calendar.MONTH));
    assertEquals(1, parsed.getTimestamp().get(Calendar.DAY_OF_MONTH));
    assertEquals(10, parsed.getTimestamp().get(Calendar.HOUR_OF_DAY));
    assertEquals(24, parsed.getTimestamp().get(Calendar.MINUTE));
    assertTrue(parsed.hasPermission(FTPFile.USER_ACCESS, FTPFile.READ_PERMISSION));
    assertTrue(parsed.hasPermission(FTPFile.GROUP_ACCESS, FTPFile.READ_PERMISSION));
    assertTrue(parsed.hasPermission(FTPFile.WORLD_ACCESS, FTPFile.READ_PERMISSION));
    assertFalse(parsed.hasPermission(FTPFile.USER_ACCESS, FTPFile.WRITE_PERMISSION));
    assertFalse(parsed.hasPermission(FTPFile.GROUP_ACCESS, FTPFile.WRITE_PERMISSION));
    assertFalse(parsed.hasPermission(FTPFile.WORLD_ACCESS, FTPFile.WRITE_PERMISSION));
    assertFalse(parsed.hasPermission(FTPFile.USER_ACCESS, FTPFile.EXECUTE_PERMISSION));
    assertFalse(parsed.hasPermission(FTPFile.GROUP_ACCESS, FTPFile.EXECUTE_PERMISSION));
    assertFalse(parsed.hasPermission(FTPFile.WORLD_ACCESS, FTPFile.EXECUTE_PERMISSION));
}

From source file:ch.cyberduck.core.ftp.parser.OpensolarisFTPEntryParserTest.java

@Test
public void testParse() throws Exception {
    FTPFile parsed;/*w ww  . ja  v  a2s  .  c  om*/

    // #3689
    parsed = parser.parseFTPEntry("drwxr-xr-x+  5 niels    staff          7 Sep  6 13:46 data");
    assertNotNull(parsed);
    assertEquals(parsed.getName(), "data");
    assertEquals(FTPFile.DIRECTORY_TYPE, parsed.getType());
    assertEquals(7, parsed.getSize());
    assertEquals(Calendar.SEPTEMBER, parsed.getTimestamp().get(Calendar.MONTH));
    assertEquals(6, parsed.getTimestamp().get(Calendar.DAY_OF_MONTH));
    assertTrue(parsed.hasPermission(FTPFile.USER_ACCESS, FTPFile.READ_PERMISSION));
    assertTrue(parsed.hasPermission(FTPFile.USER_ACCESS, FTPFile.WRITE_PERMISSION));
    assertTrue(parsed.hasPermission(FTPFile.USER_ACCESS, FTPFile.EXECUTE_PERMISSION));
    assertTrue(parsed.hasPermission(FTPFile.GROUP_ACCESS, FTPFile.READ_PERMISSION));
    assertTrue(parsed.hasPermission(FTPFile.GROUP_ACCESS, FTPFile.EXECUTE_PERMISSION));
    assertTrue(parsed.hasPermission(FTPFile.WORLD_ACCESS, FTPFile.READ_PERMISSION));
    assertTrue(parsed.hasPermission(FTPFile.WORLD_ACCESS, FTPFile.EXECUTE_PERMISSION));
}

From source file:MonthPanel.java

protected JPanel createDaysGUI() {
    JPanel dayPanel = new JPanel(true);
    dayPanel.setLayout(new GridLayout(0, dayNames.length));

    Calendar today = Calendar.getInstance();
    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.MONTH, month);
    calendar.set(Calendar.YEAR, year);
    calendar.set(Calendar.DAY_OF_MONTH, 1);

    Calendar iterator = (Calendar) calendar.clone();
    iterator.add(Calendar.DAY_OF_MONTH, -(iterator.get(Calendar.DAY_OF_WEEK) - 1));

    Calendar maximum = (Calendar) calendar.clone();
    maximum.add(Calendar.MONTH, +1);

    for (int i = 0; i < dayNames.length; i++) {
        JPanel dPanel = new JPanel(true);
        dPanel.setBorder(BorderFactory.createLineBorder(Color.BLACK));
        JLabel dLabel = new JLabel(dayNames[i]);
        dPanel.add(dLabel);//from   ww w  .j a v a2 s .  c  om
        dayPanel.add(dPanel);
    }

    int count = 0;
    int limit = dayNames.length * 6;

    while (iterator.getTimeInMillis() < maximum.getTimeInMillis()) {
        int lMonth = iterator.get(Calendar.MONTH);
        int lYear = iterator.get(Calendar.YEAR);

        JPanel dPanel = new JPanel(true);
        dPanel.setBorder(BorderFactory.createLineBorder(Color.BLACK));
        JLabel dayLabel = new JLabel();

        if ((lMonth == month) && (lYear == year)) {
            int lDay = iterator.get(Calendar.DAY_OF_MONTH);
            dayLabel.setText(Integer.toString(lDay));
        }
        dPanel.add(dayLabel);
        dayPanel.add(dPanel);
        iterator.add(Calendar.DAY_OF_YEAR, +1);
        count++;
    }

    for (int i = count; i < limit; i++) {
        JPanel dPanel = new JPanel(true);
        dPanel.setBorder(BorderFactory.createLineBorder(Color.BLACK));

        dPanel.add(new JLabel());
        dayPanel.add(dPanel);
    }
    return dayPanel;
}

From source file:ch.cyberduck.core.ftp.parser.FilezillaFTPEntryParserTest.java

@Test
public void testParse() throws Exception {
    FTPFile parsed;/*from   ww w.  jav a 2 s . c  om*/

    // #3119
    parsed = parser.parseFTPEntry("-rw-r--r-- 1 ftp ftp         100847 Sep 10  2004 octfront2.jpg");
    assertNotNull(parsed);
    assertEquals("octfront2.jpg", parsed.getName());
    assertEquals(FTPFile.FILE_TYPE, parsed.getType());
    assertEquals(100847, parsed.getSize());
    assertEquals(Calendar.SEPTEMBER, parsed.getTimestamp().get(Calendar.MONTH));
    assertEquals(10, parsed.getTimestamp().get(Calendar.DAY_OF_MONTH));
    assertTrue(parsed.hasPermission(FTPFile.USER_ACCESS, FTPFile.READ_PERMISSION));
    assertTrue(parsed.hasPermission(FTPFile.GROUP_ACCESS, FTPFile.READ_PERMISSION));
    assertTrue(parsed.hasPermission(FTPFile.WORLD_ACCESS, FTPFile.READ_PERMISSION));
    assertTrue(parsed.hasPermission(FTPFile.USER_ACCESS, FTPFile.WRITE_PERMISSION));
}