List of usage examples for java.util Calendar clone
@Override
public Object clone()
From source file:org.kuali.kra.award.paymentreports.closeout.AwardCloseoutServiceImpl.java
protected java.util.Date getCloseoutDueDate(Date finalExpirationDate, AwardReportTerm awardReportTerm, Calendar calendar) { java.util.Date dueDate = calendar.getTime(); if (awardReportTerm.getDueDate() != null) { dueDate = awardReportTerm.getDueDate(); } else if (awardReportTerm.getFrequency() != null && (awardReportTerm.getFrequency().getNumberOfMonths() != null || awardReportTerm.getFrequency().getNumberOfDays() != null || awardReportTerm.getFrequency().getAdvanceNumberOfMonths() != null || awardReportTerm.getFrequency().getAdvanceNumberOfDays() != null)) { // don't want to change calendar's value dueDate = getCalculatedDueDate(finalExpirationDate, awardReportTerm, (Calendar) calendar.clone()); }/*from w w w . jav a 2 s . c o m*/ return dueDate; }
From source file:org.betaconceptframework.astroboa.portal.utility.CalendarUtils.java
public List<Calendar> getDiscreteDatesInPeriod(Calendar fromCalendarInclusive, Calendar toCalendarInclusive) { List<Calendar> discreteDatesInPeriod = new ArrayList<Calendar>(); if (fromCalendarInclusive != null && toCalendarInclusive != null) { if (fromCalendarInclusive.before(toCalendarInclusive)) { // when we process discrete dates we reset the hour. clearTimeFromCalendar(fromCalendarInclusive); while (fromCalendarInclusive.before(toCalendarInclusive) || fromCalendarInclusive.equals(toCalendarInclusive)) { Calendar discreteDate = (GregorianCalendar) fromCalendarInclusive.clone(); discreteDatesInPeriod.add(discreteDate); fromCalendarInclusive.add(Calendar.DAY_OF_MONTH, 1); }/*from ww w. ja v a 2 s . co m*/ } else { // check if both dates are equal and return one date only clearTimeFromCalendar(fromCalendarInclusive); clearTimeFromCalendar(toCalendarInclusive); if (fromCalendarInclusive.equals(toCalendarInclusive)) { Calendar discreteDate = (GregorianCalendar) fromCalendarInclusive.clone(); discreteDatesInPeriod.add(discreteDate); } } } else if (fromCalendarInclusive != null && toCalendarInclusive == null) { // we are looking for a specific date // when we process discrete dates we reset the hour. we assume that the date field for which we set the criteria contains date(s) without hour data. clearTimeFromCalendar(fromCalendarInclusive); Calendar discreteDate = (GregorianCalendar) fromCalendarInclusive.clone(); discreteDatesInPeriod.add(discreteDate); } else if (fromCalendarInclusive == null && toCalendarInclusive != null) { // we are looking for a specific date // when we process discrete dates we reset the hour. we assume that the date field for which we set the criteria contains date(s) without hour data. clearTimeFromCalendar(toCalendarInclusive); Calendar discreteDate = (GregorianCalendar) toCalendarInclusive.clone(); discreteDatesInPeriod.add(discreteDate); } return discreteDatesInPeriod; }
From source file:com.intuit.wasabi.tests.service.IntegrationExperiment.java
/** * Checks if an experiment is created in a 15 second time window and yields all the correct data. * * @throws java.text.ParseException if the dates are not correctly formatted. *//*from w w w . j av a 2 s.c o m*/ @Test(dependsOnGroups = { "ping" }) public void t_createAndValidateExperiment() throws java.text.ParseException { Calendar now = Calendar.getInstance(TimeZone.getTimeZone("UTC")); now.add(Calendar.SECOND, -2); // adjust: drops milliseconds. -2 to avoid all problems with that Calendar latest = (Calendar) now.clone(); latest.add(Calendar.SECOND, 15); Experiment created = postExperiment(completeExperiment); completeExperiment.setState(Constants.EXPERIMENT_STATE_DRAFT); assertEqualModelItems(created, completeExperiment, new DefaultNameExclusionStrategy("id", "creationTime", "modificationTime", "results", "ruleJson", "hypothesisIsCorrect")); String nowStr = TestUtils.getTimeString(now); String latestStr = TestUtils.getTimeString(latest); Calendar creationTime = TestUtils.parseTime(created.creationTime); Assert.assertTrue(creationTime.after(now) && creationTime.before(latest), "Creation time is not in the correct interval.\nEarly: " + nowStr + "\nCreated: " + created.creationTime + "\nLate: " + latestStr); Calendar modificationTime = TestUtils.parseTime(created.modificationTime); Assert.assertTrue(modificationTime.after(now) && modificationTime.before(latest), "Modification time is not in the correct interval.\nEarly: " + nowStr + "\nCreated: " + created.modificationTime + "\nLate: " + latestStr); Assert.assertEquals(created.creationTime, created.modificationTime, "Creation and Modification are not equal."); completeExperiment.update(created); }
From source file:org.gss_project.gss.server.ejb.GSSDAOBean.java
@Override public void updateAccounting(User user, Date date, long bandwidthDiff) { AccountingInfo ai = null;//from w w w . ja v a 2 s . c om try { ai = (AccountingInfo) manager .createQuery("select ai from AccountingInfo ai " + "where ai.user=:user and ai.dateFrom<=:date and ai.dateTo>:date") .setParameter("user", user).setParameter("date", date).getSingleResult(); } catch (NoResultException e) { ai = null; } if (ai == null) { Calendar dateFrom; Calendar dateTo; Calendar thisDate = new GregorianCalendar(); thisDate.setTime(date); dateFrom = (Calendar) thisDate.clone(); dateFrom.set(Calendar.DAY_OF_MONTH, thisDate.getActualMinimum(Calendar.DAY_OF_MONTH)); dateFrom.set(Calendar.HOUR_OF_DAY, thisDate.getActualMinimum(Calendar.HOUR_OF_DAY)); dateFrom.set(Calendar.MINUTE, thisDate.getActualMinimum(Calendar.MINUTE)); dateFrom.set(Calendar.SECOND, thisDate.getActualMinimum(Calendar.SECOND)); dateFrom.set(Calendar.MILLISECOND, thisDate.getActualMinimum(Calendar.MILLISECOND)); dateTo = (Calendar) thisDate.clone(); dateTo.set(Calendar.DAY_OF_MONTH, thisDate.getActualMaximum(Calendar.DAY_OF_MONTH)); dateTo.set(Calendar.HOUR_OF_DAY, thisDate.getActualMaximum(Calendar.HOUR_OF_DAY)); dateTo.set(Calendar.MINUTE, thisDate.getActualMaximum(Calendar.MINUTE)); dateTo.set(Calendar.SECOND, thisDate.getActualMaximum(Calendar.SECOND)); dateTo.set(Calendar.MILLISECOND, thisDate.getActualMaximum(Calendar.MILLISECOND)); ai = new AccountingInfo(user, dateFrom.getTime(), dateTo.getTime()); manager.persist(ai); } // Do the update. ai.updateBandwidth(bandwidthDiff); }
From source file:com.alibaba.otter.manager.biz.monitor.impl.AbstractRuleMonitor.java
protected boolean isAfter(Calendar now, String time) { String[] hourAndMin = StringUtils.split(time, ":"); if (hourAndMin == null || hourAndMin.length != 2) { log.error("error period time format in rule : " + time); return isInPeriodWhenErrorFormat(); }// w w w .j a va2 s . c o m int hour; int min; try { hour = Integer.parseInt(hourAndMin[0]); min = Integer.parseInt(hourAndMin[1]); } catch (NumberFormatException e) { log.error("error period time format in rule : " + time, e); return isInPeriodWhenErrorFormat(); } if (hour > 24 || min > 60) { log.error("error period time format in rule : " + time); return isInPeriodWhenErrorFormat(); } Calendar when = (Calendar) now.clone(); when.set(Calendar.HOUR_OF_DAY, hour); when.set(Calendar.MINUTE, min); return !now.before(when); }
From source file:org.pensco.CreateStatementsOp.java
protected void createStatementsForCustomer(String inCustomer) throws IOException, COSVisitorException { DocumentModel doc = null;/*from w w w . j ava 2 s . co m*/ int pos = inCustomer.indexOf(" "); String firstName = inCustomer.substring(0, pos); String lastName = inCustomer.substring(pos + 1); String titlePrefix = lastName.substring(0, lastName.length() < 8 ? lastName.length() - 1 : 8) + "-" + firstName.charAt(0); Calendar startCal = (Calendar) today.clone(); int nbStatements = ToolsMisc.randomInt(3, 6); startCal.add(Calendar.DATE, -(nbStatements * (DAYS_BETWEEN_STATEMENTS + 2))); for (int i = 0; i < nbStatements; ++i) { int year = startCal.get(Calendar.YEAR); int month = startCal.get(Calendar.MONTH); int day = startCal.get(Calendar.DATE); String title = titlePrefix + "-" + year + "-" + String.format("%02d", month + 1) + "-" + String.format("%02d", day); Calendar inNDays = (Calendar) startCal.clone(); inNDays.add(Calendar.DATE, DAYS_BETWEEN_STATEMENTS); doc = session.createDocumentModel(parentPath, title, "File"); doc.setPropertyValue("dc:title", title); doc.setPropertyValue("dc:created", inNDays); doc.setPropertyValue("dc:modified", inNDays); String user = MODIF_USERS[ToolsMisc.randomInt(0, MODIF_USERS_MAX)]; doc.setPropertyValue("dc:lastContributor", user); contributors[0] = user; doc.setPropertyValue("dc:contributors", contributors); doc.setPropertyValue("ac:kind", "Statement"); doc.setPropertyValue("ac:customer_name", inCustomer); doc.setPropertyValue("ac:deal_id", MiscUtils.getSomeUID(6)); doc.setPropertyValue("ac:st_start", (Serializable) startCal.clone()); doc.setPropertyValue("ac:st_end", (Serializable) inNDays.clone()); Blob thePdf = buildPDF(inCustomer, startCal, inNDays); thePdf.setFilename(title + ".pdf"); thePdf.setMimeType("application/pdf"); doc.setPropertyValue("file:content", (Serializable) thePdf); doc.setPropertyValue("ac:st_lines", statementLines); doc.putContextData(DublinCoreListener.DISABLE_DUBLINCORE_LISTENER, true); doc = session.createDocument(doc);// Disable dublincore doc.putContextData(DublinCoreListener.DISABLE_DUBLINCORE_LISTENER, true); doc = session.saveDocument(doc); // Prepare next loop startCal.add(Calendar.DATE, DAYS_BETWEEN_STATEMENTS + 1); countCreated += 1; } }
From source file:org.everit.jira.timetracker.plugin.JiraTimetrackerPluginImpl.java
/** * Check the given date, the user have worklogs or not. * * @param date//from w w w .j av a 2s. c om * The date what have to check. * @return If The user have worklogs the given date then true, esle false. * @throws GenericEntityException * GenericEntity Exception. */ private boolean isContainsWorklog(final Date date) throws GenericEntityException { JiraAuthenticationContext authenticationContext = ComponentAccessor.getJiraAuthenticationContext(); ApplicationUser user = authenticationContext.getUser(); Calendar startDate = DateTimeConverterUtil.setDateToDayStart(date); Calendar endDate = (Calendar) startDate.clone(); endDate.add(Calendar.DAY_OF_MONTH, 1); List<EntityCondition> exprList = createWorklogQueryExprList(user, startDate, endDate); List<GenericValue> worklogGVList = ComponentAccessor.getOfBizDelegator().findByAnd("Worklog", exprList); return !((worklogGVList == null) || worklogGVList.isEmpty()); }
From source file:org.everit.jira.timetracker.plugin.JiraTimetrackerPluginImpl.java
/** * Check the given date is contains enough worklog. The worklog spent time have to be equal or * greater then 8 hours./*w w w. j a va 2s . c o m*/ * * @param date * The date what have to check. * @param checkNonWorking * Exclude or not the non-working issues. * @return True if the day contains enough worklog or weeked or exclude date. * @throws GenericEntityException * If GenericEntity Exception. */ private boolean isContainsEnoughWorklog(final Date date, final boolean checkNonWorking) throws GenericEntityException { JiraAuthenticationContext authenticationContext = ComponentAccessor.getJiraAuthenticationContext(); ApplicationUser user = authenticationContext.getUser(); Calendar startDate = DateTimeConverterUtil.setDateToDayStart(date); Calendar endDate = (Calendar) startDate.clone(); endDate.add(Calendar.DAY_OF_MONTH, 1); List<EntityCondition> exprList = createWorklogQueryExprList(user, startDate, endDate); List<GenericValue> worklogGVList = ComponentAccessor.getOfBizDelegator().findByAnd("Worklog", exprList); if ((worklogGVList == null) || worklogGVList.isEmpty()) { return false; } if (checkNonWorking) { removeNonWorkingIssues(worklogGVList); } long timeSpent = 0; for (GenericValue worklog : worklogGVList) { timeSpent += worklog.getLong("timeworked").longValue(); } if (timeSpent < DateTimeConverterUtil.EIGHT_HOUR_IN_SECONDS) { return false; } return true; }
From source file:cs.umass.edu.prepare.view.activities.CalendarActivity.java
/** * Allows the user to set time for adherence data where the time is unknown. * @param medication the medication for which the adherence is being modified. * @param index the index of the adherence being modified, i.e. AM or PM. *//* www .ja v a 2 s . com*/ private void setTimeTaken(final Medication medication, final Calendar dateKey, final int index) { final Dialog dialog = new Dialog(this); dialog.setContentView(R.layout.dialog_set_time); final TimePicker timePicker = (TimePicker) dialog.findViewById(R.id.time_picker); Button cancelButton = (Button) dialog.findViewById(R.id.btn_time_cancel); cancelButton.setOnClickListener(v -> dialog.dismiss()); Button saveButton = (Button) dialog.findViewById(R.id.btn_time_save); saveButton.setOnClickListener(v -> { Calendar time = Utils.getTimeNoInterval(timePicker); // TODO: Store times taken Map<Medication, Adherence[]> dailyAdherence = adherenceData.get(dateKey); Adherence[] adherence = dailyAdherence.get(medication); adherence[index].setTimeTaken(time); Calendar[] schedule = dailySchedule.get(medication); Calendar timeToTake = (Calendar) time.clone(); timeToTake.set(Calendar.HOUR_OF_DAY, schedule[index].get(Calendar.HOUR_OF_DAY)); timeToTake.set(Calendar.MINUTE, schedule[index].get(Calendar.MINUTE)); Calendar upperBound = (Calendar) timeToTake.clone(); upperBound.add(Calendar.HOUR_OF_DAY, 1); Calendar lowerBound = (Calendar) timeToTake.clone(); lowerBound.add(Calendar.HOUR_OF_DAY, -1); if (time.after(upperBound) || time.before(lowerBound)) { adherence[index].setAdherenceType(Adherence.AdherenceType.TAKEN_EARLY_OR_LATE); } else { adherence[index].setAdherenceType(Adherence.AdherenceType.TAKEN); } dialog.dismiss(); refresh(); DataIO preferences = DataIO.getInstance(CalendarActivity.this); preferences.setAdherenceData(this, adherenceData); }); dialog.show(); }
From source file:org.everit.jira.timetracker.plugin.JiraTimetrackerPluginImpl.java
@Override public List<EveritWorklog> getWorklogs(final String selectedUser, final Date date, final Date finalDate) throws ParseException, GenericEntityException { Calendar startDate = DateTimeConverterUtil.setDateToDayStart(date); Calendar endDate = (Calendar) startDate.clone(); if (finalDate == null) { endDate.add(Calendar.DAY_OF_MONTH, 1); } else {/* ww w.ja va 2 s . com*/ endDate = DateTimeConverterUtil.setDateToDayStart(finalDate); endDate.add(Calendar.DAY_OF_MONTH, 1); } List<EveritWorklog> worklogs = new ArrayList<EveritWorklog>(); JiraAuthenticationContext authenticationContext = ComponentAccessor.getJiraAuthenticationContext(); ApplicationUser loggedInUser = authenticationContext.getUser(); String userKey; if ((selectedUser == null) || "".equals(selectedUser)) { userKey = loggedInUser.getKey(); } else { userKey = selectedUser; } List<EntityCondition> exprList = createWorklogQueryExprListWithPermissionCheck(userKey, loggedInUser, startDate, endDate); List<GenericValue> worklogGVList = ComponentAccessor.getOfBizDelegator().findByAnd("IssueWorklogView", exprList); LOGGER.warn("JTTP LOG: getWorklogs worklog GV list size: " + worklogGVList.size()); for (GenericValue worklogGv : worklogGVList) { EveritWorklog worklog = new EveritWorklog(worklogGv, collectorIssuePatterns); worklogs.add(worklog); } Collections.sort(worklogs, new EveritWorklogComparator()); LOGGER.warn("JTTP LOG: getWorklogs worklog GV list size: " + worklogs.size()); return worklogs; }