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.axelor.controller.ConnectionToPrestashop.java
License:Open Source License
@SuppressWarnings("finally") @Transactional/* w w w.j a va 2s . c o m*/ public String syncAddress() { String message = ""; try { List<Integer> prestashopIdList = new ArrayList<Integer>(); List<Integer> erpIdList = new ArrayList<Integer>(); List<Address> erpList = Address.all().fetch(); for (Address prestahopAddress : erpList) { erpIdList.add(prestahopAddress.getPrestashopid()); } URL url = new URL("http://localhost/client-lib/crud/action.php?resource=addresses&action=getallid&Akey=" + apiKey); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod("GET"); connection.connect(); InputStream inputStream = connection.getInputStream(); Scanner scan = new Scanner(inputStream); while (scan.hasNext()) { String data = scan.nextLine(); System.out.println(data); prestashopIdList.add(Integer.parseInt(data)); } System.out.println("From Prestashop Addresses :: " + prestashopIdList.size()); System.out.println("From ERP Addresses :: " + erpIdList.size()); scan.close(); // Check new entries in the prestashop Iterator<Integer> prestaListIterator = prestashopIdList.iterator(); while (prestaListIterator.hasNext()) { Integer tempId = prestaListIterator.next(); System.out.println("Current AddressPrestashopId for operation ::" + tempId); if (erpIdList.contains(tempId)) { com.axelor.pojo.Address tempAddress = getAddress(tempId); String dateUpdate = tempAddress.getDate_upd(); LocalDateTime dt1 = LocalDateTime.parse(dateUpdate, DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss")); Address pAddress = Address.all().filter("prestashopid=?", tempId).fetchOne(); LocalDateTime dt2 = pAddress.getUpdatedOn(); if (dt2 != null) { int diff = Seconds.secondsBetween(dt2, dt1).getSeconds(); if (diff > 1) updateAddress(tempAddress, tempId); } else { updateAddress(tempAddress, tempId); } erpIdList.remove(tempId); } else { System.out.println("Current AddressPrestashopId for insertion operation ::" + tempId); // insert new data in ERP Database insertAddress(tempId); erpIdList.remove(tempId); } } if (erpIdList.isEmpty()) { System.out.println("Synchronization is completed."); message = "done"; } else { // delete from ERP Iterator<Integer> erpListIterator = erpIdList.iterator(); while (erpListIterator.hasNext()) { Integer tempId = erpListIterator.next(); if (tempId != 0) { Address addressDelete = Address.all().filter("prestashopid=?", tempId).fetchOne(); String fullName = addressDelete.getFullName(); // addressDelete.remove(); addressDelete.setArchived(Boolean.TRUE); System.out.println("Address deleted ::" + fullName); } } while (prestaListIterator.hasNext()) { Integer tempId = prestaListIterator.next(); System.out.println("Currently in prestashop ::" + tempId); } System.out.println("Synchronization is completed."); message = "done"; } } catch (Exception e) { message = "Wrong Authentication Key or Key has been disabled."; } finally { return message; } }
From source file:com.bazaarvoice.dropwizard.caching.HttpHeaderUtils.java
License:Apache License
/** * Convert the difference between two times to seconds to use as the value for the "Age" HTTP header (end - start) * or null if end < start.// w ww. j a v a2 s . com */ public static String toAge(DateTime start, DateTime end) { checkNotNull(start); checkNotNull(end); int value = Seconds.secondsBetween(start, end).getSeconds(); return value < 0 ? null : Integer.toString(value); }
From source file:com.bazaarvoice.dropwizard.caching.ResponseCache.java
License:Apache License
/** * Test if this request allows a specific cached response to be returned. * * @param request the request context/*from w w w . j a v a 2 s . co m*/ * @param now instant that represents the current time * @param response response to check * @return true if the cached response can be returned, false if the request must be re-validated with the origin * server */ private static boolean isCacheAcceptable(CacheRequestContext request, DateTime now, CachedResponse response) { // NOTE: Do not check that the expiration time is before NOW here. That is verified later against the max-stale // cache-control option. DateTime responseDate = response.getDate(); DateTime responseExpires = response.getExpires().get(); if (responseExpires.isBefore(responseDate)) { return false; } RequestCacheControl requestCacheControl = request.getCacheControl(); if (requestCacheControl.getMaxAge() > 0) { int age = Seconds.secondsBetween(responseDate, now).getSeconds(); if (age > requestCacheControl.getMaxAge()) { return false; } } if (requestCacheControl.getMinFresh() >= 0 || requestCacheControl.getMaxStale() >= 0) { int freshness = Seconds.secondsBetween(now, responseExpires).getSeconds(); if (requestCacheControl.getMinFresh() >= 0 && freshness < requestCacheControl.getMinFresh()) { return false; } if (requestCacheControl.getMaxStale() >= 0) { CacheControl responseCacheControl = response.getCacheControl().orNull(); boolean responseMustRevalidate = responseCacheControl != null && (responseCacheControl.isProxyRevalidate() || responseCacheControl.isMustRevalidate()); if (!responseMustRevalidate) { return freshness >= -requestCacheControl.getMaxStale(); } } } return !responseExpires.isBefore(now); }
From source file:com.bitplan.rest.RestServerImpl.java
License:Apache License
/** * stop this server//from www . j av a2 s .c o m * * @see com.bitplan.rest.RestServer#stop() */ @Override public void stop() { if (httpServer != null) { httpServer.shutdown(); httpServer = null; running = false; stopTime = DateTime.now(); Seconds secs = Seconds.secondsBetween(startTime, stopTime); System.out.println("finished after " + secs.getSeconds() + " secs"); // if someone is waiting for us let him continue .. informStarter(); } }
From source file:com.cisco.devnetlabs.choochoo.impl.ChoochooMqttPlugin.java
License:Open Source License
private void handleMqttMessage(String topic, String message) { //LOG.info("handleMqttMessage: topic: {}, message: {}", topic, message); JSONObject jSensor = null;/*from w w w . jav a 2s. co m*/ try { jSensor = new JSONObject(message); } catch (JSONException e) { LOG.error("{}", e.toString()); return; } String sensorBlockId = jSensor.optString("block", null); if (sensorBlockId == null) { LOG.error("processSensor: missing block in Json String: {}", jSensor.toString()); return; } String blockPosition = jSensor.optString("pos", null); if (blockPosition == null) { LOG.error("processSensor: missing pos in Json String: {}", jSensor.toString()); return; } else if (blockPosition.contentEquals("0")) { savePosId = 0; return; } DateTime currTime = new DateTime(DateTimeZone.UTC); long diff = Seconds.secondsBetween(saveTime, currTime).getSeconds() % 60; if (diff < 2) return; // only sample sensor values at most every 2 seconds saveTime = currTime; // if nothing has changed, return as we have alredy handled entering this state if (saveBlockId == Integer.valueOf(sensorBlockId) && savePosId == Integer.valueOf(blockPosition)) { return; } saveBlockId = Integer.valueOf(sensorBlockId); savePosId = Integer.valueOf(blockPosition); Integer sensorId = (Integer.valueOf(sensorBlockId) - 1) * 3 + Integer.valueOf(blockPosition); onem2mManager.processSensor(topic, sensorId); }
From source file:com.cisco.dvbu.ps.utils.date.DateDiffDate.java
License:Open Source License
/** * Called to invoke the stored procedure. Will only be called a * single time per instance. Can throw CustomProcedureException or * SQLException if there is an error during invoke. *///w w w .jav a 2s .c o m public void invoke(Object[] inputValues) throws CustomProcedureException, SQLException { java.util.Date startDate = null; java.util.Date endDate = null; Calendar startCal = null; Calendar endCal = null; DateTime startDateTime = null; DateTime endDateTime = null; String datePart = null; long dateLength = 0; try { result = null; if (inputValues[0] == null) { result = new Long(dateLength); return; } if (inputValues[1] == null) { result = new Long(dateLength); return; } if (inputValues[2] == null) { result = new Long(dateLength); return; } datePart = (String) inputValues[0]; startDate = (java.util.Date) inputValues[1]; startCal = Calendar.getInstance(); startCal.setTime(startDate); endDate = (java.util.Date) inputValues[2]; endCal = Calendar.getInstance(); endCal.setTime(endDate); startDateTime = new DateTime(startCal.get(Calendar.YEAR), startCal.get(Calendar.MONTH) + 1, startCal.get(Calendar.DAY_OF_MONTH), 0, 0, 0, 0); endDateTime = new DateTime(endCal.get(Calendar.YEAR), endCal.get(Calendar.MONTH) + 1, endCal.get(Calendar.DAY_OF_MONTH), 0, 0, 0, 0); if (datePart.equalsIgnoreCase("second")) { Seconds seconds = Seconds.secondsBetween(startDateTime, endDateTime); dateLength = seconds.getSeconds(); } if (datePart.equalsIgnoreCase("minute")) { Minutes minutes = Minutes.minutesBetween(startDateTime, endDateTime); dateLength = minutes.getMinutes(); } if (datePart.equalsIgnoreCase("hour")) { Hours hours = Hours.hoursBetween(startDateTime, endDateTime); dateLength = hours.getHours(); } if (datePart.equalsIgnoreCase("day")) { Days days = Days.daysBetween(startDateTime, endDateTime); dateLength = days.getDays(); } if (datePart.equalsIgnoreCase("week")) { Weeks weeks = Weeks.weeksBetween(startDateTime, endDateTime); dateLength = weeks.getWeeks(); } if (datePart.equalsIgnoreCase("month")) { Months months = Months.monthsBetween(startDateTime, endDateTime); dateLength = months.getMonths(); } if (datePart.equalsIgnoreCase("year")) { Years years = Years.yearsBetween(startDateTime, endDateTime); dateLength = years.getYears(); } result = new Long(dateLength); } catch (Throwable t) { throw new CustomProcedureException(t); } }
From source file:com.cubeia.games.poker.adapter.FirebaseServerAdapter.java
License:Open Source License
private int secondsToNextLevel(com.cubeia.poker.model.BlindsLevel level) { int secondsToNextLevel = Seconds .secondsBetween(dateFetcher.date(), new DateTime(level.getNextLevelStartTime())).getSeconds(); log.debug("Now: " + dateFetcher.date() + " Next level starts on: " + new DateTime(level.getNextLevelStartTime()) + " Seconds to next level: " + secondsToNextLevel); return secondsToNextLevel; }
From source file:com.haarman.pebblenotifier.notifications.MyNotificationListenerService.java
License:Apache License
private boolean shouldIgnoreNotification(@NotNull final Notification notification) { Notification lastNotification = mOrmManager.getLastNotification(); if (lastNotification == null) { return false; }/*from ww w . j a v a2s .c o m*/ boolean result = false; if (notification.getTitle().equals(lastNotification.getTitle())) { if (notification.getText().equals(lastNotification.getText())) { if (Seconds.secondsBetween(lastNotification.getCreated(), notification.getCreated()) .getSeconds() < 60) { result = true; } } } return result; }
From source file:com.hp.autonomy.hod.redis.RedisTokenRepository.java
License:MIT License
private int getExpirySeconds(final DateTime dateTime) { return Seconds.secondsBetween(DateTime.now(), dateTime).getSeconds(); }
From source file:com.inkubator.common.util.DateTimeUtil.java
/** * get total Second difference, between two date type * * @return Integer/*w w w.ja v a2 s.c o m*/ * @param date1 Date reference * @param date2 Date reference */ public static Integer getTotalSecondsDifference(Date date1, Date date2) { return Seconds.secondsBetween(new DateTime(date1), new DateTime(date2)).getSeconds(); }