List of usage examples for java.util Calendar clear
public final void clear(int field)
Calendar
undefined. From source file:org.cloudgraph.hbase.slice.DatePredicateSliceTest.java
public void testLike() throws IOException { long id = System.currentTimeMillis() + 40000; // 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.fetchSliceLike(now.getTime(), "*date*", "*3"); assertNotNull(fetched);//from w ww. j a va 2 s .co m debugGraph(fetched.getDataGraph()); assertTrue(fetched.getChildCount() == 1); assertNotNull(fetched.getChild(0).getStringField()); assertTrue(fetched.getChild(0).getStringField().contains("date")); assertTrue(fetched.getChild(0).getStringField().contains("3")); }
From source file:org.apache.ranger.audit.utils.RollingTimeUtil.java
private Date computeTopOfHourDate(int hours) { Date ret = null;/*from ww w . ja v a 2 s . c o m*/ Calendar calendarHour = Calendar.getInstance(); calendarHour.add(Calendar.HOUR_OF_DAY, hours); calendarHour.clear(Calendar.MINUTE); calendarHour.clear(Calendar.SECOND); calendarHour.clear(Calendar.MILLISECOND); ret = calendarHour.getTime(); return ret; }
From source file:com.sap.dirigible.runtime.registry.RegistryServlet.java
private Calendar getCalendar(Date time) { Calendar calendar = Calendar.getInstance(); calendar.setTime(time); calendar.clear(Calendar.MILLISECOND); return calendar; }
From source file:org.cloudgraph.hbase.slice.DatePredicateSliceTest.java
public void testBetween() throws IOException { long id = System.currentTimeMillis() + 30000; // 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); int startIndex = 1; int endIndex = 4; Calendar start = Calendar.getInstance(); start.setTime(now.getTime());/*from w ww .ja v a 2s.c om*/ start.clear(Calendar.MILLISECOND); start.add(Calendar.DAY_OF_YEAR, startIndex); Calendar end = Calendar.getInstance(); end.setTime(now.getTime()); end.clear(Calendar.MILLISECOND); end.add(Calendar.DAY_OF_YEAR, endIndex); log.info(start.getTime()); log.info(end.getTime()); // fetch a slice Node fetched = this.fetchSliceBetween(now.getTime(), start.getTime(), end.getTime()); assertNotNull(fetched); debugGraph(fetched.getDataGraph()); assertTrue(fetched.getChildCount() == (endIndex - startIndex) + 1); assertNotNull(fetched.getChild(startIndex - 1).getDateField()); assertTrue(fetched.getChild(startIndex - 1).getDateField().compareTo(start.getTime()) == 0); assertTrue(fetched.getChild(endIndex - 1).getDateField().compareTo(end.getTime()) == 0); }
From source file:org.kuali.coeus.s2sgen.impl.datetime.S2SDateTimeServiceImpl.java
/** * * This method computes the number of months between any 2 given {@link java.sql.Date} objects * * @param dateStart starting date.//from ww w. ja v a 2 s . c o m * @param dateEnd end date. * * @return number of months between the start date and end date. */ @Override public ScaleTwoDecimal getNumberOfMonths(java.util.Date dateStart, java.util.Date dateEnd) { ScaleTwoDecimal monthCount = ScaleTwoDecimal.ZERO; int fullMonthCount = 0; Calendar startDate = Calendar.getInstance(); Calendar endDate = Calendar.getInstance(); startDate.setTime(dateStart); endDate.setTime(dateEnd); startDate.clear(Calendar.HOUR); startDate.clear(Calendar.MINUTE); startDate.clear(Calendar.SECOND); startDate.clear(Calendar.MILLISECOND); endDate.clear(Calendar.HOUR); endDate.clear(Calendar.MINUTE); endDate.clear(Calendar.SECOND); endDate.clear(Calendar.MILLISECOND); if (startDate.after(endDate)) { return ScaleTwoDecimal.ZERO; } int startMonthDays = startDate.getActualMaximum(Calendar.DATE) - startDate.get(Calendar.DATE); startMonthDays++; int startMonthMaxDays = startDate.getActualMaximum(Calendar.DATE); BigDecimal startMonthFraction = BigDecimal.valueOf(startMonthDays).setScale(2, RoundingMode.HALF_UP).divide( BigDecimal.valueOf(startMonthMaxDays).setScale(2, RoundingMode.HALF_UP), RoundingMode.HALF_UP); int endMonthDays = endDate.get(Calendar.DATE); int endMonthMaxDays = endDate.getActualMaximum(Calendar.DATE); BigDecimal endMonthFraction = BigDecimal.valueOf(endMonthDays).setScale(2, RoundingMode.HALF_UP).divide( BigDecimal.valueOf(endMonthMaxDays).setScale(2, RoundingMode.HALF_UP), RoundingMode.HALF_UP); startDate.set(Calendar.DATE, 1); endDate.set(Calendar.DATE, 1); while (startDate.getTimeInMillis() < endDate.getTimeInMillis()) { startDate.set(Calendar.MONTH, startDate.get(Calendar.MONTH) + 1); fullMonthCount++; } fullMonthCount = fullMonthCount - 1; monthCount = monthCount.add(new ScaleTwoDecimal(fullMonthCount)) .add(new ScaleTwoDecimal(startMonthFraction)).add(new ScaleTwoDecimal(endMonthFraction)); return monthCount; }
From source file:org.kuali.coeus.propdev.impl.print.ProposalBaseStream.java
/** * * This method computes the number of months between any 2 given {@link java.sql.Date} objects * * @param dateStart starting date.//from ww w. j a va2 s. com * @param dateEnd end date. * * @return number of months between the start date and end date. */ public ScaleTwoDecimal getNumberOfMonths(Date dateStart, Date dateEnd) { ScaleTwoDecimal monthCount = ScaleTwoDecimal.ZERO; int fullMonthCount = 0; Calendar startDate = Calendar.getInstance(); Calendar endDate = Calendar.getInstance(); startDate.setTime(dateStart); endDate.setTime(dateEnd); startDate.clear(Calendar.HOUR); startDate.clear(Calendar.MINUTE); startDate.clear(Calendar.SECOND); startDate.clear(Calendar.MILLISECOND); endDate.clear(Calendar.HOUR); endDate.clear(Calendar.MINUTE); endDate.clear(Calendar.SECOND); endDate.clear(Calendar.MILLISECOND); if (startDate.after(endDate)) { return ScaleTwoDecimal.ZERO; } int startMonthDays = startDate.getActualMaximum(Calendar.DATE) - startDate.get(Calendar.DATE); startMonthDays++; int startMonthMaxDays = startDate.getActualMaximum(Calendar.DATE); BigDecimal startMonthFraction = BigDecimal.valueOf(startMonthDays).setScale(2, RoundingMode.HALF_UP).divide( BigDecimal.valueOf(startMonthMaxDays).setScale(2, RoundingMode.HALF_UP), RoundingMode.HALF_UP); int endMonthDays = endDate.get(Calendar.DATE); int endMonthMaxDays = endDate.getActualMaximum(Calendar.DATE); BigDecimal endMonthFraction = BigDecimal.valueOf(endMonthDays).setScale(2, RoundingMode.HALF_UP).divide( BigDecimal.valueOf(endMonthMaxDays).setScale(2, RoundingMode.HALF_UP), RoundingMode.HALF_UP); startDate.set(Calendar.DATE, 1); endDate.set(Calendar.DATE, 1); while (startDate.getTimeInMillis() < endDate.getTimeInMillis()) { startDate.set(Calendar.MONTH, startDate.get(Calendar.MONTH) + 1); fullMonthCount++; } fullMonthCount = fullMonthCount - 1; monthCount = monthCount.add(new ScaleTwoDecimal(fullMonthCount)) .add(new ScaleTwoDecimal(startMonthFraction)).add(new ScaleTwoDecimal(endMonthFraction)); return monthCount; }
From source file:org.apache.ranger.audit.utils.RollingTimeUtil.java
private Date computeTopOfDayDate(int days) { Date ret = null;/*from w ww. j a v a 2 s. co m*/ Calendar calendarDay = Calendar.getInstance(); calendarDay.add(Calendar.DAY_OF_MONTH, days); calendarDay.set(Calendar.HOUR_OF_DAY, 0); calendarDay.clear(Calendar.MINUTE); calendarDay.clear(Calendar.SECOND); calendarDay.clear(Calendar.MILLISECOND); ret = calendarDay.getTime(); return ret; }
From source file:de.berlios.statcvs.xml.report.CommitActivityChart.java
private void addToXYSeries(XYSeries series, CvsRevision rev) { Calendar cal = Calendar.getInstance(); cal.setTime(rev.getDate());//from ww w. ja va 2 s . co m double hour = cal.get(Calendar.HOUR_OF_DAY); double minutes = cal.get(Calendar.MINUTE); // clear time info cal.clear(Calendar.HOUR); cal.clear(Calendar.HOUR_OF_DAY); cal.clear(Calendar.MINUTE); cal.clear(Calendar.SECOND); cal.clear(Calendar.MILLISECOND); series.add(cal.getTime().getTime(), hour + (minutes / 60)); }
From source file:com.square.core.agent.desactivation.relation.DesactivationRelationsAgentJmxThead.java
@Override public void run() { agent.setEtat("Agent DesactivationRelations debut de traitement"); try {// w w w .java 2s. c o m final Calendar date = Calendar.getInstance(); if (StringUtils.isNotBlank(agent.getDate())) { final SimpleDateFormat formatDate = new SimpleDateFormat("dd/MM/yyyy"); date.setTime(formatDate.parse(agent.getDate())); } date.clear(Calendar.HOUR); date.clear(Calendar.MINUTE); date.clear(Calendar.SECOND); date.clear(Calendar.MILLISECOND); final SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss"); agent.setEtat("Lancement desactivation relations la date du " + format.format(date.getTime())); int counter = 0; // Cration des criteres des relations dsactiver final RelationCriteresRechercheDto criterias = new RelationCriteresRechercheDto(); criterias.setDateFinMax(date); criterias.setActif(true); criterias.setSupprime(null); // Calcul du nombre total final int nbTotal = personneService.countRelationsParCriteres(criterias); agent.setEtat("Traitement des relations : " + nbTotal + " lments"); // Recuparation des ids de relations List<Long> listeRelationsADesactiver = personneService.rechercherIdsRelationsADesactiver(date, agent.getPagination()); while (listeRelationsADesactiver.size() > 0 && !agent.isStopping()) { counter += listeRelationsADesactiver.size(); logger.debug("Dsactivation des relations en cours " + counter + " / " + nbTotal); personneService.desactiverRelations(listeRelationsADesactiver); // Rcupration des relations dsactiver listeRelationsADesactiver = personneService.rechercherIdsRelationsADesactiver(date, agent.getPagination()); } } catch (Exception e) { agent.setEtat(e.getMessage()); e.printStackTrace(); } finally { agent.getSessionFactory().openSession().close(); agent.stop(); } }
From source file:de.berlios.statcvs.xml.report.CommitActivityChart.java
private XYSeries createXYSeries(String title, Iterator it) { XYSeries series = new XYSeries(title); while (it.hasNext()) { CvsRevision rev = (CvsRevision) it.next(); Calendar cal = Calendar.getInstance(); cal.setTime(rev.getDate());/*from w w w .j a va2 s .c om*/ double hour = cal.get(Calendar.HOUR_OF_DAY); double minutes = cal.get(Calendar.MINUTE); // clear time info cal.clear(Calendar.HOUR); cal.clear(Calendar.HOUR_OF_DAY); cal.clear(Calendar.MINUTE); cal.clear(Calendar.SECOND); cal.clear(Calendar.MILLISECOND); series.add(cal.getTime().getTime(), hour + (minutes / 60)); } return series; }