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(int field) 

Source Link

Document

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

Usage

From source file:org.mnode.coucou.JournalQueryTreeTableNode.java

/**
 * @param query/*w w  w.  ja va 2s .c o m*/
 */
public JournalQueryTreeTableNode(Node node) {
    super(node);
    try {
        if ("Today".equals(node.getName())) {
            Calendar todayCal = Calendar.getInstance();
            todayCal.set(Calendar.HOUR_OF_DAY, 0);
            todayCal.clear(Calendar.MINUTE);
            todayCal.clear(Calendar.SECOND);
            todayCal.clear(Calendar.MILLISECOND);
            getBindVariables().put("minDate", node.getSession().getValueFactory().createValue(todayCal));
        } else if ("Yesterday".equals(node.getName())) {
            Calendar yesterdayCal = Calendar.getInstance();
            yesterdayCal.add(Calendar.DAY_OF_MONTH, -1);
            yesterdayCal.set(Calendar.HOUR_OF_DAY, 0);
            yesterdayCal.clear(Calendar.MINUTE);
            yesterdayCal.clear(Calendar.SECOND);
            yesterdayCal.clear(Calendar.MILLISECOND);
            getBindVariables().put("minDate", node.getSession().getValueFactory().createValue(yesterdayCal));
        }
    } catch (RepositoryException e) {
        LOG.log(LogEntries.NODE_ERROR, e, node);
    }
}

From source file:org.mnode.coucou.PlannerQueryTreeTableNode.java

/**
 * @param query/*  ww w  . ja  va  2s . com*/
 */
public PlannerQueryTreeTableNode(Node node) {
    super(node);
    try {
        if ("Today".equals(node.getName()) || "This Week".equals(node.getName())) {
            Calendar todayCal = Calendar.getInstance();
            todayCal.set(Calendar.HOUR_OF_DAY, 0);
            todayCal.clear(Calendar.MINUTE);
            todayCal.clear(Calendar.SECOND);
            todayCal.clear(Calendar.MILLISECOND);
            getBindVariables().put("minDate", node.getSession().getValueFactory().createValue(todayCal));
        } else if ("Tomorrow".equals(node.getName())) {
            Calendar tomorrowCal = Calendar.getInstance();
            tomorrowCal.add(Calendar.DAY_OF_MONTH, 1);
            tomorrowCal.set(Calendar.HOUR_OF_DAY, 0);
            tomorrowCal.clear(Calendar.MINUTE);
            tomorrowCal.clear(Calendar.SECOND);
            tomorrowCal.clear(Calendar.MILLISECOND);
            getBindVariables().put("minDate", node.getSession().getValueFactory().createValue(tomorrowCal));
        }
    } catch (RepositoryException e) {
        LOG.log(LogEntries.NODE_ERROR, e, node);
    }
}

From source file:org.openmrs.module.kenyaemr.fragment.controller.facilityDashboard.FacilityDashboardFragmentController.java

private Date todaysDate() {
    Calendar gc = new GregorianCalendar();
    gc.clear(Calendar.HOUR);
    gc.clear(Calendar.HOUR_OF_DAY);
    gc.clear(Calendar.MINUTE);//w  w w  .j a  v a2s .c o m
    gc.clear(Calendar.SECOND);
    gc.clear(Calendar.MILLISECOND);
    Date today = gc.getTime();

    return today;
}

From source file:org.kuali.rice.kew.docsearch.SearchableAttributeDateTimeValue.java

@Override
public void setupAttributeValue(ResultSet resultSet, String columnName) throws SQLException {
    Calendar c = Calendar.getInstance();
    c.clear(Calendar.HOUR);
    c.clear(Calendar.MINUTE);/*w w w .j  a  va  2  s  .c o m*/
    c.clear(Calendar.SECOND);
    c.clear(Calendar.MILLISECOND);
    this.setSearchableAttributeValue(resultSet.getTimestamp(columnName, c));
}

From source file:org.openmrs.module.patientportaltoolkit.fragment.controller.AddRelationshipFragmentController.java

