public static Duration getInexactDuration(org.joda.time.Duration d) { return new InexactDuration(d.toPeriod()); }
public String duration(PeriodFormatter formatter) { return formatter.print(duration.toPeriod()); }
public long getTotalSeconds() { Period period = duration.toPeriod(); return period.getHours()*3600 + period.getMinutes()*60 + period.getSeconds(); } }
public static String humanDuration(final Duration dur) { final Period p = dur.toPeriod().normalizedStandard(); if (dur.getStandardSeconds() == 0) { return "0 seconds"; } else if (dur.getStandardSeconds() < 60) { return format("%d second%s", p.getSeconds(), p.getSeconds() > 1 ? "s" : ""); } else if (dur.getStandardMinutes() < 60) { return format("%d minute%s", p.getMinutes(), p.getMinutes() > 1 ? "s" : ""); } else if (dur.getStandardHours() < 24) { return format("%d hour%s", p.getHours(), p.getHours() > 1 ? "s" : ""); } else { return format("%d day%s", dur.getStandardDays(), dur.getStandardDays() > 1 ? "s" : ""); } }
@Test(expected = ArithmeticException.class) public void testMinMaxPeriod() { final Period period = Intervals.ETERNITY.toDuration().toPeriod(); Assert.assertEquals(Long.MAX_VALUE, period.getMinutes()); }
this.periodFormatter.print(new Duration(this.startTime, System.currentTimeMillis()).toPeriod()); String timeSpentOnTopicMsg = String.format("Time spent on topic %s:%d = %s", key.getTopic(), key.getPartition(), timeSpentOnPartition); if (this.numRecordsReadForCurrentPartition != 0) { String timeSpentOnPartition = this.periodFormatter.print(new Duration(this.startTime, System.currentTimeMillis()).toPeriod()); log.info("Time spent on this partition = " + timeSpentOnPartition); log.info("Num of records read for this partition = " + this.numRecordsReadForCurrentPartition);
@Override public String toString() { return PERIOD_FORMATTER.print(delay.toPeriod()); } }
public static Duration getInexactDuration(org.joda.time.Duration d) { return new InexactDuration(d.toPeriod()); }
@Nonnull public HCTime setAsDuration (@Nonnull final Duration aDuration) { return setAsDuration (aDuration.toPeriod ()); }
private String convert(long runningDurationMillis) { Duration duration = new Duration(runningDurationMillis); PeriodFormatter formatter = PeriodFormat.getDefault(); return formatter.print(duration.toPeriod()); }
@Override public String toString(Duration value) { if (value == null) { return null; } else { return ISOPeriodFormat.standard().print(value.toPeriod()); } }
@Override public void doneComputing(ExperimentResults results) { final Duration dur = new Duration(startTime, System.currentTimeMillis()); printStream.println("Computing done, duration: " + PeriodFormat.getDefault().print(dur.toPeriod()) + "."); printMemorySummary(printStream); } }
@Override public void receive(SimulationResult result) { if (result.getResultObject() instanceof FailureStrategy) { failures++; } else { received++; } final Duration dur = new Duration(startTime, System.currentTimeMillis()); printStream.println(Joiner.on("") .join(received, SLASH, total, " (failures: ", failures, ", duration: ", PeriodFormat.getDefault().print(dur.toPeriod()), ", memory free/total/max (M): ", memorySummary(), ")")); }
@Contract("null -> null; !null -> !null") public static @Nullable String jodaDurationToString(final Duration d) { if (d == null) { return null; } if (d.isShorterThan(new Duration(60000))) { return "0min"; } return DURATIONFORMAT.print(d.toPeriod()); }
private static void printScriptRunTime(DateTime startTime) { DateTime endTime = new DateTime(); Duration duration = new Duration(startTime, endTime); Period period = duration.toPeriod().normalizedStandard(PeriodType.time()); log.info("Pig script completed in " + PeriodFormat.getDefault().print(period) + " (" + duration.getMillis() + " ms)"); }
public String getFormattedDuration() { int duration; try { duration = Integer.parseInt(this.duration); } catch (NumberFormatException e) { return "?"; } Period period = Duration.standardSeconds(duration).toPeriod(); PeriodFormatter formatter = (period.getHours() > 0) ? hourPeriodFormatter : secondsPeriodFormatter; return period.toString(formatter); }
/** {@inheritDoc} */ @Override public String marshal(final Duration v) { if (v.equals(Duration.ZERO)) { return "0"; } return DEFAULT_PERIOD_FORMATTER.print(v.toPeriod().normalizedStandard()); }
@ProcessElement public void processElement(ProcessContext c, BoundedWindow window) { IntervalWindow w = (IntervalWindow) window; int duration = new Duration(w.start(), w.end()).toPeriod().toStandardMinutes().getMinutes(); c.output(duration); } }
protected void checkTimestamp(WindowedValue<IN> ref, Instant timestamp) { if (timestamp.isBefore(ref.getTimestamp().minus(doFn.getAllowedTimestampSkew()))) { throw new IllegalArgumentException(String.format( "Cannot output with timestamp %s. Output timestamps must be no earlier than the " + "timestamp of the current input (%s) minus the allowed skew (%s). See the " + "DoFn#getAllowedTimestmapSkew() Javadoc for details on changing the allowed skew.", timestamp, ref.getTimestamp(), PeriodFormat.getDefault().print(doFn.getAllowedTimestampSkew().toPeriod()))); } }
public static String prettyDuration(Long millis) { Duration duration = new Duration(millis); PeriodFormatter formatter = new PeriodFormatterBuilder().appendDays().appendSuffix("D ").appendHours().appendSuffix("h ").appendMinutes() .appendSuffix("m").toFormatter(); return formatter.print(duration.toPeriod()); }