List of usage examples for org.joda.time Minutes minutesBetween
public static Minutes minutesBetween(ReadablePartial start, ReadablePartial end)
Minutes
representing the number of whole minutes between the two specified partial datetimes. From source file:com.xumpy.timesheets.services.TickedJobsDetailSrv.java
public static TickedJobsDetail calculate(List<? extends TickedJobs> tickedJobs) { TickedJobsDetail tickedJobsDetail = new TickedJobsDetail(); tickedJobsDetail.setTickedJobs(tickedJobs); if (tickedJobs.size() > 0) { tickedJobs = sortTickedJobs(tickedJobs); Date startCounterWork = null; Date startCounterPause = null; BigDecimal workedMinutes = new BigDecimal(0); BigDecimal pausedMinutes = new BigDecimal(0); for (int i = 0; i < tickedJobs.size(); i++) { if (i % 2 == 0) { if (!tickedJobs.get(i).isStarted()) { tickedJobsDetail.setActualPause(new BigDecimal(-1)); tickedJobsDetail.setActualWorked(new BigDecimal(-1)); break; } else { if (startCounterPause != null) { Minutes minutes = Minutes.minutesBetween(new DateTime(startCounterPause), new DateTime(tickedJobs.get(i).getTicked())); pausedMinutes = pausedMinutes.add(new BigDecimal(minutes.getMinutes())); }// w ww . ja va 2s . com startCounterWork = tickedJobs.get(i).getTicked(); } } else { if (tickedJobs.get(i).isStarted()) { tickedJobsDetail.setActualPause(new BigDecimal(-1)); tickedJobsDetail.setActualWorked(new BigDecimal(-1)); break; } else { Minutes minutes = Minutes.minutesBetween(new DateTime(startCounterWork), new DateTime(tickedJobs.get(i).getTicked())); workedMinutes = workedMinutes.add(new BigDecimal(minutes.getMinutes())); startCounterPause = tickedJobs.get(i).getTicked(); } } tickedJobsDetail.setActualPause(pausedMinutes); tickedJobsDetail.setActualWorked(workedMinutes); } } else { tickedJobsDetail.setTickedJobs(tickedJobs); tickedJobsDetail.setActualWorked(new BigDecimal(0)); tickedJobsDetail.setActualPause(new BigDecimal(0)); } return tickedJobsDetail; }
From source file:controllers.SearchController.java
License:Open Source License
protected String determineHistogramResolution(final SearchResult searchResult) { final String interval; final int HOUR = 60; final int DAY = HOUR * 24; final int WEEK = DAY * 7; final int MONTH = HOUR * 24 * 30; final int YEAR = MONTH * 12; // Return minute as default resolution if search from and to DateTimes are not available if (searchResult.getFromDateTime() == null && searchResult.getToDateTime() == null) { return "minute"; }//from w w w. j a v a 2s. c o m int queryRangeInMinutes; // We don't want to use fromDateTime coming from the search query if the user asked for all messages if (isEmptyRelativeRange(searchResult.getTimeRange())) { List<IndexRangeSummary> usedIndices = searchResult.getUsedIndices(); Collections.sort(usedIndices, new Comparator<IndexRangeSummary>() { @Override public int compare(IndexRangeSummary o1, IndexRangeSummary o2) { return o1.start().compareTo(o2.start()); } }); IndexRangeSummary oldestIndex = usedIndices.get(0); queryRangeInMinutes = Minutes.minutesBetween(oldestIndex.start(), searchResult.getToDateTime()) .getMinutes(); } else { queryRangeInMinutes = Minutes .minutesBetween(searchResult.getFromDateTime(), searchResult.getToDateTime()).getMinutes(); } if (queryRangeInMinutes < DAY / 2) { interval = "minute"; } else if (queryRangeInMinutes < DAY * 2) { interval = "hour"; } else if (queryRangeInMinutes < MONTH) { interval = "day"; } else if (queryRangeInMinutes < MONTH * 6) { interval = "week"; } else if (queryRangeInMinutes < YEAR * 2) { interval = "month"; } else if (queryRangeInMinutes < YEAR * 10) { interval = "quarter"; } else { interval = "year"; } return interval; }
From source file:de.appsolve.padelcampus.admin.controller.bookings.AdminBookingsReservationsController.java
private Long getDuration(ReservationRequest reservationRequest, CalendarConfig calendarConfig) throws Exception { int minutes = Minutes.minutesBetween(reservationRequest.getStartTime(), reservationRequest.getEndTime()) .getMinutes();//from w w w .j av a2 s . co m if (minutes < calendarConfig.getMinDuration()) { throw new Exception(msg.get("MinDurationIs", new Object[] { calendarConfig.getMinDuration() })); } return Long.valueOf(minutes); }
From source file:de.cinovo.cloudconductor.server.rest.impl.AgentImpl.java
License:Apache License
@Override @Transactional/*from w w w.j av a 2 s . co m*/ public Set<String> getAliveAgents() { List<EHost> hosts = this.dhost.findList(); DateTime now = new DateTime(); Set<String> result = new HashSet<>(); for (EHost host : hosts) { DateTime dt = new DateTime(host.getLastSeen()); int diff = Minutes.minutesBetween(dt, now).getMinutes(); if (diff < AgentImpl.MAX_TIMEOUT_HOST) { result.add(host.getName()); } } return result; }
From source file:de.cinovo.cloudconductor.server.rest.impl.AgentImpl.java
License:Apache License
/** * @param template//w w w . jav a2 s . c o m * @param host */ private boolean sendPackageChanges(ETemplate template, EHost host) { DateTime now = DateTime.now(); int maxHostsOnUpdate = template.getHosts().size() / 2; int hostsOnUpdate = 0; if ((template.getSmoothUpdate() == null) || !template.getSmoothUpdate() || (maxHostsOnUpdate < 1)) { return true; } if (host.getStartedUpdate() != null) { return true; } for (EHost h : template.getHosts()) { if (h.getStartedUpdate() != null) { int timeElapsed = Minutes.minutesBetween(new DateTime(h.getStartedUpdate()), now).getMinutes(); if (timeElapsed > AgentImpl.MAX_UPDATE_THRESHOLD) { continue; } hostsOnUpdate++; } } if (maxHostsOnUpdate > hostsOnUpdate) { return true; } return false; }
From source file:de.cinovo.cloudconductor.server.util.CleanUpTask.java
License:Apache License
@Override public void run() { if (this.dhost == null) { CleanUpTask.LOGGER.debug("Couldn't get the host dao injected"); return;/*from www . j a v a 2s . co m*/ } List<EHost> hosts = this.dhost.findList(); Set<EHost> delete = new HashSet<>(); for (EHost host : hosts) { DateTime now = new DateTime(); DateTime dt = new DateTime(host.getLastSeen()); int diff = Minutes.minutesBetween(dt, now).getMinutes(); if (diff > CleanUpTask.MAX_AGE) { delete.add(host); } } for (EHost host : delete) { this.dhost.delete(host); } }
From source file:de.dekstop.cosm.Coverage.java
License:Open Source License
static int getDistance(CoverageType type, DateTime start, DateTime end) { switch (type) { case SECOND:/*from w ww .j a va 2s . c om*/ return Seconds.secondsBetween(start, end).getSeconds(); case MINUTE: return Minutes.minutesBetween(start, end).getMinutes(); case HOUR: return Hours.hoursBetween(start, end).getHours(); case DAY: return Days.daysBetween(start, end).getDays(); } throw new IllegalArgumentException("Unknown type: " + type); }
From source file:dk.nsi.haiba.lprimporter.rules.ConnectContactsRule.java
License:Open Source License
@Override public LPRRule doProcessing(Statistics statistics) { // Overlapping contacts has been sorted out now, so sort the contacts by in date Collections.sort(contacts, new AdministrationInDateComparator()); if (contacts.size() > 1) { Administration previousContact = null; for (Administration contact : contacts) { if (previousContact == null) { previousContact = contact; continue; }/*from w ww . j a va2 s .c om*/ DateTime previousOut = new DateTime(previousContact.getUdskrivningsDatetime()); DateTime in = new DateTime(contact.getIndlaeggelsesDatetime()); // if same hospital if (previousContact.getSygehusCode().equals(contact.getSygehusCode())) { // check if gap is <= "sameHospitalDifference" in hours if (Minutes.minutesBetween(previousOut, in).isGreaterThan(Minutes.minutes(0)) && Minutes.minutesBetween(previousOut, in) .isLessThan(Minutes.minutes(sameHospitalDifference * 60 + 1))) { // Increment counter for rule #13 statistics.rule13Counter += 1; previousContact.setUdskrivningsDatetime(contact.getIndlaeggelsesDatetime()); } } else { // else if different hospital // check if gap is <= "differentHospitalDifference" in hours if (Minutes.minutesBetween(previousOut, in).isGreaterThan(Minutes.minutes(0)) && Minutes.minutesBetween(previousOut, in) .isLessThan(Minutes.minutes(differentHospitalDifference * 60 + 1))) { // Increment counter for rule #13 statistics.rule13Counter += 1; previousContact.setUdskrivningsDatetime(contact.getIndlaeggelsesDatetime()); } } // set previous to current, for the next iteration previousContact = contact; } } else { log.trace("Only one contact in list"); } // setup the next rule in the chain contactToAdmissionRule.setContacts(contacts); return contactToAdmissionRule; }
From source file:energy.usef.core.util.PtuUtil.java
License:Apache License
/** * Return the number of PTU's between two {@link LocalDate}'s based on the ptuDuration and ptuIndex of the end date. * * @param startDate Start date for the difference (starting with ptu index 1) * @param endDate End date for the difference (ending at parameter ptuIndex) * @param ptuStartIndex The ptu index of the start date * @param ptuEndIndex The ptu index of the end date * @param ptuDuration Number of minutes per PTU * @return//from w w w .j av a 2s . c om */ public static Integer numberOfPtusBetween(LocalDate startDate, LocalDate endDate, int ptuStartIndex, int ptuEndIndex, int ptuDuration) { Double ptusPassed = Math .floor(Minutes.minutesBetween(startDate.toLocalDateTime(LocalTime.MIDNIGHT), endDate.toLocalDateTime(LocalTime.MIDNIGHT)).getMinutes() / ptuDuration) - ptuStartIndex + ptuEndIndex; return ptusPassed.intValue(); }
From source file:hoot.services.models.osm.Changeset.java
License:Open Source License
/** * Updates the expiration of this changeset in the database by modifying its closed at time * * This logic is pulled directly from the Rails port, and is meant to be executed * at the end of each upload process involving this changeset. This effectively extends the * changeset's expiration once any data is written to it and leaves it with a shorter expiration * if it has been opened but had no data added to it. * * @throws Exception/* ww w .j a v a 2 s .c om*/ * @todo This method is very confusing. */ public void updateExpiration() throws Exception { final DateTime now = new DateTime(); //SQLQuery query = new SQLQuery(conn, DbUtils.getConfiguration()); Changesets changesetRecord = (Changesets) new SQLQuery(conn, DbUtils.getConfiguration(_mapId)) .from(changesets).where(changesets.id.eq(getId())).singleResult(changesets); if (isOpen()) { final int maximumChangesetElements = Integer.parseInt(HootProperties.getInstance().getProperty( "maximumChangesetElements", HootProperties.getDefault("maximumChangesetElements"))); Timestamp newClosedAt = null; assert (changesetRecord.getNumChanges() <= maximumChangesetElements); if (changesetRecord.getNumChanges() == maximumChangesetElements) { newClosedAt = new Timestamp(now.getMillis()); } else if (changesetRecord.getNumChanges() > 0) { /* * from rails port: * * if (closed_at - created_at) > (MAX_TIME_OPEN - IDLE_TIMEOUT) * self.closed_at = create_at + MAX_TIME_OPEN * else * self.closed_at = Time.now.getutc + IDLE_TIMEOUT */ final DateTime createdAt = new DateTime(changesetRecord.getCreatedAt().getTime()); final DateTime closedAt = new DateTime(changesetRecord.getClosedAt().getTime()); final int changesetIdleTimeout = Integer.parseInt(HootProperties.getInstance().getProperty( "changesetIdleTimeoutMinutes", HootProperties.getDefault("changesetIdleTimeoutMinutes"))); final int changesetMaxOpenTime = Integer.parseInt(HootProperties.getInstance().getProperty( "changesetMaxOpenTimeHours", HootProperties.getDefault("changesetMaxOpenTimeHours"))); //The testChangesetAutoClose option = true causes changesetIdleTimeoutMinutes and //changesetMaxOpenTimeHours to be interpreted in seconds rather than minutes and hours, //respectively. This enables faster running of auto-close related unit tests. if (Boolean.parseBoolean(HootProperties.getInstance().getProperty("testChangesetAutoClose", HootProperties.getDefault("testChangesetAutoClose")))) { final int changesetMaxOpenTimeSeconds = changesetMaxOpenTime; final int changesetIdleTimeoutSeconds = changesetIdleTimeout; if (Seconds.secondsBetween(createdAt, closedAt) .getSeconds() > (changesetMaxOpenTimeSeconds - changesetIdleTimeoutSeconds)) { newClosedAt = new Timestamp(createdAt.plusSeconds(changesetMaxOpenTimeSeconds).getMillis()); } else { newClosedAt = new Timestamp(now.plusSeconds(changesetIdleTimeoutSeconds).getMillis()); } } else { final int changesetMaxOpenTimeMinutes = changesetMaxOpenTime * 60; final int changesetIdleTimeoutMinutes = changesetIdleTimeout; if (Minutes.minutesBetween(createdAt, closedAt) .getMinutes() > (changesetMaxOpenTimeMinutes - changesetIdleTimeoutMinutes)) { newClosedAt = new Timestamp(createdAt.plusMinutes(changesetMaxOpenTimeMinutes).getMillis()); } else { newClosedAt = new Timestamp(now.plusMinutes(changesetIdleTimeoutMinutes).getMillis()); } } } if (newClosedAt != null) { if (new SQLUpdateClause(conn, DbUtils.getConfiguration(_mapId), changesets) .where(changesets.id.eq(getId())).set(changesets.closedAt, newClosedAt).execute() != 1) { throw new Exception("Error updating expiration on changeset."); } } } else { //TODO: I have no idea why this code block is needed now. It didn't use to be, but after //some refactoring to support the changes to marking items as reviewed in ReviewResource, it //now is needed. I've been unable to track down what causes this to happen. if (!changesetRecord.getClosedAt().before(new Timestamp(now.getMillis()))) { if (new SQLUpdateClause(conn, DbUtils.getConfiguration(_mapId), changesets) .where(changesets.id.eq(getId())).set(changesets.closedAt, new Timestamp(now.getMillis())) .execute() != 1) { throw new Exception("Error updating expiration on changeset."); } } } }