Example usage for java.util Calendar YEAR

List of usage examples for java.util Calendar YEAR

Introduction

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

Prototype

int YEAR

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

Click Source Link

Document

Field number for get and set indicating the year.

Usage

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:eu.trentorise.smartcampus.mobility.processor.alerts.ParkingChecker.java

private static String buildDate() {
    Calendar cal = new GregorianCalendar();
    return cal.get(Calendar.DAY_OF_MONTH) + "-" + cal.get(Calendar.MONTH) + "-" + cal.get(Calendar.YEAR);
}

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

private Interval findNearestPeriod(Calendar now) {

    final int year;

    if (now.get(Calendar.MONTH) > Calendar.AUGUST) {

        year = now.get(Calendar.YEAR) + 1;

    } else {//from  w w  w  .java2 s.c o m
        year = now.get(Calendar.YEAR);
    }

    final Calendar mayStart = Calendar.getInstance();
    mayStart.set(year, Calendar.MAY, 1, 0, 0, 0);

    final Calendar augEnd = Calendar.getInstance();
    augEnd.set(year, Calendar.AUGUST, 31, 0, 0, 0);

    return new Interval(mayStart.getTime(), augEnd.getTime());
}

From source file:controllers.UserReportController.java

@RequestMapping("/summarizedReport")
public String getFullUserReport(Map<String, Object> model,
        @RequestParam(value = "dateCampaignFrom", required = false) Date dateCampaignFrom,
        @RequestParam(value = "dateCampaignTo", required = false) Date dateCampaignTo,
        HttpServletRequest request) throws Exception {
    lk.dataByUserAndCompany(request, model);
    Long cabinetId = (long) request.getSession().getAttribute(CABINET_ID_SESSION_NAME);
    if (dateCampaignFrom == null || dateCampaignFrom.toString().equals("")) {
        Calendar cl = Calendar.getInstance();
        cl.set(Calendar.YEAR, Calendar.MONTH, 1, 0, 0, 0);
        dateCampaignFrom = cl.getTime();
    }/* w  w w.j  a  va2  s .c  om*/
    if (dateCampaignTo == null || dateCampaignTo.toString().equals("")) {
        dateCampaignTo = new Date();
    }
    LinkedHashMap<User, HashMap> reportMap = eventService
            .getUsersAndSuccessfulFailedPerformancesForReport(dateCampaignFrom, dateCampaignTo, cabinetId);

    model.put("reportMap", reportMap);
    model.put("errors", eventService.getErrors());
    return "summarizedUserReport";
}

From source file:com.cemeterylistingswebtest.test.rest.RegistrationControllerTest.java

@Test(enabled = false)
public void testCreate() {
    System.out.println("Registration Testing");
    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.YEAR, 2008);
    calendar.set(Calendar.MONTH, Calendar.FEBRUARY);
    calendar.set(Calendar.DATE, 4);

    java.sql.Date javaSqlDate = new java.sql.Date(calendar.getTime().getTime());

    UserRole user = new UserRole.Builder().setLevel(1).build();

    Subscriber newSub = new Subscriber.Builder().setEmail("zaakir@gmail.com").setFirstName("zaakir")
            .setSurname("arendse").setPwd("123").setUsername("zak").setSubscriptionDate(javaSqlDate)
            .setUserRoleID(user).build();

    HttpEntity<Subscriber> requestEntity = new HttpEntity<>(newSub, getContentType());
    //        Make the HTTP POST request, marshaling the request to JSON, and the response to a String
    ResponseEntity<String> responseEntity = restTemplate.exchange(URL + "api/Registration/create",
            HttpMethod.POST, requestEntity, String.class);
    System.out.println(" THE RESPONSE BODY " + responseEntity.getBody());
    System.out.println(" THE RESPONSE STATUS CODE " + responseEntity.getStatusCode());
    System.out.println(" THE RESPONSE IS HEADERS " + responseEntity.getHeaders());

    Assert.assertEquals(responseEntity.getStatusCode(), HttpStatus.OK);
    id = newSub.getSubscriberID();//from  w  w w .  ja  v a 2  s  . com
}

From source file:Main.java

