List of usage examples for java.util Calendar clone
@Override
public Object clone()
From source file:gbc.jtimecalc.AbstractTimeDifferenceCalculatorTest.java
public void shouldReturn30Days1Hour0Minutes0seconds() { Calendar end = prepareCalendar(2006, Calendar.FEBRUARY, 1, 1, 0, 0, 0); // 1.02.2006 01:00:00.0 setEndTime(end.getTimeInMillis());/*from ww w . ja va 2s.co m*/ Calendar start = (Calendar) end.clone(); start.add(Calendar.DATE, -30); start.add(Calendar.HOUR, -1); setStartTime(start.getTimeInMillis()); // 2.01.2006 00:00:00.0 expectedValue = messages.get("30Days1Hour"); }
From source file:gbc.jtimecalc.AbstractTimeDifferenceCalculatorTest.java
public void shouldReturn2Months3Days0Hours0Minutes0seconds() { Calendar end = prepareCalendar(2006, Calendar.FEBRUARY, 1, 0, 0, 0, 0); // 1.02.2006 00:00:00.0 setEndTime(end.getTimeInMillis());//w w w.j a v a 2 s. c o m Calendar start = (Calendar) end.clone(); start.set(Calendar.MONTH, Calendar.DECEMBER); start.set(Calendar.YEAR, 2005); // 1.12.2005 00:00:00.0 setStartTime(start.getTimeInMillis()); expectedValue = messages.get("2Months3Days"); }
From source file:org.psystems.dicom.browser.server.stat.StatClientRequestsChartServlet2.java
/** * Returns a sample dataset.//ww w.ja va 2s.com * * @return The dataset. */ private CategoryDataset createDataset() { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); Calendar calendarEnd = Calendar.getInstance(); int tzoffset = calendarEnd.getTimeZone().getOffset(calendarEnd.getTimeInMillis()); long timeEnd = calendarEnd.getTimeInMillis(); timeEnd = timeEnd - (timeEnd % (60 * 60 * 24 * 1000)) - tzoffset; calendarEnd.setTimeInMillis(timeEnd); try { Connection connection = Util.getConnection("main", getServletContext()); Calendar calendarBegin = (Calendar) calendarEnd.clone(); calendarBegin.add(Calendar.DAY_OF_MONTH, -7); getMetrics(connection, "", "CLIENT_CONNECTIONS", calendarBegin, calendarEnd, dataset); getMetrics(connection, "", "CLIENT_CONNECTIONS", calendarBegin, calendarEnd, dataset); } catch (SQLException e) { logger.error(e); e.printStackTrace(); } // result.addValue(20.3, "product 1 (US)", "01.01.2010"); // result.addValue(27.2, "product 1 (US)", "02.01.2010"); // result.addValue(19.7, "product 1 (US)", "03.01.2010"); // result.addValue(19.7, "product 1 (US)", "04.01.2010"); // result.addValue(19.7, "product 1 (US)", "05.01.2010"); // result.addValue(19.7, "product 1 (US)", "06.01.2010"); // result.addValue(19.7, "product 1 (US)", "07.01.2010"); // // result.addValue(19.4, "product 1 (Europe)", "01.01.2010"); // result.addValue(10.9, "product 1 (Europe)", "02.01.2010"); // result.addValue(18.4, "product 1 (Europe)", "03.01.2010"); // result.addValue(19.7, "product 1 (Europe)", "04.01.2010"); // result.addValue(19.7, "product 1 (Europe)", "05.01.2010"); // result.addValue(19.7, "product 1 (Europe)", "06.01.2010"); // result.addValue(19.7, "product 1 (Europe)", "07.01.2010"); return dataset; }
From source file:org.psystems.dicom.browser.server.stat.StatDailyLoadChartServlet2.java
/** * Returns a sample dataset.//from w ww.j a v a 2 s .c o m * * @return The dataset. */ private CategoryDataset createDataset() { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); Calendar calendarEnd = Calendar.getInstance(); int tzoffset = calendarEnd.getTimeZone().getOffset(calendarEnd.getTimeInMillis()); long timeEnd = calendarEnd.getTimeInMillis(); timeEnd = timeEnd - (timeEnd % (60 * 60 * 24 * 1000)) - tzoffset; calendarEnd.setTimeInMillis(timeEnd); try { Connection connection = Util.getConnection("main", getServletContext()); Calendar calendarBegin = (Calendar) calendarEnd.clone(); calendarBegin.add(Calendar.DAY_OF_MONTH, -7); getMetrics(connection, "??? (DCM-)", "ALL_DCM_SIZE", calendarBegin, calendarEnd, dataset); getMetrics(connection, "? (JPG-)", "ALL_IMAGE_SIZE", calendarBegin, calendarEnd, dataset); } catch (SQLException e) { logger.error(e); e.printStackTrace(); } // result.addValue(20.3, "product 1 (US)", "01.01.2010"); // result.addValue(27.2, "product 1 (US)", "02.01.2010"); // result.addValue(19.7, "product 1 (US)", "03.01.2010"); // result.addValue(19.7, "product 1 (US)", "04.01.2010"); // result.addValue(19.7, "product 1 (US)", "05.01.2010"); // result.addValue(19.7, "product 1 (US)", "06.01.2010"); // result.addValue(19.7, "product 1 (US)", "07.01.2010"); // // result.addValue(19.4, "product 1 (Europe)", "01.01.2010"); // result.addValue(10.9, "product 1 (Europe)", "02.01.2010"); // result.addValue(18.4, "product 1 (Europe)", "03.01.2010"); // result.addValue(19.7, "product 1 (Europe)", "04.01.2010"); // result.addValue(19.7, "product 1 (Europe)", "05.01.2010"); // result.addValue(19.7, "product 1 (Europe)", "06.01.2010"); // result.addValue(19.7, "product 1 (Europe)", "07.01.2010"); return dataset; }
From source file:uk.ac.ox.oucs.vle.ModuleImpl.java
/** * /*from ww w . j a va 2 s . c o m*/ */ public void initialise() { Calendar calendar = new GregorianCalendar(); calendar.set(Calendar.HOUR, 0); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); lastMidnight = (Date) calendar.getTime(); int aboutToCloseDays = getAboutToCloseDays(); Calendar today = (Calendar) calendar.clone(); today.add(Calendar.DATE, aboutToCloseDays); todayMidnight = (Date) today.getTime(); int aboutToStartDays = getAboutToStartDays(); Calendar tomorrow = (Calendar) calendar.clone(); tomorrow.add(Calendar.DATE, aboutToStartDays); aboutToStart = (Date) tomorrow.getTime(); log.info("ModuleImpl.initialise"); log.info("Last Midnight [" + DateFormat.getInstance().format(lastMidnight) + "]"); log.info("Today Midnight [" + DateFormat.getInstance().format(todayMidnight) + "]"); log.info("About to Start [" + DateFormat.getInstance().format(aboutToStart) + "]"); log.info("Courses about to Close [close date between " + DateFormat.getInstance().format(lastMidnight) + " and " + DateFormat.getInstance().format(todayMidnight) + "]"); log.info("Courses about to Start [start date between " + DateFormat.getInstance().format(todayMidnight) + " and " + DateFormat.getInstance().format(aboutToStart) + "]"); }
From source file:org.nuxeo.cm.demo.UpdateDemoData.java
private Calendar _buildDate(Calendar inDate, int inDays, boolean inOkIfAfterToday) { Calendar d = (Calendar) inDate.clone(); d.add(Calendar.DATE, inDays); if (d.after(_today) && !inOkIfAfterToday) { d = (Calendar) _today.clone(); }//from w w w .j a v a2 s .co m return d; }
From source file:DateUtil.java
/** * Returns true if the two calendars represent dates that fall in the same * week, else false. A week here is defined by the Calendar.WEEK_OF_YEAR * package. Special provisions have been made to test weeks than may span the * end/beginning of a year, and returning true if the two calendars are * specifying dates within such a week, despite Calendar.WEEK_OF_YEAR being * unequal for the two Calendars.//from w w w .j av a2 s . c om * * @param c1 * Calendar one. * @param c2 * Calendar two. * @return boolean. */ public static boolean inSameWeek(Calendar c1, Calendar c2) { if (inSameYear(c1, c2) && (c1.get(Calendar.WEEK_OF_YEAR) == c2.get(Calendar.WEEK_OF_YEAR))) return true; Calendar tmp; if (c1.before(c2)) { tmp = c2; c2 = c1; c1 = tmp; } int c1week = c1.get(Calendar.WEEK_OF_YEAR); int c2week = c1.get(Calendar.WEEK_OF_YEAR); if (c1.get(Calendar.YEAR) == c2.get(Calendar.YEAR) + 1) { if (c1week == c1.getActualMinimum(Calendar.WEEK_OF_YEAR) && c2week == c2.getActualMaximum(Calendar.WEEK_OF_YEAR)) { tmp = (Calendar) c2.clone(); tmp.add(Calendar.DAY_OF_YEAR, 7); if (tmp.get(Calendar.WEEK_OF_YEAR) > c1week) return true; } } return false; }
From source file:com.health.openscale.gui.GraphFragment.java
private void generateLineData(Calendar calMonth) { scaleDataList = openScale.getScaleDataOfMonth(calYears.get(Calendar.YEAR), calMonth.get(Calendar.MONTH)); float maxValue = openScale.getMaxValueOfScaleData(calYears.get(Calendar.YEAR), calMonth.get(Calendar.MONTH)); SimpleDateFormat day_date = new SimpleDateFormat("dd", Locale.getDefault()); Calendar calDays = (Calendar) calMonth.clone(); calDays.set(Calendar.DAY_OF_MONTH, 1); int maxDays = calDays.getActualMaximum(Calendar.DAY_OF_MONTH); List<AxisValue> axisValues = new ArrayList<AxisValue>(); for (int i = 0; i < maxDays; i++) { String day_name = day_date.format(calDays.getTime()); axisValues.add(new AxisValue(i, day_name.toCharArray())); calDays.add(Calendar.DAY_OF_MONTH, 1); }/*w w w . ja va 2 s . co m*/ List<PointValue> valuesWeight = new ArrayList<PointValue>(); List<PointValue> valuesFat = new ArrayList<PointValue>(); List<PointValue> valuesWater = new ArrayList<PointValue>(); List<PointValue> valuesMuscle = new ArrayList<PointValue>(); List<Line> lines = new ArrayList<Line>(); Calendar calDB = Calendar.getInstance(); for (ScaleData scaleEntry : scaleDataList) { calDB.setTime(scaleEntry.date_time); valuesWeight.add(new PointValue(calDB.get(Calendar.DAY_OF_MONTH) - 1, scaleEntry.weight)); valuesFat.add(new PointValue(calDB.get(Calendar.DAY_OF_MONTH) - 1, scaleEntry.fat)); valuesWater.add(new PointValue(calDB.get(Calendar.DAY_OF_MONTH) - 1, scaleEntry.water)); valuesMuscle.add(new PointValue(calDB.get(Calendar.DAY_OF_MONTH) - 1, scaleEntry.muscle)); } Line lineWeight = new Line(valuesWeight).setColor(Utils.COLOR_VIOLET).setCubic(true) .setHasLabels(prefs.getBoolean("labelsEnable", true)) .setFormatter(new SimpleValueFormatter(1, false, null, null)); Line lineFat = new Line(valuesFat).setColor(Utils.COLOR_ORANGE).setCubic(true) .setHasLabels(prefs.getBoolean("labelsEnable", true)) .setFormatter(new SimpleValueFormatter(1, false, null, null)); Line lineWater = new Line(valuesWater).setColor(Utils.COLOR_BLUE).setCubic(true) .setHasLabels(prefs.getBoolean("labelsEnable", true)) .setFormatter(new SimpleValueFormatter(1, false, null, null)); Line lineMuscle = new Line(valuesMuscle).setColor(Utils.COLOR_GREEN).setCubic(true) .setHasLabels(prefs.getBoolean("labelsEnable", true)) .setFormatter(new SimpleValueFormatter(1, false, null, null)); activeLines = new ArrayList<lines>(); if (prefs.getBoolean("weightEnable", true)) { lines.add(lineWeight); activeLines.add(GraphFragment.lines.WEIGHT); } if (prefs.getBoolean("fatEnable", true)) { lines.add(lineFat); activeLines.add(GraphFragment.lines.FAT); } if (prefs.getBoolean("waterEnable", true)) { lines.add(lineWater); activeLines.add(GraphFragment.lines.WATER); } if (prefs.getBoolean("muscleEnable", true)) { lines.add(lineMuscle); activeLines.add(GraphFragment.lines.MUSCLE); } LineChartData lineData = new LineChartData(lines); lineData.setAxisXBottom(new Axis(axisValues).setHasLines(true).setTextColor(Color.BLACK)); lineData.setAxisYLeft(new Axis().setHasLines(true).setMaxLabelChars(3).setTextColor(Color.BLACK)); chartTop.setLineChartData(lineData); chartTop.setViewportCalculationEnabled(false); if (maxValue == 0.0) { maxValue = 100; } else { maxValue += 20; } Viewport v = new Viewport(0, (int) maxValue, maxDays - 1, 0); chartTop.setMaximumViewport(v); chartTop.setCurrentViewport(v, true); chartTop.setZoomType(ZoomType.HORIZONTAL); }
From source file:org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexEditorContext.java
/** * Checks if last suggestion build time was done sufficiently in the past AND that there were non-zero indexedNodes * stored in the last run. Note, if index is updated only to rebuild suggestions, even then we update indexedNodes, * which would be zero in case it was a forced update of suggestions. * @return is suggest dict should be updated *//*from w w w .j av a2 s . c o m*/ private boolean shouldUpdateSuggestions() { boolean updateSuggestions = false; if (definition.isSuggestEnabled()) { NodeBuilder suggesterStatus = definitionBuilder.child(":suggesterStatus"); PropertyState suggesterLastUpdatedValue = suggesterStatus.getProperty("lastUpdated"); if (suggesterLastUpdatedValue != null) { Calendar suggesterLastUpdatedTime = ISO8601.parse(suggesterLastUpdatedValue.getValue(Type.DATE)); int updateFrequency = definition.getSuggesterUpdateFrequencyMinutes(); Calendar nextSuggestUpdateTime = (Calendar) suggesterLastUpdatedTime.clone(); nextSuggestUpdateTime.add(Calendar.MINUTE, updateFrequency); if (getCalendar().after(nextSuggestUpdateTime)) { updateSuggestions = (writer != null || isIndexUpdatedAfter(suggesterLastUpdatedTime)); } } else { updateSuggestions = true; } } return updateSuggestions; }
From source file:org.kuali.kra.award.paymentreports.awardreports.reporting.service.ReportTrackingNotificationServiceImpl.java
@Override public List<ReportTrackingNotificationDetails> runReportTrackingNotifications() { List<ReportTrackingNotificationDetails> resultDetails = new ArrayList<ReportTrackingNotificationDetails>(); AwardReportTrackingNotificationRenderer renderer = new AwardReportTrackingNotificationRenderer(); for (ReportTrackingNotification notification : notifications) { ReportTrackingNotificationDetails details = new ReportTrackingNotificationDetails(); details.setActionCode(notification.getActionCode()); details.setNotificationName(notification.getName()); resultDetails.add(details);//from ww w. ja v a 2 s.c o m try { NotificationType notificationType = notificationService.getNotificationType("1", notification.getActionCode()); if (notificationType != null && notificationType.isActive() && notificationType.getNotificationTypeRecipients() != null && !notificationType.getNotificationTypeRecipients().isEmpty()) { details.setNotificationActive(true); details.setNotificationRecipients(notificationType.getNotificationTypeRecipients().size()); int recordsFound = 0; int recordsMatched = 0; int notificationsSent = 0; // either add or subtract, based on the overdue flag the number of days specified in the notification from today Calendar checkFor = Calendar.getInstance(); Calendar until = null; if (notification.isOverdue()) { checkFor.add(Calendar.DAY_OF_MONTH, (notification.getDays() + notification.getScope()) * -1); } else { checkFor.add(Calendar.DAY_OF_MONTH, notification.getDays() - notification.getScope()); } until = (Calendar) checkFor.clone(); until.add(Calendar.DAY_OF_MONTH, notification.getScope()); clearTimeFields(checkFor); clearTimeFields(until); Map<Award, List<ReportTracking>> matchedReports = new HashMap<Award, List<ReportTracking>>(); Map<NotificationRecipient.Builder, List<ReportTracking>> recipients = new TreeMap<NotificationRecipient.Builder, List<ReportTracking>>( new Comparator<NotificationRecipient.Builder>() { public int compare(NotificationRecipient.Builder o1, NotificationRecipient.Builder o2) { return o1.getRecipientId().compareTo(o2.getRecipientId()); } }); for (ReportTrackingNotificationTask task : notification.getTasks()) { List<ReportTracking> reports = (List<ReportTracking>) businessObjectService .findMatching(ReportTracking.class, task.getReportTrackingValueMap()); recordsFound += reports.size(); for (ReportTracking report : reports) { //if the report's due date is between the checked for date and the scoped date, and a notification //hasn't previously been sent for it, add it to the matched reports. if (report.getDueDate() != null && doDatesMatch(report.getDueDate(), checkFor, until) && !hasSentNotification(report, notification)) { recordsMatched++; Award curAward = awardService.getActiveOrNewestAward(report.getAwardNumber()); report.setAward(curAward); List<ReportTracking> curReports = matchedReports.get(curAward); if (curReports == null) { curReports = new ArrayList<ReportTracking>(); matchedReports.put(curAward, curReports); } curReports.add(report); } } //rehash the reports per recipient found in the notification for (Award award : matchedReports.keySet()) { Set<NotificationRecipient.Builder> recips = notificationService .getNotificationRecipients(new AwardNotificationContext(award, notification.getActionCode(), notification.getName())); for (NotificationRecipient.Builder recip : recips) { List<ReportTracking> curReports = recipients.get(recip); if (curReports == null) { curReports = new ArrayList<ReportTracking>(); recipients.put(recip, curReports); } curReports.addAll(matchedReports.get(award)); } } for (Map.Entry<NotificationRecipient.Builder, List<ReportTracking>> entry : recipients .entrySet()) { renderer.setReports(entry.getValue()); String message = renderer.render(notificationType.getMessage()); notificationService.sendNotification(notification.getName(), notificationType.getSubject(), message, Collections.singleton(entry.getKey())); notificationsSent++; } //for each matched report, create a sent report record to make sure we don't attempt //to send this notification for this report again. List<SentReportNotification> sentReports = new ArrayList<SentReportNotification>(); for (Map.Entry<Award, List<ReportTracking>> entry : matchedReports.entrySet()) { for (ReportTracking report : entry.getValue()) { sentReports.add(new SentReportNotification(notification.getActionCode(), report)); } } businessObjectService.save(sentReports); } details.setTrackingRecordsFound(recordsFound); details.setTrackingRecordsMatched(recordsMatched); details.setNotificationsSent(notificationsSent); } } catch (Exception e) { LOG.error("Error sending report tracking notifications for " + notification.getActionCode(), e); details.setErrorMessage(e.getMessage()); } } return resultDetails; }