List of usage examples for org.joda.time Seconds secondsBetween
public static Seconds secondsBetween(ReadablePartial start, ReadablePartial end)
Seconds
representing the number of whole seconds between the two specified partial datetimes. From source file:com.jeet.cli.Admin.java
private static void checkIntegrity(Map fileMap) { System.out.print("Enter File Index(0 to cancel): "); String choise = null;/*from ww w. j a v a 2 s. c o m*/ try { choise = bufferRead.readLine(); } catch (IOException ioe) { System.err.println("Error in reading option."); System.err.println("Please try again."); checkIntegrity(fileMap); } if (choise != null && NumberUtils.isDigits(choise)) { Integer choiseInt = Integer.parseInt(choise); if (fileMap.containsKey(choiseInt)) { try { String key = fileMap.get(choiseInt).toString(); File file = FileUtil.downloadAndDecryptFile(key); Long fileLength = file.length(); if (FileUtil.getHash(key.split("/")[1]).equals(HashUtil.generateFileHash(file))) { Map userMetadata = S3Connect.getUserMetadata(key); // System.out.println(userMetadata.get(Constants.LAST_MODIFIED_KEY)); // System.out.println(S3Connect.getLastModified(key).getTime()); //check last access time if (userMetadata.containsKey(Constants.LAST_MODIFIED_KEY)) { Long millisFromMettaData = Long .valueOf(userMetadata.get(Constants.LAST_MODIFIED_KEY).toString()); Long millisFromS3 = S3Connect.getLastModified(key).getTime(); Seconds difference = Seconds.secondsBetween(new DateTime(millisFromMettaData), new DateTime(millisFromS3)); if (difference.getSeconds() < Constants.LAST_MODIFIED_VARIANT) { //check file length if (userMetadata.containsKey(Constants.FILE_LENGTH_KEY) && fileLength.toString() .equals(userMetadata.get(Constants.FILE_LENGTH_KEY))) { //check hash from user data if (userMetadata.containsKey(Constants.HASH_KEY) && userMetadata .get(Constants.HASH_KEY).equals(FileUtil.getHash(key.split("/")[1]))) { System.out.println(ANSI_GREEN + "Data integrity is preserved."); } else { System.out.println(ANSI_RED + "Data integrity is not preserved."); } } else { System.out.println(ANSI_RED + "File is length does not matched."); } } else { System.out.println(ANSI_RED + "File is modified outside the system."); } } else { System.out.println(ANSI_RED + "File is modified outside the system."); } } else { System.out.println(ANSI_RED + "Data integrity is not preserved."); } } catch (Exception ex) { ex.printStackTrace(); System.err.println("Error in downlaoding file."); } askFileListInputs(fileMap); } else if (choiseInt.equals(0)) { System.out.println("Check Integrity file canceled."); askFileListInputs(fileMap); } else { System.err.println("Please select from provided options only."); checkIntegrity(fileMap); } } else { System.err.println("Please enter digits only."); checkIntegrity(fileMap); } }
From source file:com.jslsolucoes.tagria.lib.servlet.Tagria.java
License:Apache License
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String uri = request.getRequestURI().replaceAll(";jsessionid=.*", ""); String etag = DigestUtils.sha256Hex(uri); if (uri.endsWith("blank")) { response.setStatus(HttpServletResponse.SC_OK); return;// w w w.ja va2 s .com } if (uri.endsWith("locale")) { Config.set(request.getSession(), Config.FMT_LOCALE, Locale.forLanguageTag(request.getParameter("locale"))); response.setStatus(HttpServletResponse.SC_OK); return; } if (request.getHeader("If-None-Match") != null && etag.equals(request.getHeader("If-None-Match"))) { response.setStatus(HttpServletResponse.SC_NOT_MODIFIED); return; } String charset = "utf-8"; if (TagUtil.getInitParam(TagriaConfigParameter.ENCODING) != null) { charset = TagUtil.getInitParam(TagriaConfigParameter.ENCODING); } response.setCharacterEncoding(charset); try { DateTime today = new DateTime(); DateTime expires = new DateTime().plusDays(CACHE_EXPIRES_DAY); if (uri.endsWith(".css")) { response.setContentType("text/css"); } else if (uri.endsWith(".js")) { response.setContentType("text/javascript"); } else if (uri.endsWith(".png")) { response.setContentType("image/png"); } SimpleDateFormat sdf = new SimpleDateFormat("E, dd MMM yyyy HH:mm:ss 'GMT'", Locale.ENGLISH); if (Boolean.valueOf(TagUtil.getInitParam(TagriaConfigParameter.CDN_ENABLED))) { response.setHeader(HttpHeaderParameter.ACCESS_CONTROL_ALLOW_ORIGIN.getName(), "*"); } response.setHeader(HttpHeaderParameter.ETAG.getName(), etag); response.setHeader(HttpHeaderParameter.EXPIRES.getName(), sdf.format(expires.toDate())); response.setHeader(HttpHeaderParameter.CACHE_CONTROL.getName(), "public,max-age=" + Seconds.secondsBetween(today, expires).getSeconds()); String url = "/com/jslsolucoes" + uri.replaceFirst(request.getContextPath(), "").replaceAll(";jsessionid=.*", ""); InputStream in = getClass().getResourceAsStream(url); IOUtils.copy(in, response.getOutputStream()); in.close(); } catch (Exception exception) { logger.error("Could not load resource", exception); response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); } }
From source file:com.keepassdroid.utils.DateUtil.java
License:Open Source License
public static long convertDateToKDBX4Time(DateTime dt) { try {//from ww w . ja v a2 s . c o m Seconds secs = Seconds.secondsBetween(javaEpoch, dt); return secs.getSeconds() + epochOffset; } catch (ArithmeticException e) { // secondsBetween overflowed an int Date javaDt = dt.toDate(); long seconds = javaDt.getTime() / 1000L; return seconds + epochOffset; } }
From source file:com.linagora.scheduling.ScheduledTask.java
License:Open Source License
@Override public long getDelay(TimeUnit unit) { return unit.convert(Seconds.secondsBetween(scheduler.now(), scheduledTime).getSeconds(), TimeUnit.SECONDS); }
From source file:com.pacoapp.paco.ui.ExperimentExecutor.java
License:Open Source License
private void addTiming(Event event) { if (formOpenTime != null) { DateTime formFinishTime = DateTime.now(); Seconds duration = Seconds.secondsBetween(formOpenTime, formFinishTime); Output durationResponse = new Output(); durationResponse.setAnswer(Integer.toString(duration.getSeconds())); durationResponse.setName(FORM_DURATION_IN_SECONDS); event.addResponse(durationResponse); }/* w ww. j av a 2s .co m*/ }
From source file:com.qcadoo.mes.cmmsMachineParts.listeners.PlannedEventRealizationDetailsListeners.java
License:Open Source License
public void calculateDuration(final ViewDefinitionState view, final ComponentState state, final String[] args) { FieldComponent startDateFieldComponent = (FieldComponent) view .getComponentByReference(PlannedEventRealizationFields.START_DATE); FieldComponent finishDateFieldComponent = (FieldComponent) view .getComponentByReference(PlannedEventRealizationFields.FINISH_DATE); FieldComponent durationFieldComponent = (FieldComponent) view .getComponentByReference(PlannedEventRealizationFields.DURATION); if ((startDateFieldComponent.getFieldValue() == null || startDateFieldComponent.getFieldValue().toString().isEmpty()) || (finishDateFieldComponent.getFieldValue() == null || finishDateFieldComponent.getFieldValue().toString().isEmpty())) { return;/*from www .ja v a 2 s . c o m*/ } Date start = DateUtils.parseDate(startDateFieldComponent.getFieldValue()); Date end = DateUtils.parseDate(finishDateFieldComponent.getFieldValue()); if (start != null && end != null && start.before(end)) { Seconds seconds = Seconds.secondsBetween(new DateTime(start), new DateTime(end)); durationFieldComponent.setFieldValue(Integer.valueOf(seconds.getSeconds())); } durationFieldComponent.requestComponentUpdateState(); }
From source file:com.qcadoo.mes.cmmsMachineParts.listeners.StaffWorkTimeDetailsListenersCMMS.java
License:Open Source License
public void calculateLaborTime(final ViewDefinitionState view, final ComponentState state, final String[] args) { FieldComponent startDateFieldComponent = (FieldComponent) view .getComponentByReference(StaffWorkTimeFields.EFFECTIVE_EXECUTION_TIME_START); FieldComponent endDateFieldComponent = (FieldComponent) view .getComponentByReference(StaffWorkTimeFields.EFFECTIVE_EXECUTION_TIME_END); FieldComponent laborTimeFieldComponent = (FieldComponent) view .getComponentByReference(StaffWorkTimeFields.LABOR_TIME); if (startDateFieldComponent.getFieldValue() == null || endDateFieldComponent.getFieldValue() == null) { return;/*w w w . j av a 2 s .c o m*/ } Date start = DateUtils.parseDate(startDateFieldComponent.getFieldValue()); Date end = DateUtils.parseDate(endDateFieldComponent.getFieldValue()); if (start != null && end != null && start.before(end)) { Seconds seconds = Seconds.secondsBetween(new DateTime(start), new DateTime(end)); laborTimeFieldComponent.setFieldValue(Integer.valueOf(seconds.getSeconds())); } laborTimeFieldComponent.requestComponentUpdateState(); }
From source file:com.qcadoo.mes.cmmsMachineParts.states.MaintenanceEventStateValidationService.java
License:Open Source License
private Optional<Integer> getProgressTime(Entity event) { StringBuilder hqlForStart = new StringBuilder(); hqlForStart/*from ww w.j a va 2 s . com*/ .append("select max(dateAndTime) as date from #cmmsMachineParts_maintenanceEventStateChange sc "); hqlForStart.append("where sc.maintenanceEvent = :eventId and sc.status = '03successful' "); hqlForStart.append("and sc.targetState = '02inProgress'"); SearchQueryBuilder query = dataDefinitionService .get(CmmsMachinePartsConstants.PLUGIN_IDENTIFIER, CmmsMachinePartsConstants.MODEL_MAINTENANCE_EVENT_STATE_CHANGE) .find(hqlForStart.toString()); query.setLong("eventId", event.getId()); Date start = query.setMaxResults(1).uniqueResult().getDateField("date"); StringBuilder hqlForEnd = new StringBuilder(); hqlForEnd.append("select max(dateAndTime) as date from #cmmsMachineParts_maintenanceEventStateChange sc "); hqlForEnd.append("where sc.maintenanceEvent = :eventId and sc.status = '03successful' "); hqlForEnd.append("and sc.targetState = '03edited'"); query = dataDefinitionService.get(CmmsMachinePartsConstants.PLUGIN_IDENTIFIER, CmmsMachinePartsConstants.MODEL_MAINTENANCE_EVENT_STATE_CHANGE).find(hqlForEnd.toString()); query.setLong("eventId", event.getId()); Date end = query.setMaxResults(1).uniqueResult().getDateField("date"); if (start != null && end != null && start.before(end)) { Seconds seconds = Seconds.secondsBetween(new DateTime(start), new DateTime(end)); return Optional.of(Integer.valueOf(seconds.getSeconds())); } return Optional.empty(); }
From source file:com.qcadoo.mes.orders.OrderStateChangeReasonService.java
License:Open Source License
public long getEffectiveDateFromDifference(final Entity parameter, final Entity order) { if (!neededWhenChangingEffectiveDateFrom(parameter)) { return 0L; }// w ww . j av a 2 s . c o m final long dateFromTimestamp = getTimestampFromOrder(order, DATE_FROM, CORRECTED_DATE_FROM); if (dateFromTimestamp == 0L) { return 0L; } final DateTime dateFrom = new DateTime(dateFromTimestamp); if (getEffectiveDate(order, EFFECTIVE_DATE_FROM) == null) { return 0L; } final DateTime effectiveDateFrom = new DateTime(getEffectiveDate(order, EFFECTIVE_DATE_FROM)); final DateTime maxTime = new DateTime( dateFromTimestamp + getAllowedDelayFromParametersAsMiliseconds(DELAYED_EFFECTIVE_DATE_FROM_TIME)); final DateTime minTime = new DateTime( dateFromTimestamp - getAllowedDelayFromParametersAsMiliseconds(EARLIER_EFFECTIVE_DATE_FROM_TIME)); long difference = 0L; if ((effectiveDateFrom.isAfter(maxTime) && needForDelayedDateFrom(parameter)) || (effectiveDateFrom.isBefore(minTime) && needForEarlierDateFrom(parameter))) { difference = Seconds.secondsBetween(dateFrom, effectiveDateFrom).getSeconds(); } return difference; }
From source file:com.qcadoo.mes.orders.OrderStateChangeReasonService.java
License:Open Source License
public long getEffectiveDateToDifference(final Entity parameter, final Entity order) { if (!neededWhenChangingEffectiveDateTo(parameter)) { return 0L; }/*w w w . j av a 2s .com*/ final long dateToTimestamp = getTimestampFromOrder(order, DATE_TO, CORRECTED_DATE_TO); if (dateToTimestamp == 0L) { return 0L; } final DateTime dateTo = new DateTime(dateToTimestamp); if (getEffectiveDate(order, EFFECTIVE_DATE_TO) == null) { return 0L; } final DateTime effectiveDateTo = new DateTime(getEffectiveDate(order, EFFECTIVE_DATE_TO)); final DateTime maxTime = new DateTime( dateToTimestamp + getAllowedDelayFromParametersAsMiliseconds(DELAYED_EFFECTIVE_DATE_TO_TIME)); final DateTime minTime = new DateTime( dateToTimestamp - getAllowedDelayFromParametersAsMiliseconds(EARLIER_EFFECTIVE_DATE_TO_TIME)); long difference = 0L; if ((effectiveDateTo.isAfter(maxTime) && needForDelayedDateTo(parameter)) || (effectiveDateTo.isBefore(minTime) && needForEarlierDateTo(parameter))) { difference = Seconds.secondsBetween(dateTo, effectiveDateTo).getSeconds(); } return difference; }