/**
 * Adds a number of years to a date returning a new object.
 * The original date object is unchanged.
 *
 * @param date  the date, not null/*from   w ww.ja  v a2  s .co  m*/
 * @param amount  the amount to add, may be negative
 * @return the new date object with the amount added
 * @throws IllegalArgumentException if the date is null
 */
public static Date addYears(Date date, int amount) {
    return add(date, Calendar.YEAR, amount);
}

From source file:edu.stanford.muse.email.CalendarUtil.java

public static int getDiffInMonths(Date firstDate, Date lastDate) {
    Calendar cFirst = new GregorianCalendar();
    cFirst.setTime(firstDate);/*w w w .j  ava2 s  .c  om*/
    Calendar cLast = new GregorianCalendar();
    cLast.setTime(lastDate);
    int cFirst_year = cFirst.get(Calendar.YEAR);
    int cFirst_month = cFirst.get(Calendar.MONTH);
    int cLast_year = cLast.get(Calendar.YEAR);
    int cLast_month = cLast.get(Calendar.MONTH);
    return (cLast_year - cFirst_year)
            * (cLast.getMaximum(Calendar.MONTH) - cLast.getMinimum(Calendar.MONTH) + 1)
            + (cLast_month - cFirst_month);
}

From source file:com.example.geomesa.authorizations.AuthorizationsTutorial.java

/**
 * Creates a base filter that will return a small subset of our results. This can be tweaked to
 * return different results if desired. Currently it should return 16 results.
 *
 * @return//from w w  w .  j  a v a2 s.  c  o  m
 *
 * @throws CQLException
 * @throws IOException
 */
static Filter createBaseFilter() throws CQLException, IOException {

    // Get a FilterFactory2 to build up our query
    FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2();

    // We are going to query for events in Ukraine during the
    // civil unrest.

    // We'll start by looking at a particular day in February of 2014
    Calendar calendar = Calendar.getInstance();
    calendar.clear();
    calendar.set(Calendar.YEAR, 2013);
    calendar.set(Calendar.MONTH, Calendar.JANUARY);
    calendar.set(Calendar.DAY_OF_MONTH, 1);
    calendar.set(Calendar.HOUR_OF_DAY, 0);
    Date start = calendar.getTime();

    calendar.set(Calendar.YEAR, 2014);
    calendar.set(Calendar.MONTH, Calendar.APRIL);
    calendar.set(Calendar.DAY_OF_MONTH, 30);
    calendar.set(Calendar.HOUR_OF_DAY, 23);
    Date end = calendar.getTime();
    //        2013-01-01T00:00:00.000Z/2014-04-30T23:00:00.000Z
    Filter timeFilter = ff.between(ff.property(GdeltFeature.Attributes.SQLDATE.getName()), ff.literal(start),
            ff.literal(end));

    // We'll bound our query spatially to Ukraine
    Filter spatialFilter = ff.bbox(GdeltFeature.Attributes.geom.getName(), 31.6, 44, 37.4, 47.75, "EPSG:4326");

    // we'll also restrict our query to only articles about the US, UK or UN
    Filter attributeFilter = ff.like(ff.property(GdeltFeature.Attributes.Actor1Name.getName()), "UNITED%");

    // Now we can combine our filters using a boolean AND operator
    Filter conjunction = ff.and(Arrays.asList(timeFilter, spatialFilter, attributeFilter));

    return conjunction;
}

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);/* w  w w.  j a  v  a 2 s  .c o  m*/
        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.MicrosoftFTPEntryParserTest.java

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

    // #3701
    parsed = parser.parseFTPEntry("12-04-06  12:43PM                65335 fon1.kucuk.jpg");
    assertNotNull(parsed);
    assertEquals("fon1.kucuk.jpg", parsed.getName());
    assertEquals(FTPFile.FILE_TYPE, parsed.getType());
    assertEquals(65335, parsed.getSize());
    assertEquals(2006, parsed.getTimestamp().get(Calendar.YEAR));
    assertEquals(Calendar.DECEMBER, parsed.getTimestamp().get(Calendar.MONTH));
    assertEquals(4, parsed.getTimestamp().get(Calendar.DAY_OF_MONTH));
}