private Date updateAge(String birthdate, String dateformat, String age) throws java.text.ParseException {
    SimpleDateFormat df = new SimpleDateFormat();
    if (!"".equals(dateformat)) {
        dateformat = dateformat.toLowerCase().replaceAll("m", "M");
    } else {//from www  .  j  a va2  s  .co  m
        dateformat = new String("MM/dd/yyyy");
    }
    df.applyPattern(dateformat);
    Calendar cal = Calendar.getInstance();
    cal.clear(Calendar.HOUR);
    cal.clear(Calendar.MINUTE);
    cal.clear(Calendar.SECOND);
    cal.clear(Calendar.MILLISECOND);
    if ("".equals(birthdate)) {
        if ("".equals(age)) {
            return cal.getTime();
        }
        try {
            cal.add(Calendar.YEAR, -(Integer.parseInt(age)));
        } catch (NumberFormatException nfe) {
            log.error("Error during adding date into calendar", nfe);
        }
        return cal.getTime();
    } else {
        cal.setTime(df.parse(birthdate));
    }
    return cal.getTime();
}

From source file:org.kuali.coeus.s2sgen.impl.datetime.S2SDateTimeServiceImpl.java

/**
 * This method is used to get Calendar date for the corresponding date object.
 *
 * @param date(Date) date for which Calendar value has to be found.
 * @return calendar value corresponding to the date.
 *///from  w  ww . j a  va2  s. com
@Override
public Calendar convertDateToCalendar(java.util.Date date) {
    Calendar calendar = null;
    if (date != null) {
        calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.clear(Calendar.ZONE_OFFSET);
        calendar.clear(Calendar.DST_OFFSET);
    }
    return calendar;
}

From source file:org.openmrs.module.kenyaemr.fragment.controller.facilityDashboard.FacilityDashboardFragmentController.java

private Map<String, Date> getReportDates(int month) {
    Map<String, Date> reportDates = new HashMap<String, Date>();
    Calendar gc = new GregorianCalendar();
    gc.set(Calendar.MONTH, month);
    gc.set(Calendar.DAY_OF_MONTH, 1);
    gc.clear(Calendar.HOUR);
    gc.clear(Calendar.HOUR_OF_DAY);
    gc.clear(Calendar.MINUTE);/* ww w.java  2 s  .  c  o  m*/
    gc.clear(Calendar.SECOND);
    gc.clear(Calendar.MILLISECOND);
    Date monthStart = gc.getTime();
    reportDates.put("startDate", monthStart);
    gc.add(Calendar.MONTH, 1);
    gc.add(Calendar.DAY_OF_MONTH, -1);
    Date monthEnd = gc.getTime();
    reportDates.put("endDate", monthEnd);
    return reportDates;
}

From source file:org.apache.ranger.audit.utils.RollingTimeUtil.java

private Date computeTopOfMinuteDate(int mins) {
    Date ret = null;/*w  w  w.ja va  2  s  .com*/

    Calendar calendarMin = Calendar.getInstance();
    calendarMin.add(Calendar.MINUTE, mins);
    calendarMin.clear(Calendar.SECOND);
    calendarMin.clear(Calendar.MILLISECOND);

    ret = calendarMin.getTime();

    return ret;
}

From source file:org.cloudgraph.hbase.slice.DatePredicateSliceTest.java

public void testEqual() throws IOException {
    long id = System.currentTimeMillis() + 10000; // space tests out more
    // than 1 second
    Calendar now = Calendar.getInstance();
    now.setTime(new Date(id));
    now.clear(Calendar.MILLISECOND);
    Node root = this.createGraph(id, now.getTime());
    service.commit(root.getDataGraph(), USERNAME);

    // fetch a slice
    Node fetched = this.fetchSliceEquals(now.getTime());
    debugGraph(fetched.getDataGraph());//from w  w w.ja  v  a 2s.c  om
    assertNotNull(fetched);
    assertTrue(fetched.getChildCount() == 1);
    assertNotNull(fetched.getChild(0).getDateField());
    assertTrue(fetched.getChild(0).getDateField().compareTo(now.getTime()) == 0);
}

From source file:org.cloudgraph.hbase.slice.DatePredicateSliceTest.java

public void testGreaterThan() throws IOException {
    long id = System.currentTimeMillis() + 20000; // space tests out more
    // than 1 second
    Calendar now = Calendar.getInstance();
    now.setTime(new Date(id));
    now.clear(Calendar.MILLISECOND);
    Node root = this.createGraph(id, now.getTime());
    service.commit(root.getDataGraph(), USERNAME);

    // fetch a slice
    Node fetched = this.fetchSliceGreaterThan(now.getTime());
    assertNotNull(fetched);/*from   w w w .ja  v  a  2 s  .c  o  m*/
    debugGraph(fetched.getDataGraph());
    assertTrue(fetched.getChildCount() == maxRows - 1);
    for (Node node : fetched.getChild())
        assertTrue(node.getDateField().compareTo(now.getTime()) > 0);
}