List of usage examples for java.util Calendar after
public boolean after(Object when)
Calendar
represents a time after the time represented by the specified Object
. From source file:biz.varkon.shelvesom.provider.boardgames.BoardGamesUpdater.java
private boolean boardgameCoverUpdated(BoardGamesStore.BoardGame boardgame, ImageUtilities.ExpiringBitmap expiring) { expiring.lastModified = null;/*from w w w . j a va 2 s . c o m*/ final String tinyThumbnail = Preferences.getImageURLForUpdater(boardgame); if (tinyThumbnail != null && !tinyThumbnail.equals("")) { HttpGet get = null; try { get = new HttpGet(Preferences.getImageURLForUpdater(boardgame)); } catch (NullPointerException npe) { android.util.Log.e(LOG_TAG, "Could not check modification image for " + boardgame, npe); } HttpEntity entity = null; try { final HttpResponse response = HttpManager.execute(get); if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { entity = response.getEntity(); final Header header = response.getFirstHeader("Last-Modified"); if (header != null) { final Calendar calendar = Calendar.getInstance(); try { calendar.setTime(mLastModifiedFormat.parse(header.getValue())); expiring.lastModified = calendar; return calendar.after(boardgame.getLastModified()); } catch (ParseException e) { return false; } } } } catch (IOException e) { android.util.Log.e(LOG_TAG, "Could not check modification date for " + boardgame, e); } catch (IllegalArgumentException iae) { android.util.Log.e(LOG_TAG, "Null get value for " + boardgame, iae); } finally { if (entity != null) { try { entity.consumeContent(); } catch (IOException e) { android.util.Log.e(LOG_TAG, "Could not check modification date for " + boardgame, e); } } } } return false; }
From source file:org.uhp.portlets.news.web.validator.ItemValidator.java
public void validateEndDate(final ItemForm itemForm, final Errors errors) { Calendar endD = null;// w w w . ja v a 2 s. com if (itemForm.getItem().getEndDate() != null) { endD = Calendar.getInstance(); endD.setTime(itemForm.getItem().getEndDate()); final Calendar today = Calendar.getInstance(); today.set(Calendar.HOUR_OF_DAY, 0); today.set(Calendar.MINUTE, 0); today.set(Calendar.SECOND, 0); today.set(Calendar.MILLISECOND, 0); if (today.after(endD)) { errors.rejectValue("item.endDate", "ITEM_END_DATE_NOT_BEFORE_TODAY", "End date should not before today"); } } if ((itemForm.getItem().getStartDate() != null) && (endD != null)) { Calendar startD = Calendar.getInstance(); startD.setTime(itemForm.getItem().getStartDate()); if (startD.after(endD)) { errors.rejectValue("item.endDate", "ITEM_END_DATE_NOT_BEFORE_START_DAY", "End date should be after start day"); } } }
From source file:org.jahia.modules.iview.rules.IViewImageService.java
private void cropScale(AddedNodeFact imageNode, String nodeName, int width, int height, JCRSessionWrapper session, KnowledgeHelper drools) throws Exception { long timer = System.currentTimeMillis(); if (imageNode.getNode().hasNode(nodeName)) { JCRNodeWrapper node = imageNode.getNode().getNode(nodeName); Calendar thumbDate = node.getProperty("jcr:lastModified").getDate(); Calendar contentDate = imageNode.getNode().getNode("jcr:content").getProperty("jcr:lastModified") .getDate();/*from w w w .j a v a 2s .c om*/ if (contentDate.after(thumbDate)) { AddedNodeFact thumbNode = new AddedNodeFact(node); File f = crop(imageNode, 0, 0, width, height, drools); if (f == null) { return; } drools.insert(new ChangedPropertyFact(thumbNode, Constants.JCR_DATA, f, drools)); drools.insert(new ChangedPropertyFact(thumbNode, Constants.JCR_LASTMODIFIED, new GregorianCalendar(), drools)); } } else { File f = crop(imageNode, 0, 0, width, height, drools); if (f == null) { return; } AddedNodeFact thumbNode = new AddedNodeFact(imageNode, nodeName, "jnt:resource", drools); if (thumbNode.getNode() != null) { drools.insert(thumbNode); drools.insert(new ChangedPropertyFact(thumbNode, Constants.JCR_DATA, f, drools)); drools.insert(new ChangedPropertyFact(thumbNode, Constants.JCR_MIMETYPE, imageNode.getMimeType(), drools)); drools.insert(new ChangedPropertyFact(thumbNode, Constants.JCR_LASTMODIFIED, new GregorianCalendar(), drools)); } } if (logger.isDebugEnabled()) { logger.debug("crop for node {} created in {} ms", new Object[] { imageNode.getNode().getPath(), System.currentTimeMillis() - timer }); } }
From source file:net.solarnetwork.node.backup.test.FileSystemBackupServiceTest.java
@Test public void backupOne() throws IOException, InterruptedException { final ClassPathResource testResource = new ClassPathResource("test-context.xml", AbstractNodeTransactionalTest.class); final BackupService bs = service; final List<BackupResource> resources = new ArrayList<BackupResource>(1); final Calendar now = new GregorianCalendar(); now.set(Calendar.MILLISECOND, 0); resources.add(new ResourceBackupResource(testResource, "test.xml")); Backup result = bs.performBackup(resources); assertNotNull(result);//ww w.j a v a2s . c om assertNotNull(result.getDate()); assertTrue(!now.after(result.getDate())); assertNotNull(result.getKey()); assertTrue(result.isComplete()); // now let's verify we can get that file back out of the backup Collection<Backup> backups = bs.getAvailableBackups(); assertNotNull(backups); assertEquals(1, backups.size()); Backup b = backups.iterator().next(); assertEquals(result.getKey(), b.getKey()); assertEquals(result.getDate().getTime(), b.getDate().getTime()); int count = 0; final BackupResourceIterable backupResources = bs.getBackupResources(b); try { for (BackupResource r : backupResources) { count++; assertEquals("test.xml", r.getBackupPath()); Assert.assertArrayEquals(FileCopyUtils.copyToByteArray(testResource.getInputStream()), FileCopyUtils.copyToByteArray(r.getInputStream())); } } finally { backupResources.close(); } assertEquals("Should only have one backup resource", 1, count); }
From source file:jobs.WarningMonitorJob.java
/** * Check alert table to see if there is an active Warning of the given Alert type and that they are not older then the stale hours limit. * Active warnings are considered stale if they are older then the configured Stale hours options which defaults to 12. * @param aType//ww w.j ava 2s. c o m * @return true if no active warnings or the active warning is over ignore limit time. */ public boolean isAlertTypeActive(AlertType aType, Options options) { List<Warning> resp = Warning.getActive(aType); if (resp.size() > 0) { //See if warning has gone stale. Warning mostRecent = resp.get(0); Calendar now = Calendar.getInstance(); now.add(Calendar.HOUR, -1 * options.snoozeActiveWarnings_hours); Calendar lastDate = Calendar.getInstance(); lastDate.setTime(mostRecent.dateTime); if (now.after(lastDate)) return true; } return false; }
From source file:org.huahinframework.emanager.amazonaws.elasticmapreduce.ElasticMapReduceManager.java
/** * @return If true, returns time afeter//from ww w . j a va2s . c o m */ public boolean isTimeAfter() { if (checkDate == null) { return false; } Calendar check = Calendar.getInstance(); Calendar now = Calendar.getInstance(); check.setTime(checkDate); check.set(Calendar.MINUTE, check.get(Calendar.MINUTE) + CHARGE_MINUTES); if (now.after(check)) { checkDate = check.getTime(); return false; } check.setTime(checkDate); check.set(Calendar.MINUTE, check.get(Calendar.MINUTE) + TIME_LIMIT_MINUTES); return now.after(check); }
From source file:is.idega.idegaweb.egov.gumbo.licenses.SetDraganotveidiValidPeriod.java
public void execute(ExecutionContext executionContext) throws Exception { final Interval period; final Calendar now = Calendar.getInstance(); now.set(Calendar.HOUR, 0);/*from www. j a v a 2 s .c om*/ now.set(Calendar.MINUTE, 0); now.set(Calendar.SECOND, 0); now.set(Calendar.MILLISECOND, 0); final Calendar mayStart = Calendar.getInstance(); mayStart.set(now.get(Calendar.YEAR), Calendar.MAY, 1, 0, 0, 0); final Calendar augEnd = Calendar.getInstance(); augEnd.set(now.get(Calendar.YEAR), Calendar.AUGUST, 31, 0, 0, 0); if (now.after(mayStart) && now.before(augEnd)) { period = new Interval(now.getTime(), augEnd.getTime()); } else { period = findNearestPeriod(now); } executionContext.setVariable("date_validityFrom", period.getFrom()); executionContext.setVariable("date_validityTo", period.getTo()); }
From source file:edu.unlv.kilo.web.ChartingController.java
@RequestMapping(method = RequestMethod.POST) public String post(@Valid ChartingForm form, BindingResult result, Model model, HttpServletRequest request) { // Returns the form with errors found from the @ checks if (result.hasErrors()) { return createForm(model, form); }//from ww w . ja v a2s. co m Calendar startDate = form.getStartDate(); // Gets the start date from the user Calendar endDate = form.getEndDate(); // Gets the end date from the user // Have to make sure the begin date is actually before the end date // If not, throw an error if (startDate.after(endDate)) { result.rejectValue("startDate", "start_date_after_end"); return createForm(model, form); //result.rejectValue("startDate", "start_after_end", "The start date must be before the end date."); } int interval = form.getDay_Interval(); // Gets the interval in days from the user // Send the data to projecting and receive the points to plot //List<MoneyValue> data_Points = Projection.getGraphData(startDate, endDate, interval); /*------------TEST CASE------------------------------------------*/ List<MoneyValue> data_Points = new ArrayList<MoneyValue>(); data_Points.clear(); for (long j = 0; j < 10; j++) { MoneyValue abc = new MoneyValue(); abc.setAmount(j); data_Points.add(abc); } /*------------TEST CASE------------------------------------------*/ // This sets up the start date and end date to be able // to be printed in a nice default format. SimpleDateFormat nice_String = new SimpleDateFormat("MM/dd/yyyy"); String begin_Print = null; String end_Print = null; begin_Print = nice_String.format(startDate.getTime()); end_Print = nice_String.format(endDate.getTime()); /*-------------GRAPHING STARTS HERE-------------*/ int number_of_points = data_Points.size(); // Holds the points for graphing. // Library dictates it must be a double double[] points = new double[number_of_points]; // These values are set so they're sure to be changed double min_Value = 1000000; // The minimum Money amount in the list double max_Value = 0; // The maximum Money amount in the list // Put the Money amounts into the array and check for updated // minimum and maximum values. for (int i = 0; i < number_of_points; i++) { points[i] = (double) data_Points.get(i).getAmount(); if (min_Value > points[i]) { min_Value = points[i]; } if (max_Value < points[i]) { max_Value = points[i]; } } //Line charting_Line = Plots.newLine(Data.newData(points), RED, "Item"); Line charting_Line = Plots.newLine(DataUtil.scaleWithinRange(min_Value, max_Value, points), RED, "Item"); charting_Line.setLineStyle(LineStyle.newLineStyle(3, 1, 0)); charting_Line.addShapeMarkers(Shape.CIRCLE, Color.AQUAMARINE, 8); // Defining the chart LineChart chart = GCharts.newLineChart(charting_Line); chart.setSize(550, 450); chart.setTitle("Budgeting Line Chart", MAROON, 14); chart.setGrid(number_of_points, number_of_points, 3, 2); // Defining the axis information and styles AxisStyle axisStyle = AxisStyle.newAxisStyle(BLACK, 12, AxisTextAlignment.CENTER); AxisLabels xAxis = AxisLabelsFactory.newAxisLabels(begin_Print, "Dates", end_Print); xAxis.setAxisStyle(axisStyle); AxisLabels yAxis = AxisLabelsFactory.newNumericAxisLabels(min_Value, max_Value); yAxis.setAxisStyle(axisStyle); // Adding axis information to the chart chart.addXAxisLabels(xAxis); chart.addYAxisLabels(yAxis); // Defining the background color chart.setBackgroundFill(Fills.newSolidFill(LIGHTBLUE)); // The image url to be sent to the jspx String url = chart.toURLString(); // Setting the "url" variable for the jspx model.addAttribute("url", chart.toURLString()); return "charting/graph"; }
From source file:nl.strohalm.cyclos.entities.ads.Ad.java
public Status getStatus() { if (permanent) { return Status.PERMANENT; } else {//from w w w . j av a 2 s.c om final Calendar begin = publicationPeriod == null ? null : publicationPeriod.getBegin(); final Calendar end = publicationPeriod == null ? null : publicationPeriod.getEnd(); final Calendar now = Calendar.getInstance(); if (begin != null && begin.after(now)) { return Status.SCHEDULED; } else if (end != null && end.before(now)) { return Status.EXPIRED; } } return Status.ACTIVE; }
From source file:com.amazonaws.mturk.cmd.GetResults.java
/** * Updates the statistics for the result that are displayed after * all results have been retrieved// w ww . j a va 2s . c o m */ private void updateStatistics(HITResults r) { totalAssignments += r.getHIT().getMaxAssignments(); if (r.getHIT().getCreationTime().before(firstHitCreateTime)) { firstHitCreateTime = r.getHIT().getCreationTime(); } Assignment[] assignments = r.getAssignments(); if (assignments != null) { for (Assignment a : assignments) { AssignmentStatus status = a.getAssignmentStatus(); Calendar acceptTime = a.getAcceptTime(); Calendar submitTime = a.getSubmitTime(); if (status == AssignmentStatus.Submitted || status == AssignmentStatus.Approved || status == AssignmentStatus.Rejected) { totalAssignmentsCompleted++; } if (submitTime != null && submitTime.after(lastAssignmentSubmitTime)) { lastAssignmentSubmitTime = submitTime; } if (acceptTime != null && submitTime != null) { totalWorkTimeMillis += (submitTime.getTimeInMillis() - acceptTime.getTimeInMillis()); } } } }