List of usage examples for org.joda.time Duration ZERO
Duration ZERO
To view the source code for org.joda.time Duration ZERO.
Click Source Link
From source file:io.v.impl.google.lib.discovery.GlobalDiscovery.java
License:Open Source License
/** * Returns a new global {@link Discovery} instance that uses the Vanadium namespace * under {@code path} with default mount ttl (120s) and scan interval (90s). * * @param ctx current context/*from ww w.j a v a 2s . com*/ * @param path a namespace path to use for global discovery * @throws VException if a new discovery instance cannot be created */ public static Discovery newDiscovery(VContext ctx, String path) throws VException { return nativeNewDiscovery(ctx, path, Duration.ZERO, Duration.ZERO); }
From source file:io.v.mojo.discovery.DiscoveryImpl.java
License:Open Source License
private static Duration parseDuration(String duration) { if (duration == null || duration.equals("0")) { return Duration.ZERO; }/*from ww w . j a va 2 s. c o m*/ PeriodFormatter formatter = new PeriodFormatterBuilder().appendHours().appendSuffix("h").appendMinutes() .appendSuffix("m").appendSecondsWithOptionalMillis().appendSuffix("s").toFormatter(); return formatter.parsePeriod(duration).toStandardDuration(); }
From source file:julian.lylly.model.Prospect.java
public List<Pair<Duration, Duration>> getBudgets(LocalDate pointer, Duration timespent) { int relDay = Days.daysBetween(start, pointer).getDays(); if (pointer.isBefore(start) || !end.isAfter(pointer)) { throw new IllegalArgumentException("day is out of range:\t" + "start = " + start.toString() + "\t" + "pointer = " + pointer.toString() + "\t" + "end = " + end.toString()); }// w ww.j a v a 2s . com List<Integer> subl = weights.subList(relDay, weights.size()); int sum = 0; for (int k : subl) { sum += k; } Duration minleft = Util.max(Duration.ZERO, min.minus(timespent)); Duration maxleft = Util.max(Duration.ZERO, max.minus(timespent)); List<Pair<Duration, Duration>> res = new ArrayList<>(); for (int k : subl) { Duration bMin = minleft.multipliedBy(k).dividedBy(sum); Duration bMax = maxleft.multipliedBy(k).dividedBy(sum); res.add(new Pair(bMin, bMax)); } return res; }
From source file:julian.lylly.model.Task.java
/** * behaviour undefined if interval list is unsorted * any {@code null} input is interpreted as a non-bound in that direction * @param focusStart/*from ww w . j ava 2 s .c o m*/ * @param focusEnd * @return */ public Duration getTimeSpentInInterval(LocalDate focusStart, LocalDate focusEnd) { Instant startInst, endInst; if (intervals.size() == 0 && !isActive()) { // # return Duration.ZERO; } if (focusStart == null) { startInst = intervals.size() == 0 ? starttime // != null because # : intervals.get(0).getStart().toInstant(); } else { startInst = focusStart.toDateTimeAtStartOfDay().toInstant(); } if (focusEnd == null) { endInst = isActive() ? Instant.now() //v intervals.size() != 0 because # : intervals.get(intervals.size() - 1).getEnd().toInstant();//TODO } else { endInst = focusEnd.toDateTimeAtStartOfDay().toInstant(); } Interval focus = new Interval(startInst, endInst); return getTimeSpentInInterval(focus); }
From source file:julian.lylly.model.Task.java
public Duration getTimeSpentInInterval(Interval focus) { if (focus == null) { throw new IllegalArgumentException("focus == nul"); }/*from w w w . ja va 2s. c o m*/ Duration timespent = Duration.ZERO; for (Interval i : intervals) { Duration ov = computeOverlap(i, focus); timespent = timespent.plus(ov); } if (isActive()) { Interval activeInterval = new Interval(starttime, Instant.now()); Duration overlapDuration = computeOverlap(activeInterval, focus); timespent = timespent.plus(overlapDuration); } return timespent; }
From source file:julian.lylly.model.Task.java
private Duration computeOverlap(Interval x, Interval y) { if (x.overlaps(y)) { return x.overlap(y).toDuration(); } else {/*from w w w . ja va2s . c o m*/ return Duration.ZERO; } }
From source file:julian.lylly.model.TaskOrganizerImpl.java
@Override public Duration getInvestedTime(LocalDate start, LocalDate end, Tag tag) { Duration sum = Duration.ZERO; for (Task task : toDo) { // Check for null, because some tasks may not have a tag if (task.getTag() != null) { if (task.getTag().equals(tag)) { sum = sum.plus(task.getTimeSpentInInterval(start, end)); }//from w w w . ja v a 2s. c o m } } return sum; }
From source file:kr.debop4j.timeperiod.calendars.DateAdd.java
License:Apache License
/** start ? offset ? ?? . */ public DateTime add(DateTime start, Duration offset, SeekBoundaryMode seekBoundary) { if (isTraceEnable) log.trace("Add. start=[{}] + offset=[{}]? ?? . seekBoundaryMode=[{}]", start, offset, seekBoundary);//from w w w .ja v a2 s.c o m if (getIncludePeriods().size() == 0 && getExcludePeriods().size() == 0) return start.plus(offset); Pair<DateTime, Duration> results = offset.compareTo(Duration.ZERO) < 0 ? calculateEnd(start, Durations.negate(offset), SeekDirection.Backward, seekBoundary) : calculateEnd(start, offset, SeekDirection.Forward, seekBoundary); DateTime end = (results != null) ? results.getV1() : null; Duration remaining = (results != null) ? results.getV2() : null; if (isDebugEnable) log.debug( "Add. start=[{}] + offset=[{}] ? end=[{}], remaining=[{}]. seekBoundaryMode=[{}]", start, offset, end, remaining, seekBoundary); return end; }
From source file:kr.debop4j.timeperiod.calendars.DateAdd.java
License:Apache License
/** start ? offset ? ( ??) ?? . */ public DateTime subtract(DateTime start, Duration offset, SeekBoundaryMode seekBoundary) { if (isTraceEnable) log.trace("Subtract. start=[{}] - offset=[{}]? ?? . seekBoundaryMode=[{}]", start, offset, seekBoundary); Pair<DateTime, Duration> results = offset.compareTo(Duration.ZERO) < 0 ? calculateEnd(start, Durations.negate(offset), SeekDirection.Forward, seekBoundary) : calculateEnd(start, offset, SeekDirection.Backward, seekBoundary); DateTime end = (results != null) ? results.getV1() : null; Duration remaining = (results != null) ? results.getV2() : null; if (isDebugEnable) log.debug(/*from w w w . j a va 2 s .c o m*/ "Subtract. start=[{}] - offset=[{}] ? end=[{}], remaining=[{}]. seekBoundaryMode=[{}]", start, offset, end, remaining, seekBoundary); return end; }
From source file:kr.debop4j.timeperiod.calendars.DateAdd.java
License:Apache License
/** * ? offset ? ?? ./*from w w w . j a v a 2 s . co m*/ * * @param start ? * @param offset * @param seekDir ? * @param seekBoundary ? * @return ? ?, */ protected Pair<DateTime, Duration> calculateEnd(DateTime start, Duration offset, SeekDirection seekDir, SeekBoundaryMode seekBoundary) { if (isTraceEnable) log.trace( "? ? ?? ... start=[{}], offset=[{}], seekDir=[{}], seekBoundary=[{}]", start, offset, seekDir, seekBoundary); shouldBe(offset.compareTo(Duration.ZERO) >= 0, "offset? 0 ??? . offset=[%d]", offset.getMillis()); Duration remaining = offset; DateTime end; // search periods ITimePeriodCollection searchPeriods = new TimePeriodCollection(this.includePeriods); if (searchPeriods.size() == 0) searchPeriods.add(TimeRange.Anytime); // available periods ITimePeriodCollection availablePeriods = new TimePeriodCollection(); if (excludePeriods.size() == 0) { availablePeriods.addAll(searchPeriods); } else { if (isTraceEnable) log.trace(" ? ."); TimeGapCalculator<TimeRange> gapCalculator = new TimeGapCalculator<>(); for (ITimePeriod p : searchPeriods) { if (excludePeriods.hasOverlapPeriods(p)) { if (isTraceEnable) log.trace(" ? ? ? "); for (ITimePeriod gap : gapCalculator.getGaps(excludePeriods, p)) availablePeriods.add(gap); } else { availablePeriods.add(p); } } } if (availablePeriods.size() == 0) { if (isTraceEnable) log.trace(" period ."); return Pair.create(null, remaining); } if (isTraceEnable) log.trace(" ? ? ? ..."); TimePeriodCombiner periodCombiner = new TimePeriodCombiner<TimeRange>(); availablePeriods = periodCombiner.combinePeriods(availablePeriods); if (isTraceEnable) log.trace(" ? ."); Pair<ITimePeriod, DateTime> result = (seekDir == SeekDirection.Forward) ? findNextPeriod(start, availablePeriods) : findPrevPeriod(start, availablePeriods); ITimePeriod startPeriod = result.getV1(); DateTime seekMoment = result.getV2(); // ? . if (startPeriod == null) { if (isTraceEnable) log.trace(" ? ."); return Pair.create(null, remaining); } // offset ? 0 ??, ? ? seekMoment . if (offset.isEqual(Duration.ZERO)) { if (isTraceEnable) log.trace("offset ? 0?, ? ? seekMoment ."); return Pair.create(seekMoment, remaining); } if (seekDir == SeekDirection.Forward) { for (int i = availablePeriods.indexOf(startPeriod); i < availablePeriods.size(); i++) { ITimePeriod gap = availablePeriods.get(i); Duration gapRemaining = new Duration(seekMoment, gap.getEnd()); if (isTraceEnable) log.trace("Seek forward. gap=[{}], gapRemaining=[{}], remaining=[{}], seekMoment=[{}]", gap, gapRemaining, remaining, seekMoment); boolean isTargetPeriod = (seekBoundary == SeekBoundaryMode.Fill) ? gapRemaining.compareTo(remaining) >= 0 : gapRemaining.compareTo(remaining) > 0; if (isTargetPeriod) { end = seekMoment.plus(remaining); remaining = null; return Pair.create(end, remaining); } remaining = remaining.minus(gapRemaining); if (i == availablePeriods.size() - 1) return Pair.create(null, remaining); seekMoment = availablePeriods.get(i + 1).getStart(); // next period } } else { for (int i = availablePeriods.indexOf(startPeriod); i >= 0; i--) { ITimePeriod gap = availablePeriods.get(i); Duration gapRemaining = new Duration(gap.getStart(), seekMoment); if (isTraceEnable) log.trace("Seek backward. gap=[{}], gapRemaining=[{}], remaining=[{}], seekMoment=[{}]", gap, gapRemaining, remaining, seekMoment); boolean isTargetPeriod = (seekBoundary == SeekBoundaryMode.Fill) ? gapRemaining.compareTo(remaining) >= 0 : gapRemaining.compareTo(remaining) > 0; if (isTargetPeriod) { end = seekMoment.minus(remaining); remaining = null; return Pair.create(end, remaining); } remaining = remaining.minus(gapRemaining); if (i == 0) return Pair.create(null, remaining); seekMoment = availablePeriods.get(i - 1).getEnd(); } } if (isTraceEnable) log.trace(" ?? ."); return Pair.create(null, remaining); }