List of usage examples for org.joda.time Duration Duration
public Duration(ReadableInstant start, ReadableInstant end)
From source file:de.fatalix.bookery.App.java
License:Open Source License
public void userLoggedIn(@Observes(notifyObserver = Reception.IF_EXISTS) UserLoggedInEvent event) { AppUser user = userService.updateLastLogin(event.getUsername()); if (user.getLastLogin() != null) { DateTime dtLastLogin = new DateTime(user.getLastLogin()); DateTime dtCurrentLogin = new DateTime(user.getCurrentLogin()); Duration duration = new Duration(dtLastLogin, dtCurrentLogin); String sinceLastLogin = ""; if (duration.getStandardDays() > 0) { long days = duration.getStandardDays(); if (days == 1) { sinceLastLogin = days + " day"; } else { sinceLastLogin = days + " days"; }//from w w w. j a v a2 s . co m } else if (duration.getStandardHours() > 0) { long hours = duration.getStandardHours(); if (hours == 1) { sinceLastLogin = hours + " hour"; } else { sinceLastLogin = hours + " hours"; } } else if (duration.getStandardMinutes() > 0) { long minutes = duration.getStandardMinutes(); if (minutes == 1) { sinceLastLogin = minutes + " minute"; } else { sinceLastLogin = minutes + " minutes"; } } else { long seconds = duration.getStandardSeconds(); if (seconds == 1) { sinceLastLogin = seconds + " second"; } else { sinceLastLogin = seconds + " seconds"; } } Notification.show("Welcome back " + event.getUsername() + " after " + sinceLastLogin + "."); } else { Notification.show("Welcome " + event.getUsername()); } logger.info("User " + event.getUsername() + " logged in."); getNavigator().navigateTo(HomeView.id); appLayout.getAppHeader().setLoginName(SecurityUtils.getSubject().getPrincipal().toString()); appLayout.getAppHeader().setVisible(isLoggedIn()); }
From source file:de.fu_berlin.inf.dpp.feedback.SessionDataCollector.java
License:Open Source License
@Override protected void processGatheredData() { data.setSessionID(currentSessionID); data.setLocalSessionStartTime(localSessionStart); data.setLocalSessionEndTime(localSessionEnd); data.setLocalSessionDuration(// w w w . j av a 2s . co m StatisticManager.getTimeInMinutes(new Duration(localSessionStart, localSessionEnd).getMillis())); data.setSessionCount(statisticManager.getSessionCount()); data.setIsHost(isHost); if (statisticManager.isPseudonymSubmissionAllowed()) { String pseudonym = statisticManager.getStatisticsPseudonymID().trim(); if (pseudonym.length() > 0) { data.setPseudonym(pseudonym); } } storeGeneralInfos(); }
From source file:de.hpi.bpmn2_0.replay.ReplayTrace.java
License:Open Source License
private void calcTimingAll() { TraceNode node;/*from w ww .j a v a2 s. co m*/ DateTime timeBefore = null; DateTime timeAfter = null; int timeBeforePos = 0; int timeAfterPos = 0; long duration; for (int i = 0; i < timeOrderedReplayedNodes.size(); i++) { node = timeOrderedReplayedNodes.get(i); timeBefore = null; timeAfter = null; if (!node.isTimed()) { //---------------------------------------- // The incoming nodes to this node have been already assigned timestamps // according to the traversal order starting from the Start event node (always timed) // Therefore, a node selects timestamp based on those of its incoming nodes. // This is to ensure a node's timestamp must be after all timestamp of its incoming nodes //---------------------------------------- TraceNode mostRecentIncomingNode = null; for (TraceNode incomingNode : node.getSources()) { if (timeBefore == null || timeBefore.isBefore(incomingNode.getStart())) { timeBefore = incomingNode.getStart(); mostRecentIncomingNode = incomingNode; } } timeBeforePos = timeOrderedReplayedNodes.indexOf(mostRecentIncomingNode); //---------------------------------------- //Go backward and look for a timed node, //known that it can either encounter a timed activity/gateway or //the Start event node (always timed) //---------------------------------------- /* for (int j=i-1;j>=0;j--) { if (timeOrderedReplayedNodes.get(j).isTimed()) { timeBefore = timeOrderedReplayedNodes.get(j).getStart(); timeBeforePos = j; break; } } */ //---------------------------------------- // Go forward and look for a timed node, known that it can encounter // either a timed node or the End event node eventually (always timed). // In the timeOrderedReplayedNodes array order, all nodes after // this node are either subsequent and connected to it on the model or // in parallel with it. It is possible to set a node's timestamp // after that of a parallel node because its next sequential node may have timestamp // after the node in parallel. So, this ensures its timestamp is after // any next node in chronological order, either sequential or parallel //---------------------------------------- for (int j = i + 1; j < timeOrderedReplayedNodes.size(); j++) { if (timeOrderedReplayedNodes.get(j).isTimed() && timeOrderedReplayedNodes.get(j).getStart().isAfter(timeBefore)) { timeAfter = timeOrderedReplayedNodes.get(j).getStart(); timeAfterPos = j; break; } } //---------------------------------------- //It may happen that timeBefore >= timeAfter because the two activities //at timeBeforePos and timeAfterPos are on parallel branches and have //the same timestamp. //---------------------------------------- /* if (timeBefore != null && timeAfter != null && timeBefore.isEqual(timeAfter) && !node.getSources().contains(timeOrderedReplayedNodes.get(timeBeforePos))) { //For activity or split gateway: continue searching backward for another timed node if (node.getSources().size() <= 1) { for (int j=timeBeforePos-1;j>=0;j--) { if (timeOrderedReplayedNodes.get(j).isTimed() && timeOrderedReplayedNodes.get(j).getStart().isBefore(timeAfter)) { timeBefore = timeOrderedReplayedNodes.get(j).getStart(); timeBeforePos = j; break; } } } //For joining gateway: continue searching forward for another timed node else { for (int j=timeAfterPos+1;j<timeOrderedReplayedNodes.size();j++) { if (timeOrderedReplayedNodes.get(j).isTimed() && timeOrderedReplayedNodes.get(j).getStart().isAfter(timeBefore)) { timeAfter = timeOrderedReplayedNodes.get(j).getStart(); timeAfterPos = j; break; } } } } */ //---------------------------------------------- //Always take two ends of the trace plus a buffer as time limit //in case the replay trace has no timestamped activity at two ends //NOTE: This is in case some process models cannot reach the End Event (unsound model) //---------------------------------------------- if (timeBefore == null) { timeBefore = (new DateTime(LogUtility.getTimestamp(logTrace.getTrace().get(0)))) .minusSeconds(replayer.getReplayParams().getStartEventToFirstEventDuration()); } if (timeAfter == null) { timeAfter = (new DateTime( LogUtility.getTimestamp(logTrace.getTrace().get(logTrace.getTrace().size() - 1)))) .plusSeconds(replayer.getReplayParams().getLastEventToEndEventDuration()); } //---------------------------------------------- // Take average timestamp between TimeBefore and TimeAfter //---------------------------------------------- duration = (new Duration(timeBefore, timeAfter)).getMillis(); if (timeAfterPos > timeBeforePos) { duration = Math.round(1.0 * duration * (i - timeBeforePos) / (timeAfterPos - timeBeforePos)); } node.setStart(timeBefore.plus(Double.valueOf(duration).longValue())); } } }
From source file:de.hpi.bpmn2_0.replay.ReplayTrace.java
License:Open Source License
private void calculateCompleteTimestamp() { DateTime earliestTarget = null;//w ww . jav a 2s . c o m long transferDuration; for (TraceNode node : this.timeOrderedReplayedNodes) { if (node.isActivity()) { if (node.getTargets().size() > 0) { earliestTarget = node.getTargets().get(0).getStart(); for (TraceNode target : node.getTargets()) { if (earliestTarget.isAfter(target.getStart())) { earliestTarget = target.getStart(); } } transferDuration = (new Duration(node.getStart(), earliestTarget)).getMillis(); node.setComplete(node.getStart() .plusMillis(Long.valueOf(Math.round(transferDuration * 0.1)).intValue())); } else { node.setComplete(node.getStart().plusMillis(5000)); } } else { node.setComplete(node.getStart()); } } }
From source file:de.minecrawler.cache.CacheManager.java
License:Open Source License
/** * @param index//from w ww .j a v a 2s. c o m * Index to check * @return <code>true</code> when the cache is expired, otherwhise * <code>false</code> */ private boolean isExpired(CacheIndex index) { Duration dur = new Duration(index.creationDate, null); return dur.getStandardHours() >= EXPIRE_HOUR; }
From source file:dk.dma.arcticweb.service.AppDataServiceBean.java
License:Apache License
private void createSarfaqSchedule() { logger.info("BEFORE SCHEDULE - SARFAQ"); Vessel sarfaq = vesselDao.getVessel(331037000L); DateTime now = DateTime.now(DateTimeZone.UTC); DateTimeConverter converter = DateTimeConverter.getDateTimeConverter(); DateTime firstDeparture = converter.toObject("27-09-2013 21:00"); sarfaq.addVoyageEntry(new Voyage("Nuuk", "64 10.4N", "051 43.5W", null, firstDeparture)); sarfaq.addVoyageEntry(new Voyage("Maniitsoq", "65 24.8N", "052 54.3W", converter.toObject("28-09-2013 07:00"), converter.toObject("28-09-2013 07:30"))); sarfaq.addVoyageEntry(new Voyage("Kangaamiut", "65 49.6N", "053 20.9W", converter.toObject("28-09-2013 10:45"), converter.toObject("28-09-2013 11:00"))); sarfaq.addVoyageEntry(new Voyage("Sisimiut", "66 56.5N", "053 40.5W", converter.toObject("28-09-2013 18:00"), converter.toObject("28-09-2013 21:00"))); sarfaq.addVoyageEntry(new Voyage("Aasiaat", "68 42.6N", "052 53.0W", converter.toObject("29-09-2013 08:00"), converter.toObject("29-09-2013 08:30"))); sarfaq.addVoyageEntry(new Voyage("Ilulissat", "69 13.5N", "051 06.0W", converter.toObject("29-09-2013 13:00"), converter.toObject("29-09-2013 17:00"))); sarfaq.addVoyageEntry(new Voyage("Aasiaat", "68 42.6N", "052 53.0W", converter.toObject("29-09-2013 21:30"), converter.toObject("29-09-2013 22:00"))); sarfaq.addVoyageEntry(new Voyage("Sisimiut", "66 56.5N", "053 40.5W", converter.toObject("30-09-2013 09:00"), converter.toObject("30-09-2013 10:30"))); sarfaq.addVoyageEntry(new Voyage("Kangaamiut", "65 49.6N", "053 20.9W", converter.toObject("30-09-2013 17:30"), converter.toObject("30-09-2013 17:45"))); sarfaq.addVoyageEntry(new Voyage("Maniitsoq", "65 24.8N", "052 54.3W", converter.toObject("30-09-2013 21:30"), converter.toObject("30-09-2013 22:00"))); sarfaq.addVoyageEntry(new Voyage("Nuuk", "64 10.4N", "051 43.5W", converter.toObject("01-10-2013 06:30"), converter.toObject("01-10-2013 09:00"))); sarfaq.addVoyageEntry(new Voyage("Qeqertarsuatsiaat", "63 05.4N", "050 41.0W", converter.toObject("01-10-2013 16:30"), converter.toObject("01-10-2013 16:45"))); sarfaq.addVoyageEntry(new Voyage("Paamiut", "61 59.8N", "049 40.8W", converter.toObject("01-10-2013 23:30"), converter.toObject("02-10-2013 00:00"))); sarfaq.addVoyageEntry(new Voyage("Arsuk", "61 10.5N", "048 27.1W", converter.toObject("02-10-2013 06:45"), converter.toObject("02-10-2013 07:00"))); sarfaq.addVoyageEntry(new Voyage("Qaqortoq", "60 43.1N", "046 02.4W", converter.toObject("02-10-2013 15:30"), converter.toObject("02-10-2013 19:00"))); sarfaq.addVoyageEntry(new Voyage("Narsaq", "60 54.5N", "046 03.0W", converter.toObject("02-10-2013 21:00"), converter.toObject("02-10-2013 21:30"))); sarfaq.addVoyageEntry(new Voyage("Arsuk", "61 10.5N", "048 27.2W", converter.toObject("03-10-2013 06:45"), converter.toObject("03-10-2013 07:00"))); sarfaq.addVoyageEntry(new Voyage("Paamiut", "61 59.8N", "049 40.8W", converter.toObject("03-10-2013 13:30"), converter.toObject("03-10-2013 14:30"))); sarfaq.addVoyageEntry(new Voyage("Qeqertarsuatsiaat", "63 05.4N", "050 41.0W", converter.toObject("03-10-2013 22:30"), converter.toObject("03-10-2013 22:45"))); sarfaq.addVoyageEntry(new Voyage("Nuuk", "64 10.4N", "051 43.5W", converter.toObject("04-10-2013 09:00"), converter.toObject("04-10-2013 11:00"))); // firstDeparture. Duration d = new Duration(firstDeparture, now); int weeks = (int) d.getStandardDays() / 7; logger.debug("Duration: {}, weeks:{}, days: {}", d, weeks, d.getStandardDays()); List<Voyage> schedule = sarfaq.getSchedule(); if (weeks > 0) { for (Voyage v : schedule) { v.setArrival(v.getArrival() == null ? null : v.getArrival().plusWeeks(weeks)); v.setDeparture(v.getDeparture() == null ? null : v.getDeparture().plusWeeks(weeks)); }/*from ww w . java 2 s.c om*/ } logger.debug("Schedule: {}", schedule); for (Voyage v : schedule) { scheduleDao.saveEntity(v); } em.flush(); }
From source file:dk.nsi.haiba.epimibaimporter.status.ImportStatus.java
License:Open Source License
@Override public String toString() { String body = "\nLast import started at: " + this.getStartTime(); Outcome outcome = this.getOutcome(); if (endTime != null) { body += " and ended at: " + this.getEndTime(); body += ". Processing took " + new Duration(this.getStartTime(), this.getEndTime()).getStandardSeconds() + " seconds"; } else {// w w w. j a v a2 s .com body += " and is still running"; } if (outcome != null) { body += ". Outcome was " + outcome; if (outcome.equals(Outcome.FAILURE)) { body += ", error was " + errorMessage; } } return body; }
From source file:dk.teachus.backend.domain.impl.PeriodImpl.java
License:Apache License
public boolean isTimeValid(LocalTime time) { boolean timeValid = false; Interval periodTimeInterval = new Interval(startTime.toDateTimeToday(), endTime.toDateTimeToday()); if (periodTimeInterval.contains(time.toDateTimeToday())) { int timeMinutes = new Duration(startTime.toDateTimeToday(), time.toDateTimeToday()) .toPeriod(PeriodType.minutes()).getMinutes(); if (timeMinutes % intervalBetweenLessonStart == 0) { timeValid = true;/*from w w w. jav a2 s . co m*/ } } return timeValid; }
From source file:dk.teachus.utils.DateUtils.java
License:Apache License
public static int intervalMinutes(DateTime date1, DateTime date2) { int intervalMinutes = 0; if (date1 != null && date2 != null) { intervalMinutes = new Duration(date1, date2).toPeriod(PeriodType.minutes()).getMinutes(); }/*from w w w . j a v a2 s . co m*/ return intervalMinutes; }
From source file:energy.usef.core.util.DateTimeUtil.java
License:Apache License
/** * Gets the number of milliseconds until the next occurence of the local time (which is the current day or the day after). * * @param localTime {@link LocalTime}/*from w ww. ja v a 2 s . c o m*/ * @return the number of milliseconds. */ public static Long millisecondDelayUntilNextTime(LocalTime localTime) { LocalDateTime schedule = getCurrentDateWithTime(localTime); if (schedule.isBefore(getCurrentDateTime())) { schedule = schedule.plusDays(1); } return new Duration(getCurrentDateTime().toDateTime(), schedule.toDateTime()).getMillis(); }