Example usage for java.util Calendar clear

List of usage examples for java.util Calendar clear

Introduction

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

Prototype

public final void clear() 

Source Link

Document

Sets all the calendar field values and the time value (millisecond offset from the Epoch) of this Calendar undefined.

Usage

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

@Test
public void testGetRangeBounds2() {
    TimeZone tzone = TimeZone.getTimeZone("Europe/London");
    Calendar calendar = new GregorianCalendar(tzone, Locale.UK);
    calendar.clear();
    calendar.set(2014, Calendar.FEBRUARY, 23, 6, 0);
    long start = calendar.getTimeInMillis();
    calendar.clear();//www  .ja  va 2 s  .  c o m
    calendar.set(2014, Calendar.FEBRUARY, 24, 18, 0);
    long end = calendar.getTimeInMillis();
    Range range = new Range(start, end);

    TimeSeriesCollection collection = new TimeSeriesCollection(tzone);
    assertNull(collection.getRangeBounds(Collections.EMPTY_LIST, range, true));

    TimeSeries s1 = new TimeSeries("S1");
    s1.add(new Day(24, 2, 2014), 10.0);
    collection.addSeries(s1);
    assertEquals(new Range(10.0, 10.0), collection.getRangeBounds(Arrays.asList("S1"), range, true));
    collection.setXPosition(TimePeriodAnchor.MIDDLE);
    assertEquals(new Range(10.0, 10.0), collection.getRangeBounds(Arrays.asList("S1"), range, true));
    collection.setXPosition(TimePeriodAnchor.END);
    assertNull(collection.getRangeBounds(Arrays.asList("S1"), range, true));
}

From source file:org.apache.olingo.fit.proxy.EntityCreateTestITCase.java

@Test
public void createWithBackNavigation() {
    final Integer id = 102;

    // -------------------------------
    // Create a new order
    // -------------------------------
    Order order = getContainer().newEntityInstance(Order.class);
    order.setOrderID(id);/*from w  w w .  j av  a  2s . c o  m*/

    final Calendar orderDate = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
    orderDate.clear();
    orderDate.set(2011, 3, 4, 16, 3, 57);
    order.setOrderDate(new Timestamp(orderDate.getTimeInMillis()));

    order.setShelfLife(BigDecimal.TEN);

    PrimitiveCollection<BigDecimal> osl = getContainer().newPrimitiveCollection(BigDecimal.class);
    osl.add(BigDecimal.TEN.negate());
    osl.add(BigDecimal.TEN);
    order.setOrderShelfLifes(osl);
    // -------------------------------

    // -------------------------------
    // Create a new customer
    // -------------------------------
    final Customer customer = getContainer().newEntityInstance(Customer.class);
    customer.setPersonID(id);
    customer.setPersonID(id);
    customer.setFirstName("Fabio");
    customer.setLastName("Martelli");
    customer.setCity("Pescara");

    PrimitiveCollection<String> value = getContainer().newPrimitiveCollection(String.class);
    value.add("fabio.martelli@tirasa.net");
    customer.setEmails(value);

    final Address homeAddress = getContainer().newComplexInstance(HomeAddress.class);
    homeAddress.setCity("Pescara");
    homeAddress.setPostalCode("65100");
    homeAddress.setStreet("viale Gabriele D'Annunzio 256");
    customer.setHomeAddress(homeAddress);

    value = getContainer().newPrimitiveCollection(String.class);
    value.add("3204725072");
    value.add("08569930");
    customer.setNumbers(value);

    final OrderCollection orders = getContainer().newEntityCollection(OrderCollection.class);
    orders.add(order);
    customer.setOrders(orders);
    // -------------------------------

    // -------------------------------
    // Link customer to order
    // -------------------------------
    order.setCustomerForOrder(customer);
    // -------------------------------

    getContainer().getOrders().add(order);
    getContainer().flush();

    assertEquals(id, order.getOrderID());
    assertEquals(id, customer.getPersonID());

    Customer actual = readCustomer(getContainer(), id);
    Assert.assertEquals(homeAddress.getCity(), actual.getHomeAddress().getCity());
    Assert.assertEquals(1, actual.getOrders().execute().size());
    Assert.assertEquals(id, actual.getOrders().iterator().next().getOrderID());

    order = getContainer().getOrders().getByKey(id);
    assertNotNull(order);
    Assert.assertEquals(id, order.getCustomerForOrder().load().getPersonID());

    getContainer().getOrders().delete(actual.getOrders());
    getContainer().flush();

    try {
        getContainer().getOrders().getByKey(id).load();
        fail();
    } catch (IllegalArgumentException e) {
        // Expected
    }

    actual = readCustomer(getContainer(), id);
    assertTrue(actual.getOrders().isEmpty());

    getContainer().getCustomers().delete(actual.getPersonID());
    getContainer().flush();

    try {
        getContainer().getCustomers().getByKey(id).load();
        fail();
    } catch (IllegalArgumentException e) {
        // Expected
    }
}

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

