List of usage examples for org.joda.time Duration standardHours
public static Duration standardHours(long hours)
From source file:ch.css.workingdiary.WorkingDiaryConfiguration.java
License:Open Source License
public static Duration getExpireIn() { return Duration.standardHours(1); }
From source file:com.almende.eve.agent.MeetingAgent.java
License:Apache License
/** * update the activity for meeting agent. * /* w w w. j a v a2 s.c o m*/ * @param updatedActivity * the updated activity * @return the activity * @throws Exception * the exception */ public Activity updateActivity(@Name("activity") final Activity updatedActivity) throws Exception { Activity activity = getState().get("activity", Activity.class); if (activity == null) { activity = new Activity(); } final Set<String> prevAttendees = getAgents(activity); // if no updated timestamp is provided, set the timestamp to now if (updatedActivity.withStatus().getUpdated() == null) { updatedActivity.withStatus().setUpdated(DateTime.now().toString()); } // synchronize with the stored activity activity = Activity.sync(activity, updatedActivity); // ensure the url of the meeting agent is filled in final URI myUrl = getFirstUrl("http"); activity.setAgent(myUrl); // create duration when missing Long duration = activity.withConstraints().withTime().getDuration(); if (duration == null) { duration = Duration.standardHours(1).getMillis(); // 1 hour in ms activity.withConstraints().withTime().setDuration(duration); } // remove calendar events from removed attendees final Set<String> currentAttendees = getAgents(activity); final Set<String> removedAttendees = new TreeSet<String>(prevAttendees); removedAttendees.removeAll(currentAttendees); for (final String attendee : removedAttendees) { clearAttendee(attendee); } getState().put("activity", activity); // update all attendees, start timer to regularly check update(); return getState().get("activity", Activity.class); }
From source file:com.almende.eve.agent.MeetingAgent.java
License:Apache License
/** * Calculate all feasible intervals with their preference weight, based on * the event status, stored infeasible intervals, and preferred intervals. * If there are no solutions, an empty array is returned. * // www . ja va 2 s . co m * @return solutions */ private List<Weight> calculateSolutions() { LOG.info("calculateSolutions started"); // TODO: cleanup final State state = getState(); final List<Weight> solutions = new ArrayList<Weight>(); // get the activity final Activity activity = state.get("activity", Activity.class); if (activity == null) { return solutions; } // get infeasible intervals ArrayList<Interval> infeasible = state.get("infeasible", new TypeUtil<ArrayList<Interval>>() { }); if (infeasible == null) { infeasible = new ArrayList<Interval>(); } // get preferred intervals List<Weight> preferred = state.get("preferred", new TypeUtil<ArrayList<Weight>>() { }); if (preferred == null) { preferred = new ArrayList<Weight>(); } // get the duration of the activity final Long durationLong = activity.withConstraints().withTime().getDuration(); Duration duration = null; if (durationLong != null) { duration = new Duration(durationLong); } else { // TODO: give error when duration is not defined? duration = Duration.standardHours(1); } // check interval at next half hour final DateTime firstTimeslot = getNextHalfHour(); Interval test = new Interval(firstTimeslot, firstTimeslot.plus(duration)); testInterval(infeasible, preferred, test, solutions); // loop over all infeasible intervals for (final Interval i : infeasible) { // test timeslot left from the infeasible interval test = new Interval(i.getStart().minus(duration), i.getStart()); testInterval(infeasible, preferred, test, solutions); // test timeslot right from the infeasible interval test = new Interval(i.getEnd(), i.getEnd().plus(duration)); testInterval(infeasible, preferred, test, solutions); } // loop over all preferred intervals for (final Weight w : preferred) { // test timeslot left from the start of the preferred interval test = new Interval(w.getStart().minus(duration), w.getStart()); testInterval(infeasible, preferred, test, solutions); // test timeslot right from the start of the preferred interval test = new Interval(w.getStart(), w.getStart().plus(duration)); testInterval(infeasible, preferred, test, solutions); // test timeslot left from the end of the preferred interval test = new Interval(w.getEnd().minus(duration), w.getEnd()); testInterval(infeasible, preferred, test, solutions); // test timeslot right from the end of the preferred interval test = new Interval(w.getEnd(), w.getEnd().plus(duration)); testInterval(infeasible, preferred, test, solutions); } // order the calculated feasible timeslots by weight, from highest to // lowest. In case of equals weights, the timeslots are ordered by // start date class WeightComparator implements Comparator<Weight> { @Override public int compare(final Weight a, final Weight b) { if (a.getWeight() != null && b.getWeight() != null) { final int cmp = Double.compare(a.getWeight(), b.getWeight()); if (cmp == 0) { return a.getStart().compareTo(b.getStart()); } else { return -cmp; } } return 0; } } final WeightComparator comparator = new WeightComparator(); Collections.sort(solutions, comparator); // remove duplicates int i = 1; while (i < solutions.size()) { if (solutions.get(i).equals(solutions.get(i - 1))) { solutions.remove(i); } else { i++; } } return solutions; }
From source file:com.google.cloud.dataflow.sdk.transforms.windowing.SlidingWindows.java
License:Apache License
static Duration getDefaultPeriod(Duration size) { if (size.isLongerThan(Duration.standardHours(1))) { return Duration.standardHours(1); }/*from w ww .j a va2 s .c o m*/ if (size.isLongerThan(Duration.standardMinutes(1))) { return Duration.standardMinutes(1); } if (size.isLongerThan(Duration.standardSeconds(1))) { return Duration.standardSeconds(1); } return Duration.millis(1); }
From source file:com.google.cloud.training.dataanalyst.flights.PredictRealtime.java
License:Apache License
public static Instant toInstant(String date, String hourmin) { // e.g: 2015-01-01 and 0837 int hrmin = Integer.parseInt(hourmin); int hr = hrmin / 100; int min = hrmin % 100; return Instant.parse(date) // .plus(Duration.standardHours(hr)) // .plus(Duration.standardMinutes(min)); }
From source file:com.linkedin.pinot.controller.validation.ValidationManager.java
License:Apache License
/** * Computes a list of missing intervals, given a list of existing intervals and the expected frequency of the * intervals.//from w w w . j a v a 2s.c om * * @param segmentIntervals The list of existing intervals * @param frequency The expected interval frequency * @return The list of missing intervals */ public static List<Interval> computeMissingIntervals(List<Interval> segmentIntervals, Duration frequency) { // Sanity check for freuency if (frequency == null) { return Collections.emptyList(); } // Default segment granularity to day level if its small than hours. if (frequency.getMillis() < Duration.standardHours(1).getMillis()) { frequency = Duration.standardDays(1); } // If there are less than two segments, none can be missing if (segmentIntervals.size() < 2) { return Collections.emptyList(); } // Sort the intervals by ascending starting time List<Interval> sortedSegmentIntervals = new ArrayList<Interval>(segmentIntervals); Collections.sort(sortedSegmentIntervals, new Comparator<Interval>() { @Override public int compare(Interval first, Interval second) { if (first.getStartMillis() < second.getStartMillis()) return -1; else if (second.getStartMillis() < first.getStartMillis()) return 1; return 0; } }); // Find the minimum starting time and maximum ending time final long startTime = sortedSegmentIntervals.get(0).getStartMillis(); long endTime = Long.MIN_VALUE; for (Interval sortedSegmentInterval : sortedSegmentIntervals) { if (endTime < sortedSegmentInterval.getEndMillis()) { endTime = sortedSegmentInterval.getEndMillis(); } } final long frequencyMillis = frequency.getMillis(); int lastEndIntervalCount = 0; List<Interval> missingIntervals = new ArrayList<Interval>(10); for (Interval segmentInterval : sortedSegmentIntervals) { int startIntervalCount = (int) ((segmentInterval.getStartMillis() - startTime) / frequencyMillis); int endIntervalCount = (int) ((segmentInterval.getEndMillis() - startTime) / frequencyMillis); // If there is at least one complete missing interval between the end of the previous interval and the start of // the current interval, then mark the missing interval(s) as missing if (lastEndIntervalCount < startIntervalCount - 1) { for (int missingIntervalIndex = lastEndIntervalCount + 1; missingIntervalIndex < startIntervalCount; ++missingIntervalIndex) { missingIntervals.add(new Interval(startTime + frequencyMillis * missingIntervalIndex, startTime + frequencyMillis * (missingIntervalIndex + 1) - 1)); } } lastEndIntervalCount = Math.max(lastEndIntervalCount, endIntervalCount); } return missingIntervals; }
From source file:com.mastfrog.acteur.wicket.EnsureSessionId.java
License:Open Source License
@Inject EnsureSessionId(HttpEvent evt, Application app, Settings settings) { SessionId id = findSessionId(evt);// www .j a v a 2 s. c o m if (id == null) { id = new SessionId(); DefaultCookie ck = new DefaultCookie(ActeurSessionStore.COOKIE_NAME, id.toString()); long maxAge = Duration.standardHours(settings.getLong(SETTINGS_KEY_SESSION_COOKIE_MAX_AGE_HOURS, DEFAULT_SESSION_COOKIE_MAX_AGE_HOURS)).toStandardSeconds().getSeconds(); ck.setMaxAge(maxAge); add(Headers.SET_COOKIE, ck); String sv = Headers.COOKIE.toString(new Cookie[] { ck }); evt.getRequest().headers().add(Headers.SET_COOKIE.name(), sv); IRequestLogger logger = app.getRequestLogger(); if (logger != null) { logger.sessionCreated(id.toString()); } } setState(new ConsumedLockedState(id)); }
From source file:com.mirth.connect.server.util.LoginRequirementsChecker.java
License:Open Source License
public long getStrikeTimeRemaining() { Duration lockoutPeriod = Duration.standardHours(passwordRequirements.getLockoutPeriod()); synchronized (userLoginStrikes) { Duration strikeDuration = new Duration( userLoginStrikes.get(username).getLastStrikeTime().getTimeInMillis(), System.currentTimeMillis()); return lockoutPeriod.minus(strikeDuration).getMillis(); }//from w w w . j a v a 2 s . c om }
From source file:com.nesscomputing.service.discovery.server.DiscoveryServerMain.java
License:Apache License
@Override public Module getMainModule(final Config config) { return new AbstractModule() { @Override/* w ww.ja v a 2 s . co m*/ public void configure() { install(new BasicGalaxyServerModule(config)); install(new ZookeeperModule(config)); install(new DiscoveryClientModule(false)); install(new NessQuartzModule(config)); bind(ZookeeperCleanupJob.class); QuartzJobBinder.bindQuartzJob(binder(), ZookeeperCleanupJob.class).conditional("zookeeper-cleanup") .delay(Duration.standardMinutes(1)).repeat(Duration.standardHours(8)).register(); bind(DiscoveryServerConfig.class).toProvider(ConfigProvider.of(DiscoveryServerConfig.class)) .in(Scopes.SINGLETON); bind(ZookeeperJobProcessor.class).in(Scopes.SINGLETON); bind(StateOfTheWorldResource.class); bind(ServiceLookupResource.class); bind(StaticAnnouncementResource.class); bind(ConfigStaticAnnouncer.class).asEagerSingleton(); } }; }
From source file:com.peertopark.java.dates.Dates.java
License:Apache License
public static long getSecondsFromHours(long hours) { return Duration.standardHours(hours).getStandardSeconds(); }