this.isEmpty() || (factor == 1) ) { return this; } else if (factor == 0) { return ofZero(); } else if (factor == -1) { return new Duration<>(this, true); List<Item<U>> newItems = new ArrayList<>(this.count()); int scalar = Math.abs(factor); for (int i = 0, n = this.count(); i < n; i++) { Item<U> item = this.getTotalLength().get(i); newItems.add( Item.of( return new Duration<>( newItems, ((factor < 0) != this.isNegative()) );
/** * <p>Parses a canonical representation with only date units to a * calendrical duration. </p> * * @param period duration in canonical, ISO-8601-compatible or * XML-schema-compatible format (P-string) * @return parsed calendrical duration * @throws ParseException if parsing fails * @see #parsePeriod(String) * @see #parseClockPeriod(String) */ /*[deutsch] * <p>Parst eine kanonische Darstellung nur mit * Datumskomponenten zu einer Dauer. </p> * * @param period duration in canonical, ISO-8601-compatible or * XML-schema-compatible format (P-string) * @return parsed calendrical duration * @throws ParseException if parsing fails * @see #parsePeriod(String) * @see #parseClockPeriod(String) */ public static Duration<CalendarUnit> parseCalendarPeriod(String period) throws ParseException { return parsePeriod(period, CalendarUnit.class); }
private int getIndex(ChronoUnit unit) { return getIndex(unit, this.getTotalLength()); }
/** * <p>Creates a composition of a calendar period and a clock period. </p> * * @param calendarPeriod calendrical duration * @param clockPeriod duration with clock units * @return composite duration * @since 3.0 * @see #toCalendarPeriod() * @see #toClockPeriod() */ /*[deutsch] * <p>Bildet eine aus kalendarischer Dauer und Uhrzeitperiode zusammengesetzte Dauer. </p> * * @param calendarPeriod calendrical duration * @param clockPeriod duration with clock units * @return composite duration * @since 3.0 * @see #toCalendarPeriod() * @see #toClockPeriod() */ public static Duration<IsoUnit> compose( Duration<CalendarUnit> calendarPeriod, Duration<ClockUnit> clockPeriod ) { Duration<IsoUnit> dur = Duration.ofZero(); return dur.plus(calendarPeriod).plus(clockPeriod); }
List<Item<U>> temp = new ArrayList<>(this.getTotalLength()); Item<U> item = replaceFraction(amount, unit); if (this.isEmpty()) { temp.add((item == null) ? Item.of(amount, unit) : item); return new Duration<>(temp, negatedValue); int index = this.getIndex(unit); boolean resultNegative = this.isNegative(); if (this.isNegative() == negatedValue) { temp.add(Item.of(amount, unit)); } else { // mixed signs possible => last try return this.plus(Duration.of(originalAmount, originalUnit)); MathUtils.safeMultiply( temp.get(index).getAmount(), (this.isNegative() ? -1 : 1) ), MathUtils.safeMultiply( temp.remove(index); } else if ( (this.count() == 1) || (this.isNegative() == (sum < 0)) ) { long absSum = ((sum < 0) ? MathUtils.safeNegate(sum) : sum); resultNegative = (sum < 0);
return Duration.of(this.unit.convert(dur), this.unit); case TRUNCATE_MODE: List<TimeSpan.Item<ClockUnit>> itemList = new ArrayList<TimeSpan.Item<ClockUnit>>(); return Duration.ofZero(); } else { return new Duration<ClockUnit>(itemList, dur.isNegative()); Duration<ClockUnit> d = Duration.ofZero(); d = d.plus(dur); if (negative) { d = d.abs(); d = d.with(Duration.STD_CLOCK_PERIOD); long half; switch (this.unit) { if (d.getPartialAmount(smaller) >= half) { d = d.plus(1, this.unit).with(Duration.STD_CLOCK_PERIOD); d = d.with(this.unit.truncated()); if (negative) { d = d.inverse();
duration = Duration.inYearsMonthsDays().between(refDate, date); } else { CalendarUnit[] stdUnits = {YEARS, MONTHS, WEEKS, DAYS}; duration = Duration.in(stdUnits).between(refDate, date); if (duration.isEmpty()) { return this.getEmptyRelativeString(TimeUnit.DAYS); TimeSpan.Item<CalendarUnit> item = duration.getTotalLength().get(0); long amount = item.getAmount(); CalendarUnit unit = item.getUnit(); ) { UnitPatterns patterns = UnitPatterns.of(this.locale); String replacement = (duration.isNegative() ? patterns.getYesterdayWord() : patterns.getTomorrowWord()); duration.isNegative() ? this.getPastPattern(amount, unit) : this.getFuturePattern(amount, unit));
) { if (duration.isEmpty()) { if (isEmpty(timespan)) { return duration; } else if (timespan instanceof Duration) { return cast(timespan); for (int i = 0, n = duration.count(); i < n; i++) { Item<U> item = duration.getTotalLength().get(i); map.put( item.getUnit(), MathUtils.safeMultiply( item.getAmount(), (duration.isNegative() ? -1 : 1) Item<U> item = replaceFraction(amount, unit); if (duration.isNegative() == tsign) { negative = tsign; } else { return Duration.create(map, negative);
&& this.isNegative() ) { throw new ChronoException("Negative sign not allowed in ISO-8601."); if (this.isEmpty()) { return "PT0S"; if (this.isNegative()) { sb.append('-'); for (int index = 0, limit = this.count(); index < limit; index++) { Item<U> item = this.getTotalLength().get(index); U unit = item.getUnit(); if (this.contains(DAYS)) { continue; } else { "Special units cannot be output in " + mode + "-mode: " + this.toString(PRINT_STYLE_NORMAL)); boolean representable = !timeAppended; if (representable) { for (int index = 0, limit = this.count(); index < limit; index++) { Object unit = this.getTotalLength().get(index).getUnit(); if ((unit != Weekcycle.YEARS) && (unit != CalendarUnit.WEEKS) && (unit != CalendarUnit.DAYS)) { representable = false;
if (this.isEmpty()) { return Duration.ofZero(); return Duration.ofZero(); return new Duration<>(calItems, this.isNegative());
/** * <p>Yields the length of this interval. </p> * * @return duration in hours, minutes, seconds and nanoseconds * @since 2.0 */ /*[deutsch] * <p>Liefert die Länge dieses Intervalls. </p> * * @return duration in hours, minutes, seconds and nanoseconds * @since 2.0 */ public Duration<ClockUnit> getDuration() { PlainTime t1 = this.getTemporalOfClosedStart(); PlainTime t2 = this.getEnd().getTemporal(); if (this.getEnd().isClosed()) { if (t2.getHour() == 24) { if (t1.equals(PlainTime.midnightAtStartOfDay())) { return Duration.of(24, HOURS).plus(1, NANOS); } else { t1 = t1.minus(1, NANOS); } } else { t2 = t2.plus(1, NANOS); } } return Duration.inClockUnits().between(t1, t2); }
return Duration.ofZero(); return Duration.of(dur.isNegative() ? -w : w, CalendarUnit.WEEKS); Duration.ofPositive() .years(y).months(m).days(d) .hours(h).minutes(min).seconds(s).build(); duration = duration.inverse();
public void sendRealtimeAgentHealth(Account account, List<JvmAgentStatus> statusList) { VelocityContext ctx = new VelocityContext(); ctx.put("username", account.username()); List<Cluster> clusters = new ArrayList<>(); statusList.forEach(jas -> { Cluster c = new Cluster(); c.name = jas.getAnalysis().name(); List<Jvm> jvms = new ArrayList<>(); jas.getJvms().forEach(p -> { Jvm jvm = new Jvm(); jvm.name = p.getKey(); Duration dur = Duration.of(p.getValue(), ClockUnit.SECONDS).with(Duration.STD_CLOCK_PERIOD); jvm.period = PrettyTime.of(Locale.ENGLISH).print(dur, TextWidth.ABBREVIATED); jvms.add(jvm); }); c.jvms = jvms; clusters.add(c); }); ctx.put("clusters", clusters); String template = config.readString(ConfigProperty.EMAIL_AGENT_HEALTH_TEMPLATE); StringWriter msg = new StringWriter((int) (template.length() * 1.5)); if (Velocity.evaluate(ctx, msg, account.username(), template)) { sendNotification(account, "Real-time Agent Health Status", msg.toString()); } else { LOG.info("Unable to generate velocity template for message."); } }
Item<U> item = replaceFraction(absAmount, unit); long oldAmount = this.getPartialAmount(unit); return this.plus( MathUtils.safeSubtract( MathUtils.safeMultiply( MathUtils.safeMultiply( oldAmount, this.isNegative() ? -1 : 1
/** * <p>Computes the hash code. </p> */ /*[deutsch] * <p>Basiert auf allen gespeicherten Zeitspannenelementen und dem * Vorzeichen passend zur Definition von {@code equals()}. </p> */ @Override public int hashCode() { int hash = this.getTotalLength().hashCode(); if (this.negative) { hash ^= hash; } return hash; }