/**
 * Returns the first millisecond of the time period.
 *
 * @param calendar  the calendar ({@code null} not permitted).
 *
 * @return The first millisecond of the time period.
 * /* w  ww. ja  v a 2s.  c  om*/
 * @throws NullPointerException if {@code calendar} is {@code null}.
 */
@Override
public long getFirstMillisecond(Calendar calendar) {
    int year = this.day.getYear();
    int month = this.day.getMonth() - 1;
    int day = this.day.getDayOfMonth();
    calendar.clear();
    calendar.set(year, month, day, this.hour, this.minute, this.second);
    calendar.set(Calendar.MILLISECOND, this.millisecond);
    return calendar.getTimeInMillis();
}

From source file:org.obiba.onyx.core.etl.participant.impl.XmlParticipantReaderTest.java

@Test
public void testProcessWithConfiguredAttributes() throws IOException {
    Calendar cal = Calendar.getInstance();

    cal.clear();
    cal.set(2008, 9 - 1, 1, 9, 0);//from ww w . j a v  a 2 s.  c  o m
    final Date expectedAppointmentTime = cal.getTime();

    cal.clear();
    cal.set(1964, 10 - 1, 1);
    final Date expectedBirthDate = cal.getTime();

    initConfiguredAttributeDefinition();
    XmlParticipantReaderForTest reader = createXmlParticipantReaderForTest(true,
            TEST_RESOURCES_DIR + "/appointmentList_includesConfiguredAttributes.xml");
    reader.setColumnNameToAttributeNameMap(columnNameToAttributeNameMap);
    reader.setParticipantMetadata(participantMetadata);

    reader.open(context);
    List<Participant> participants = new ArrayList<Participant>();
    try {
        while (reader.getIterator().hasNext()) {
            Participant participant = reader.read();
            if (participant != null)
                participants.add(participant);
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }

    Assert.assertEquals(1, participants.size());
    Assert.assertEquals(expectedAppointmentTime, participants.get(0).getAppointment().getDate());
    Assert.assertEquals("cag001", participants.get(0).getSiteNo());
    Assert.assertEquals("100001", participants.get(0).getEnrollmentId());
    Assert.assertEquals("Tremblay", participants.get(0).getLastName());
    Assert.assertEquals("Chantal", participants.get(0).getFirstName());
    Assert.assertEquals("F", (participants.get(0).getGender().equals(Gender.FEMALE) ? "F" : "M"));
    Assert.assertEquals(expectedBirthDate, participants.get(0).getBirthDate());

    // Verify that the participant's configured attributes have been assigned the correct values.
    Assert.assertEquals("299, Avenue des Pins Ouest",
            participants.get(0).getConfiguredAttributeValue("Street").getValue());
    Assert.assertEquals("Montr\u00e9al", participants.get(0).getConfiguredAttributeValue("City").getValue());
    Assert.assertEquals("QC", participants.get(0).getConfiguredAttributeValue("Province").getValue());
    Assert.assertEquals("Canada", participants.get(0).getConfiguredAttributeValue("Country").getValue());
    Assert.assertEquals("H1T 2M4", participants.get(0).getConfiguredAttributeValue("Postal Code").getValue());
    Assert.assertEquals("514-343-9898 ext 9494",
            participants.get(0).getConfiguredAttributeValue("Phone").getValue());
}

From source file:mx.edu.um.mateo.rh.dao.impl.EmpleadoDaoHibernate.java

private Criterion getQueryByMonth(Calendar gc) {
    Criterion cr = null;//from   ww  w  . java  2s .c o  m

    gc.add(Calendar.YEAR, 1);

    gc.set(Calendar.DAY_OF_MONTH, 1);
    Date fechaI = gc.getTime();

    gc.set(Calendar.DAY_OF_MONTH, gc.getMaximum(Calendar.DAY_OF_MONTH));
    Date fechaF = gc.getTime();

    cr = Restrictions.between("fechaNacimiento", fechaI, fechaF);

    Calendar tmp = (Calendar) gc.clone();
    tmp.clear();
    tmp.setTime(new Date());
    tmp.add(Calendar.YEAR, -17);

    if (gc.compareTo(tmp) <= 0) {
        return Restrictions.or(cr, getQueryByMonth(gc));
    } else {
        return cr;
    }
}

From source file:ivl.android.moneybalance.ExpenseEditorActivity.java

private void pickDate() {
    final DatePickerDialog.OnDateSetListener onDateSet = new DatePickerDialog.OnDateSetListener() {
        @Override//from   w w w  . j  a  v a  2s . c  om
        public void onDateSet(DatePicker view, int year, int month, int day) {
            Calendar date = Calendar.getInstance();
            date.clear();
            date.set(year, month, day);
            expense.setDate(date);
            updateDate();
        }
    };

    DialogFragment fragment = new DialogFragment() {
        @Override
        public Dialog onCreateDialog(Bundle savedInstanceState) {
            Calendar date = expense.getDate();
            int year = date.get(Calendar.YEAR);
            int month = date.get(Calendar.MONTH);
            int day = date.get(Calendar.DAY_OF_MONTH);
            return new DatePickerDialog(getActivity(), onDateSet, year, month, day);
        }
    };
    fragment.show(getSupportFragmentManager(), "datePicker");
}

From source file:org.obiba.onyx.core.etl.participant.impl.ParticipantProcessorTest.java

@Test
public void testProcessWithConfiguredAttributes() throws IOException {
    Calendar cal = Calendar.getInstance();

    cal.clear();
    cal.set(2008, 9 - 1, 1, 9, 0);/*from  w  w w.ja va  2  s. c o  m*/
    final Date expectedAppointmentTime = cal.getTime();

    cal.clear();
    cal.set(1964, 10 - 1, 1);
    final Date expectedBirthDate = cal.getTime();

    ParticipantProcessor.initProcessor();

    expect(applicationConfigurationServiceMock.getApplicationConfiguration()).andReturn(config);
    expectLastCall().times(1);

    expect(participantServiceMock.getParticipant((Participant) EasyMock.anyObject())).andReturn(null);
    expectLastCall().times(1);

    List<Participant> participants = participantReaderTest.getParticipantList(true,
            TEST_RESOURCES_DIR + "/appointmentList_includesConfiguredAttributes.xls");
    List<Participant> processedParticipants = new ArrayList<Participant>();

    replay(applicationConfigurationServiceMock);
    replay(participantServiceMock);

    try {
        for (Participant participantItem : participants) {
            Participant participant = processor.process(participantItem);
            if (participant != null)
                processedParticipants.add(participant);
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }

    verify(applicationConfigurationServiceMock);
    verify(participantServiceMock);

    Assert.assertEquals(1, participants.size());
    Assert.assertEquals(expectedAppointmentTime, participants.get(0).getAppointment().getDate());
    Assert.assertEquals("cag001", participants.get(0).getSiteNo());
    Assert.assertEquals("100001", participants.get(0).getEnrollmentId());
    Assert.assertEquals("Tremblay", participants.get(0).getLastName());
    Assert.assertEquals("Chantal", participants.get(0).getFirstName());
    Assert.assertEquals("F", (participants.get(0).getGender().equals(Gender.FEMALE) ? "F" : "M"));
    Assert.assertEquals(expectedBirthDate, participants.get(0).getBirthDate());

    // Verify that the participant's configured attributes have been assigned the correct values.
    Assert.assertEquals("299, Avenue des Pins Ouest",
            participants.get(0).getConfiguredAttributeValue("Street").getValue());
    Assert.assertEquals("Montr\u00e9al", participants.get(0).getConfiguredAttributeValue("City").getValue());
    Assert.assertEquals("QC", participants.get(0).getConfiguredAttributeValue("Province").getValue());
    Assert.assertEquals("Canada", participants.get(0).getConfiguredAttributeValue("Country").getValue());
    Assert.assertEquals("H1T 2M4", participants.get(0).getConfiguredAttributeValue("Postal Code").getValue());
    Assert.assertEquals("514-343-9898 ext 9494",
            participants.get(0).getConfiguredAttributeValue("Phone").getValue());
}

From source file:de.fhg.fokus.openride.services.profile.ProfileService.java

@PUT
@Produces("text/json")
public Response putProfile(@Context HttpServletRequest con, @PathParam("username") String username,
        String json) {//  w w w. j av  a  2  s . c  om

    System.out.println("putProfile start");

    if (json != null) {
        System.out.println("json: " + json);
        // to use this method client must send json content!

        // check if remote user == {username} in path param
        if (!username.equals(con.getRemoteUser())) {
            return Response.status(Response.Status.FORBIDDEN).build();
        }

        CustomerEntity c = customerControllerBean.getCustomerByNickname(username);

        // build a List of Objects that shall be available in the JSON context.
        ArrayList list = new ArrayList();
        list.add(new ProfileRequest());

        XStream x = Utils.getJasonXStreamer(list);

        ProfileRequest r = (ProfileRequest) x.fromXML(json);

        //TODO: data validation!
        //resp.setStatus(resp.SC_BAD_REQUEST);

        Date dateOfBirth;
        if (r.getDateOfBirth() != null) {
            dateOfBirth = new Date(r.getDateOfBirth());
        } else {
            dateOfBirth = null;
        }

        Date licenseDate;
        if (r.getLicenseDate() != null) {
            Calendar cal = Calendar.getInstance();
            cal.clear();
            cal.set(r.getLicenseDate(), 0, 1);
            licenseDate = cal.getTime();
        } else {
            licenseDate = null;
        }

        // Validate email address:
        CustomerEntity other_c = customerControllerBean.getCustomerByEmail(r.getEmail());

        // Allow existing email address if it is the user's current one!
        if (other_c != null && !other_c.getCustEmail().equals(c.getCustEmail())) {
            // "Ein Benutzer mit dieser E-Mail-Adresse ist bereits registriert."
            return Response.status(Response.Status.BAD_REQUEST).build();
        }

        // Pilotierung: nur ZU-Adressen zulssig
        /*if (!r.getEmail().endsWith("zeppelin-university.de") && !r.getEmail().endsWith("zeppelin-university.net") && !r.getEmail().endsWith("fokus.fraunhofer.de")) {
        // "E-Mail-Adresse muss auf \"zeppelin-university.de\" enden."
        return Response.status(Response.Status.BAD_REQUEST).build();
        }*/

        customerControllerBean.setPersonalData(c.getCustId(), dateOfBirth, r.getEmail(),
                r.getMobilePhoneNumber(), r.getFixedPhoneNumber(), r.getStreetAddress(), r.getZipCode(),
                r.getCity(), r.getIsSmoker(), licenseDate);
        carDetailsControllerBean.updateCarDetails(c, r.getCarBrand(), r.getCarBuildYear(), r.getCarColour(),
                r.getCarPlateNo());

        return Response.ok().build();

    } else {
        return Response.status(Response.Status.NOT_FOUND).build();
    }

}

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

/**
 * Returns the first millisecond of the minute.
 *
 * @param calendar  the calendar/timezone (<code>null</code> not permitted).
 *
 * @return The first millisecond./*from ww  w . j  av a 2 s  .  co  m*/
 *
 * @throws NullPointerException if <code>calendar</code> is
 *     <code>null</code>.
 */
@Override
public long getFirstMillisecond(Calendar calendar) {
    int year = this.day.getYear();
    int month = this.day.getMonth() - 1;
    int d = this.day.getDayOfMonth();
    calendar.clear();
    calendar.set(year, month, d, this.hour, this.minute, this.second);
    calendar.set(Calendar.MILLISECOND, 0);
    return calendar.getTimeInMillis();
}

From source file:DateParser.java

/**
 * Check if a given date is an iso8601 date.
 * //from w w  w  . j ava 2s.  c  o m
 * @param iso8601Date The date to be checked.
 * @return <code>true</code> if the date is an iso8601 date.
 * @throws InvalidDateException 
 */
private Calendar getCalendar(String iso8601Date) throws InvalidDateException {
    // YYYY-MM-DDThh:mm:ss.sTZD
    StringTokenizer st = new StringTokenizer(iso8601Date, "-T:.+Z", true);
    if (!st.hasMoreTokens()) {
        throw new InvalidDateException("Empty Date");
    }
    Calendar calendar = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
    calendar.clear();
    try {
        // Year
        if (st.hasMoreTokens()) {
            int year = Integer.parseInt(st.nextToken());
            calendar.set(Calendar.YEAR, year);
        } else {
            return calendar;
        }
        // Month
        if (checkValueAndNext(st, "-")) {
            int month = Integer.parseInt(st.nextToken()) - 1;
            calendar.set(Calendar.MONTH, month);
        } else {
            return calendar;
        }
        // Day
        if (checkValueAndNext(st, "-")) {
            int day = Integer.parseInt(st.nextToken());
            calendar.set(Calendar.DAY_OF_MONTH, day);
        } else {
            return calendar;
        }
        // Hour
        if (checkValueAndNext(st, "T")) {
            int hour = Integer.parseInt(st.nextToken());
            calendar.set(Calendar.HOUR_OF_DAY, hour);
        } else {
            calendar.set(Calendar.HOUR_OF_DAY, 0);
            calendar.set(Calendar.MINUTE, 0);
            calendar.set(Calendar.SECOND, 0);
            calendar.set(Calendar.MILLISECOND, 0);
            return calendar;
        }
        // Minutes
        if (checkValueAndNext(st, ":")) {
            int minutes = Integer.parseInt(st.nextToken());
            calendar.set(Calendar.MINUTE, minutes);
        } else {
            calendar.set(Calendar.MINUTE, 0);
            calendar.set(Calendar.SECOND, 0);
            calendar.set(Calendar.MILLISECOND, 0);
            return calendar;
        }
        if (!st.hasMoreTokens()) {
            return calendar;
        }
        // Not mandatory now
        // Seconds
        String tok = st.nextToken();
        if (tok.equals(":")) { // seconds
            if (st.hasMoreTokens()) {
                int secondes = Integer.parseInt(st.nextToken());
                calendar.set(Calendar.SECOND, secondes);
                if (!st.hasMoreTokens()) {
                    return calendar;
                }
                // decimal fraction of a second
                tok = st.nextToken();
                if (tok.equals(".")) {
                    String nt = st.nextToken();
                    while (nt.length() < 3) {
                        nt += "0";
                    }
                    if (nt.length() > 3) {
                        // check the other part from the decimal fraction to be formed only from digits
                        for (int i = 3; i < nt.length(); i++) {
                            if (!Character.isDigit(nt.charAt(i))) {
                                throw new InvalidDateException(
                                        "Invalid digit in the decimal fraction of a second: " + nt.charAt(i));
                            }
                        }
                    }
                    nt = nt.substring(0, 3); //Cut trailing chars..
                    int millisec = Integer.parseInt(nt);
                    calendar.set(Calendar.MILLISECOND, millisec);
                    if (!st.hasMoreTokens()) {
                        return calendar;
                    }
                    tok = st.nextToken();
                } else {
                    calendar.set(Calendar.MILLISECOND, 0);
                }
            } else {
                throw new InvalidDateException("No secondes specified");
            }
        } else {
            calendar.set(Calendar.SECOND, 0);
            calendar.set(Calendar.MILLISECOND, 0);
        }
        // Time zone
        if (!tok.equals("Z")) { // UTC
            if (!(tok.equals("+") || tok.equals("-"))) {
                throw new InvalidDateException("only Z, + or - allowed");
            }
            boolean plus = tok.equals("+");
            if (!st.hasMoreTokens()) {
                throw new InvalidDateException("Missing hour field");
            }
            int tzhour = Integer.parseInt(st.nextToken());
            int tzmin = 0;
            if (checkValueAndNext(st, ":")) {
                tzmin = Integer.parseInt(st.nextToken());
            } else {
                throw new InvalidDateException("Missing minute field");
            }
            if (plus) {
                calendar.add(Calendar.HOUR, -tzhour);
                calendar.add(Calendar.MINUTE, -tzmin);
            } else {
                calendar.add(Calendar.HOUR, tzhour);
                calendar.add(Calendar.MINUTE, tzmin);
            }
        } else {
            if (st.hasMoreTokens()) {
                throw new InvalidDateException(
                        "Unexpected field at the end of the date field: " + st.nextToken());
            }
        }
    } catch (NumberFormatException ex) {
        throw new InvalidDateException("[" + ex.getMessage() + "] is not an integer");
    }
    return calendar;
}